Exemple #1
0
def add_hatch_boundaries_adjacent(msp, offset):
    x, y = offset
    external = Shape2d(square(SIZE))
    outermost = Shape2d(square(SIZE - 2))
    outermost.translate((1, 1))
    default0 = Shape2d(square(2))
    default0.translate((2, 2))
    default1 = Shape2d(square(2))
    default1.translate((6, 2))
    add_hatch(
        msp,
        external=[external],
        outermost=[outermost],
        default=[default0, default1],
        hatch_style=const.HATCH_STYLE_NESTED,
        offset=offset,
    )
    add_hatch(msp,
              external=[external],
              outermost=[outermost],
              default=[default0, default1],
              hatch_style=const.HATCH_STYLE_OUTERMOST,
              offset=(x + DX, y))
    add_hatch(msp,
              external=[external],
              outermost=[outermost],
              default=[default0, default1],
              hatch_style=const.HATCH_STYLE_IGNORE,
              offset=(x + DX + DX, y))
Exemple #2
0
def test_three_polygons_from_one_hatch():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(1), flags=1)
    paths.add_polyline_path(translate(square(1), (3, 1)), flags=1)
    paths.add_polyline_path(translate(square(1), (6, 2)), flags=1)
    mapping = geo.proxy(hatch).__geo_interface__
    assert mapping['type'] == 'MultiPolygon'
    assert len(mapping['coordinates']) == 3
Exemple #3
0
def test_polygon_from_hatch_hole_in_hole():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=1)
    paths.add_polyline_path(translate(square(8), (1, 1)), flags=0)
    paths.add_polyline_path(translate(square(6), (2, 2)), flags=0)
    mapping = geo.proxy(hatch).__geo_interface__
    assert mapping['type'] == 'Polygon'
    assert len(mapping['coordinates']) == 2, 'inner hole should be removed'

    mapping = geo.proxy(hatch, force_line_string=True).__geo_interface__
    assert mapping['type'] == 'MultiLineString'
    assert len(mapping['coordinates']) == 3, 'inner hole should not be removed'
Exemple #4
0
def test_polygon_from_hatch_hole_in_hole():
    hatch = factory.new("HATCH")
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=1)
    paths.add_polyline_path(translate(square(8), (1, 1)), flags=0)
    paths.add_polyline_path(translate(square(6), (2, 2)), flags=0)
    mapping = geo.proxy(hatch).__geo_interface__
    assert mapping["type"] == "Polygon"
    assert len(mapping["coordinates"]) == 2, "inner hole should be removed"

    mapping = geo.proxy(hatch, force_line_string=True).__geo_interface__
    assert mapping["type"] == "MultiLineString"
    assert len(mapping["coordinates"]) == 3, "inner hole should not be removed"
