示例#1
0
def _virtual_polyline_entities(points, elevation: float, extrusion: Vector,
                               dxfattribs: dict,
                               doc) -> Iterable[Union['Line', 'Arc']]:
    ocs = OCS(extrusion) if extrusion else OCS()
    prev_point = None
    prev_bulge = None

    for x, y, bulge in points:
        point = Vector(x, y, elevation)
        if prev_point is None:
            prev_point = point
            prev_bulge = bulge
            continue

        attribs = dict(dxfattribs)
        if prev_bulge != 0:
            center, start_angle, end_angle, radius = bulge_to_arc(
                prev_point, point, prev_bulge)
            attribs['center'] = Vector(center.x, center.y, elevation)
            attribs['radius'] = radius
            attribs['start_angle'] = math.degrees(start_angle)
            attribs['end_angle'] = math.degrees(end_angle)
            if extrusion:
                attribs['extrusion'] = extrusion
            yield Arc.new(doc=doc, dxfattribs=attribs)
        else:
            attribs['start'] = ocs.to_wcs(prev_point)
            attribs['end'] = ocs.to_wcs(point)
            yield Line.new(doc=doc, dxfattribs=attribs)
        prev_point = point
        prev_bulge = bulge
示例#2
0
def arc():
    return Arc.new(
        dxfattribs={
            "center": (3, 4, 5),
            "radius": 2.0,
            "start_angle": 15,
            "end_angle": 75,
            "extrusion": (0, 0, -1),
        })
示例#3
0
 def test_symmetric_difference(self, base: EntityQuery):
     other = base.query("LINE") | EntityQuery(
         [Arc.new(dxfattribs={
             "layer": "arc",
             "color": 4
         })])
     result = base ^ other
     assert len(result) == 3
     assert set(e.dxftype() for e in result) == {"CIRCLE", "TEXT", "ARC"}
def arc(radius=1, start=30, end=150, count=8):
    arc_ = Arc.new(dxfattribs={
        'center': (0, 0, 0),
        'radius': radius,
        'start_angle': start,
        'end_angle': end
    },
                   doc=doc)
    control_vertices = list(arc_.vertices(arc_.angles(count)))
    return arc_, control_vertices
示例#5
0
def test_from_arc():
    from ezdxf.entities import Arc
    arc = Arc.new(dxfattribs={
        'center': (1, 0, 0),
        'radius': 1,
        'start_angle': 0,
        'end_angle': 180,
    })
    path = Path.from_arc(arc)
    assert path.start == (2, 0)
    assert path.end == (0, 0)
示例#6
0
def _virtual_edge_path(path: EdgePath, dxfattribs: Dict, ocs: OCS,
                       elevation: float) -> List["DXFGraphic"]:
    from ezdxf.entities import Line, Arc, Ellipse, Spline

    def pnt_to_wcs(v):
        return ocs.to_wcs(Vec3(v).replace(z=elevation))

    def dir_to_wcs(v):
        return ocs.to_wcs(v)

    edges: List["DXFGraphic"] = []
    for edge in path.edges:
        attribs = dict(dxfattribs)
        if isinstance(edge, LineEdge):
            attribs["start"] = pnt_to_wcs(edge.start)
            attribs["end"] = pnt_to_wcs(edge.end)
            edges.append(Line.new(dxfattribs=attribs))
        elif isinstance(edge, ArcEdge):
            attribs["center"] = edge.center
            attribs["radius"] = edge.radius
            attribs["elevation"] = elevation
            # Arcs angles are always stored in counter clockwise orientation
            # around the extrusion vector!
            attribs["start_angle"] = edge.start_angle
            attribs["end_angle"] = edge.end_angle
            attribs["extrusion"] = ocs.uz
            edges.append(Arc.new(dxfattribs=attribs))
        elif isinstance(edge, EllipseEdge):
            attribs["center"] = pnt_to_wcs(edge.center)
            attribs["major_axis"] = dir_to_wcs(edge.major_axis)
            attribs["ratio"] = edge.ratio
            # Ellipse angles are always stored in counter clockwise orientation
            # around the extrusion vector!
            attribs["start_param"] = edge.start_param
            attribs["end_param"] = edge.end_param
            attribs["extrusion"] = ocs.uz
            edges.append(Ellipse.new(dxfattribs=attribs))
        elif isinstance(edge, SplineEdge):
            spline = Spline.new(dxfattribs=attribs)
            spline.dxf.degree = edge.degree
            spline.knots = edge.knot_values
            spline.control_points = [
                pnt_to_wcs(v) for v in edge.control_points
            ]
            if edge.weights:
                spline.weights = edge.weights
            if edge.fit_points:
                spline.fit_points = [pnt_to_wcs(v) for v in edge.fit_points]
            if edge.start_tangent is not None:
                spline.dxf.start_tangent = dir_to_wcs(edge.start_tangent)
            if edge.end_tangent is not None:
                spline.dxf.end_tangent = dir_to_wcs(edge.end_tangent)
            edges.append(spline)
    return edges
示例#7
0
 def build():
     arc = Arc.new(dxfattribs={
         'start_angle': random.uniform(0, 360),
         'end_angle': random.uniform(0, 360),
     })
     vertices = list(arc.vertices(arc.angles(vertex_count)))
     m = Matrix44.chain(
         Matrix44.axis_rotate(axis=Vec3.random(), angle=random.uniform(0, math.tau)),
         Matrix44.translate(dx=random.uniform(-2, 2), dy=random.uniform(-2, 2), dz=random.uniform(-2, 2)),
     )
     return synced_transformation(arc, vertices, m)
def arc(radius=1, start=30, end=150, count=8):
    arc_ = Arc.new(
        dxfattribs={
            "center": (0, 0, 0),
            "radius": radius,
            "start_angle": start,
            "end_angle": end,
        },
        doc=doc,
    )
    control_vertices = list(arc_.vertices(arc_.angles(count)))
    return arc_, control_vertices
示例#9
0
def test_from_arc():
    from ezdxf.entities import Arc
    spline = Spline.from_arc(Arc.new(dxfattribs={
        'center': (1, 1),
        'radius': 2,
        'start_angle': 30,  # degrees
        'end_angle': 150,
        'layer': 'arc',
    }))
    assert spline.dxf.layer == 'arc'
    assert spline.dxf.degree == 2
    assert len(spline.control_points) > 2
    assert len(spline.weights) > 2
    assert len(spline.fit_points) == 0
    assert len(spline.knots) == required_knot_values(len(spline.control_points), spline.dxf.degree + 1)
示例#10
0
def test_from_arc():
    from ezdxf.entities import Arc

    spline = Spline.from_arc(
        Arc.new(
            dxfattribs={
                "center": (1, 1),
                "radius": 2,
                "start_angle": 30,  # degrees
                "end_angle": 150,
                "layer": "arc",
            }))
    assert spline.dxf.layer == "arc"
    assert spline.dxf.degree == 2
    assert len(spline.control_points) > 2
    assert len(spline.weights) > 2
    assert len(spline.fit_points) == 0
    assert len(spline.knots) == required_knot_values(
        len(spline.control_points), spline.dxf.degree + 1)
示例#11
0
def test_remove_supports_virtual_entities():
    result = EntityQuery([Text(), Line(), Arc()]).remove("TEXT")
    assert len(result) == 2