Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_box():
b = box(3, 2)
assert len(b) == 4
assert b == (Vector(0, 0), Vector(3, 0), Vector(3, 2), Vector(0, 2))
def test_closed_arrow():
a = arrow2(3, 60, 45)
assert len(a) == 4
assert a == (Vector(-3, 1.5), Vector(0, 0), Vector(-3, -1.5), Vector(-1.5, 0))
def test_vertext_attribs_xy():
result = vertex_attribs((1, 2), format='xy')
assert result == {'location': Vector(1, 2)}
def test_spline_transform_interface():
spline = Spline()
spline.set_uniform([(1, 0, 0), (3, 3, 0), (6, 0, 1)])
spline.dxf.start_tangent = Vector(1, 0, 0)
spline.dxf.end_tangent = Vector(2, 0, 0)
spline.dxf.extrusion = Vector(3, 0, 0)
spline.transform(Matrix44.translate(1, 2, 3))
assert spline.control_points[0] == (2, 2, 3)
# direction vectors are not transformed by translation
assert spline.dxf.start_tangent == (1, 0, 0)
assert spline.dxf.end_tangent == (2, 0, 0)
assert spline.dxf.extrusion == (3, 0, 0)
# 524288 (0x80000) = Enable adaptive grid display
# 1048576 (0x100000) = Enables subdivision of the grid below the set grid spacing when the grid display is adaptive
# 2097152 (0x200000) = Enables grid follows workplane switching
'clipping_boundary_handle': DXFAttr(340, default=0, optional=True),
'plot_style_name': DXFAttr(1, default=''), # Plot style sheet name assigned to this viewport
'render_mode': DXFAttr(281, default=0),
# 0 = 2D Optimized (classic 2D)
# 1 = Wireframe
# 2 = Hidden line
# 3 = Flat shaded
# 4 = Gouraud shaded
# 5 = Flat shaded with wireframe
# 6 = Gouraud shaded with wireframe
'ucs_per_viewport': DXFAttr(71, default=0),
'ucs_icon': DXFAttr(74, default=0),
'ucs_origin': DXFAttr(110, xtype=XType.point3d, default=Vector(0, 0, 0)),
'ucs_x_axis': DXFAttr(111, xtype=XType.point3d, default=Vector(1, 0, 0)),
'ucs_y_axis': DXFAttr(112, xtype=XType.point3d, default=Vector(0, 1, 0)),
'ucs_handle': DXFAttr(345),
# ID/handle of AcDbUCSTableRecord if UCS is a named UCS. If not present, then UCS is unnamed
'ucs_base_handle': DXFAttr(346, optional=True),
# ID/handle of AcDbUCSTableRecord of base UCS if UCS is orthographic (79 code is non-zero). If not present and 79
# code is non-zero, then base UCS is taken to be WORLD
'ucs_ortho_type': DXFAttr(79, default=0),
# 0 = not orthographic
# 1 = Top
# 2 = Bottom
# 3 = Front
# 4 = Back
# 5 = Left
# 6 = Right
'elevation': DXFAttr(146, default=0),
raise ValueError("Argument radius is required.")
location = Vector(location)
radius_vec = (location - center).normalize(length=radius)
mpoint = center + radius_vec
else: # defined by mpoint = measurement point on circle
if mpoint is None: # defined by radius and angle
if angle is None:
raise ValueError("Argument angle or mpoint required.")
if radius is None:
raise ValueError("Argument radius or mpoint required.")
mpoint = center + Vector.from_deg_angle(angle, radius)
dxfattribs = dict(dxfattribs or {})
dxfattribs['dimstyle'] = self._save_dimstyle(dimstyle)
dxfattribs['defpoint4'] = Vector(mpoint) # group code 15
dxfattribs['defpoint'] = Vector(center) # group code 10
dxfattribs['text'] = str(text)
dimline.update_dxf_attribs(dxfattribs)
style = DimStyleOverride(dimline, override=override)
if location is not None:
style.user_location_override(location)
return style
Explode parts of DIMENSION as basic DXF entities like LINE, ARC or TEXT into target layout,
if target layout is ``None``, the target layout is the layout of the DIMENSION.
Returns an :class:`~ezdxf.query.EntityQuery` container with all DXF parts.
Args:
target_layout: target layout for DXF parts, ``None`` for same layout as source entity.
.. versionadded:: 0.12
"""
return explode_entity(self, target_layout)
acdb_arc_dimension = DefSubclass('AcDbArcDimension', {
'ext_line1_point': DXFAttr(13, xtype=XType.point3d, default=Vector(0, 0, 0)),
'ext_line2_point': DXFAttr(14, xtype=XType.point3d, default=Vector(0, 0, 0)),
'arc_center': DXFAttr(15, xtype=XType.point3d, default=Vector(0, 0, 0)),
'start_angle': DXFAttr(40), # radians?
'end_angle': DXFAttr(41), # radians?
'is_partial': DXFAttr(70),
'has_leader': DXFAttr(71),
'leader_point1': DXFAttr(16, xtype=XType.point3d, default=Vector(0, 0, 0)),
'leader_point2': DXFAttr(17, xtype=XType.point3d, default=Vector(0, 0, 0)),
})
@register_entity
class ArcDimension(Dimension):
""" DXF ARC_DIMENSION entity """
DXFTYPE = 'ARC_DIMENSION'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_dimension, acdb_arc_dimension)
def _load_vertices(self, data: bytes):
bs = ByteStream(data)
count = bs.read_struct(' 0:
vertices.append(Vector(bs.read_struct('<3d')))
count -= 1
return vertices
def line_to(self, location: 'Vertex') -> None:
""" Add a line from actual path end point to `location`.
"""
self._commands.append((Command.LINE_TO, Vector(location)))
def _add_quadrilateral(self, type_: str, points: Iterable['Vertex'], dxfattribs: dict = None) -> 'DXFGraphic':
dxfattribs = dict(dxfattribs or {})
entity = self.new_entity(type_, dxfattribs)
for x, point in enumerate(self._four_points(points)):
entity[x] = Vector(point)
return entity