def virtual_entities(self, name: str, insert: 'Vertex' = NULLVEC, size: float = 0.625, rotation: float = 0, *, dxfattribs: Dict = None) -> Iterable['DXFGraphic']: """ Yield arrow components as virtual DXF entities. """ from ezdxf.layouts import VirtualLayout if name in self: layout = VirtualLayout() dxfattribs = dxfattribs or {} ARROWS.render_arrow( layout, name, insert=insert, size=size, rotation=rotation, dxfattribs=dxfattribs, ) yield from iter(layout)
def test_flattening_issue(): from ezdxf.layouts import VirtualLayout layout = VirtualLayout() # this configuration caused an math domain error in distance_point_line_3d() # sqrt() of negative number, cause by floating point imprecision for very # small numbers. e = layout.add_spline( degree=2, dxfattribs={ "layer": "0", "linetype": "Continuous", "color": 84, "lineweight": 0, "extrusion": (0.0, 0.0, 1.0), "flags": 12, "knot_tolerance": 1e-09, "control_point_tolerance": 1e-10, }, ) e.control_points = [ (696603.8306266892, 5711646.357537143, -2.8298889e-09), (696603.8352219285, 5711646.36068357, -2.8298889e-09), (696603.8392015211, 5711646.363408451, -2.8298889e-09), ] e.knots = [ -6.110343499933633, -6.110343499933633, -6.110343499933633, -4.326590114514485, -4.326590114514485, -4.326590114514485, ] e.weights = [ 1.607007851100765, 1.731310340973351, 1.731310340973339, ] points = list(e.flattening(0.01)) assert len(points) > 4
def test_polyline2d_closed(): # Create a circle by 2D POLYLINE: msp = VirtualLayout() polyline = msp.add_polyline2d(points=[(0, 0, 1), (1, 0, 1)], format='xyb') polyline.close(True) result = list(polyline.virtual_entities()) assert len(result) == 2 e = result[0] assert e.dxftype() == 'ARC' assert e.dxf.center == (0.5, 0) assert e.dxf.radius == 0.5 assert math.isclose(e.dxf.start_angle, 180, abs_tol=1e-12) assert math.isclose(e.dxf.end_angle, 0, abs_tol=1e-12) e = result[1] assert e.dxftype() == 'ARC' assert e.dxf.center.isclose((0.5, 0)) assert e.dxf.radius == 0.5 assert math.isclose(e.dxf.start_angle, 0, abs_tol=1e-12) assert math.isclose(abs(e.dxf.end_angle), 180, abs_tol=1e-12)
def test_boundary_path_wcs(): from ezdxf.layouts import VirtualLayout layout = VirtualLayout() e = cast( Wipeout, layout.new_entity( 'WIPEOUT', dxfattribs={ 'layer': "0", 'class_version': 0, 'insert': (150.0, 100.0, 0.0), 'u_pixel': (100.0, 0.0, 0.0), 'v_pixel': (0.0, 100.0, 0.0), 'image_size': (1.0, 1.0, 0.0), 'image_def_handle': "0", 'flags': 7, 'clipping': 1, 'brightness': 50, 'contrast': 50, 'fade': 0, 'image_def_reactor_handle': "0", 'clipping_boundary_type': 2, 'count_boundary_points': 5, 'clip_mode': 0, }, )) e.set_boundary_path([ (-0.5, 0.5), (0.5, 0.5), (0.5, -0.5), (-0.5, -0.5), (-0.5, 0.5), ]) path = e.boundary_path_wcs() assert path[0] == (150, 100) assert path[1] == (250, 100) assert path[2] == (250, 200) assert path[3] == (150, 200) assert path[0] == path[-1]
def layout(): return VirtualLayout()
def solid_entities(): lay = VirtualLayout() lay.add_solid(translate(square(1), (-10, -10))) lay.add_solid(translate(square(1), (10, 10))) return lay
def points1(): lay = VirtualLayout() lay.add_point((-1, -2, -3)) lay.add_point((4, 5, 6)) return lay
def circle(): lay = VirtualLayout() lay.add_circle((0, 0), radius=100) return lay
def msp(): return VirtualLayout()
def test_render_arrow(): layout = VirtualLayout() ARROWS.render_arrow(layout, ARROWS.closed, insert=(0, 0, 0)) assert len(layout) > 0
def test_explode_entity_into_layout(self, text): layout = VirtualLayout() entities = text2path.explode(text, kind=Kind.LWPOLYLINES, target=layout) assert len(entities) == len(layout), \ "expected all entities added to the target layout"
def cube_polyface(): layout = VirtualLayout() p = layout.add_polyface() p.append_faces(cube().faces_as_vertices()) return p
def msp(): state = ezdxf.options.use_matplotlib ezdxf.options.use_matplotlib = False yield VirtualLayout() ezdxf.options.use_matplotlib = state
def test_copy_wipeout(): layout = VirtualLayout() wipeout = layout.add_wipeout([(150, 100), (250, 200)]) copy = wipeout.copy() layout.add_entity(copy) assert len(layout) == 2