Exemple #5
0
def test_valid_hatch():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=const.BOUNDARY_PATH_EXTERNAL)
    paths.add_polyline_path(translate(square(3), (1, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    paths.add_polyline_path(translate(square(3), (5, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    p = geo.proxy(hatch)
    polygon = shapely_geometry.shape(p)
    assert polygon.is_valid is True

    p.filter(validate)
    assert p.root != {}
Exemple #6
0
def test_invalid_hatch_with_intersecting_holes():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10),
                            flags=const.BOUNDARY_PATH_EXTERNAL)
    paths.add_polyline_path(translate(square(3), (1, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    paths.add_polyline_path(translate(square(3), (2, 2)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    p = geo.proxy(hatch)
    polygon = shapely_geometry.shape(p)
    assert polygon.is_valid is False

    p.filter(validate)
    assert p.root == {}
Exemple #7
0
def create_block(
    doc: "Drawing", size: float, margin: float, base_point: Vec2 = NULLVEC
) -> "BlockLayout":
    attribs = GfxAttribs(color=colors.RED)
    block = doc.blocks.new("SQUARE", base_point=base_point)
    block.add_lwpolyline(forms.square(size), close=True, dxfattribs=attribs)

    attdef_attribs = dict(attribs)
    attdef_attribs["height"] = 1.0
    attdef_attribs["style"] = "OpenSans"
    tag = "ONE"
    attdef_attribs["prompt"] = tag
    bottom_left_attdef = block.add_attdef(
        tag, text=tag, dxfattribs=attdef_attribs
    )
    bottom_left_attdef.set_placement(
        (margin, margin), align=TextEntityAlignment.BOTTOM_LEFT
    )
    tag = "TWO"
    attdef_attribs["prompt"] = tag
    top_right_attdef = block.add_attdef(
        tag, text=tag, dxfattribs=attdef_attribs
    )
    top_right_attdef.set_placement(
        (size - margin, size - margin), align=TextEntityAlignment.TOP_RIGHT
    )
    return block
Exemple #8
0
def test_resolved_hatch_with_intersecting_holes():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=const.BOUNDARY_PATH_EXTERNAL)
    paths.add_polyline_path(translate(square(3), (1, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    paths.add_polyline_path(translate(square(3), (2, 2)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    p = geo.proxy(hatch)
    # Overlapping holes already resolved by fast_bbox_detection()
    polygon = shapely_geometry.shape(p)
    assert polygon.is_valid is True

    p.filter(validate)
    assert p.root['type'] == 'Polygon'
    assert len(p.root['coordinates']) == 2
 def test_intersecting_squares(self):
     square1 = forms.close_polygon(forms.square(2.0))
     square2 = forms.translate(square1, (1, 1))
     res = intersect_polylines_2d(Vec2.list(square1), Vec2.list(square2))
     assert len(res) == 2
     res.sort()
     assert res[0].isclose(Vec2(1, 2))
     assert res[1].isclose(Vec2(2, 1))
Exemple #10
0
def solid_blockrefs():
    doc = ezdxf.new()
    blk = doc.blocks.new('Solid')
    blk.add_solid(square(1))
    msp = doc.modelspace()
    msp.add_blockref('Solid', (-10, -10))
    msp.add_blockref('Solid', (10, 10))
    return msp
def add_predefined_hatch_pattern(msp, cols, size, gap, scale):
    for index, name in enumerate(pattern.ISO_PATTERN.keys()):
        x = (index % cols) * (size + gap)
        y = (index // cols) * (size + gap)
        boundary = list(translate(square(size), (x, HEIGHT - y)))
        msp.add_lwpolyline(boundary, close=True, dxfattribs={"layer": "LINE"})
        hatch = msp.add_hatch(dxfattribs={"layer": "HATCH"})
        hatch.set_pattern_fill(name=name, scale=scale)
        hatch.paths.add_polyline_path(boundary, is_closed=True)
def test_ngons_to_triangles():
    open_square = square()
    r = list(ngon_to_triangles(open_square))
    assert len(r) == 4
    center = r[0][2]
    assert center == (0.5, 0.5, 0)

    closed_square = list(circle(4, elevation=2, close=True))
    assert len(closed_square) == 5
    r = list(ngon_to_triangles(closed_square))
    assert len(r) == 4
    center = r[0][2]
    assert center.isclose((0, 0, 2))

    # also subdivide triangles
    r = list(ngon_to_triangles([(0, 0), (1, 0), (1, 1)]))
    assert len(r) == 3
def test_square():
    sq = square(2)
    assert len(sq) == 4
    assert close_vectors(sq, [(0, 0), (2, 0), (2, 2), (0, 2)])
Exemple #14
0
def solid_entities():
    lay = VirtualLayout()
    lay.add_solid(translate(square(1), (-10, -10)))
    lay.add_solid(translate(square(1), (10, 10)))
    return lay
#  Copyright (c) 2020, Manfred Moitzi
#  License: MIT License

import pytest
from ezdxf.render.forms import square, translate
from ezdxf.path import Path, nesting, from_vertices

EXTERIOR = list(translate(square(10), (-5, -5)))
EXT1_PATH = from_vertices(EXTERIOR)
EXT2_PATH = from_vertices(translate(EXTERIOR, (11, 0)))

CENTER_HOLE1 = list(translate(square(8), (-4, -4)))
CH1_PATH = from_vertices(CENTER_HOLE1)

CENTER_HOLE2 = list(translate(square(6), (-3, -3)))
CH2_PATH = from_vertices(CENTER_HOLE2)

LEFT_HOLE = list(translate(square(2.1), (-3, -1)))
LH_PATH = from_vertices(LEFT_HOLE)

RIGHT_HOLE = list(translate(square(2.0), (3, -1)))
RH_PATH = from_vertices(RIGHT_HOLE)

DETECTION_DATA = [
    pytest.param(
        # Each polygon is a list of paths
        [EXT1_PATH],
        [[EXT1_PATH]],
        id="1 path",
    ),
    pytest.param(
Exemple #16
0
def test_subdivide_vec2_square_in_quads():
    b = Vec2.list(square(2))
    result = list(subdivide_face(b, quads=True))
    assert len(result) == 4
    assert result[0] == ((0, 0), (1, 0), (1, 1), (0, 1))
Exemple #17
0
def test_subdivide_square_in_triangles():
    b = square(2)
    result = list(subdivide_face(b, quads=False))
    assert len(result) == 8
    assert result[0] == ((0, 1), (0, 0), (1, 1))
    assert result[1] == ((0, 0), (1, 0), (1, 1))
def test_square():
    sq = square(2)
    assert len(sq) == 4
    assert sq == (Vec3(0, 0), Vec3(2, 0), Vec3(2, 2), Vec3(0, 2))
 def test_squares_with_common_corner_vertex(self):
     square1 = forms.close_polygon(forms.square(2.0))
     square2 = forms.translate(square1, (2, 2))
     res = intersect_polylines_2d(Vec2.list(square1), Vec2.list(square2))
     assert len(res) == 1
     assert res[0].isclose(Vec2(2, 2))