def test_from_spline(): from ezdxf.entities import Spline spline = Spline.new() spline.fit_points = [(2, 0), (4, 1), (6, -1), (8, 0)] path = Path.from_spline(spline) assert path.start == (2, 0) assert path.end == (8, 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
def test_issue_494_make_path_from_spline_defined_by_fit_points_and_tangents(): from ezdxf.entities import Spline spline = Spline.new(dxfattribs={ "degree": 3, "start_tangent": (0.9920663924871818, 0.1257150464243202, 0.0), "end_tangent": (0.9999448476387669, -0.0105024606965807, 0.0), }, ) spline.fit_points = [ (209.5080107190219, 206.963463282597, 0.0), (209.55254921431026, 206.96662062623636, 0.0), ] p = make_path(spline) assert len(p) > 0
def to_splines_and_polylines( paths: Iterable[Path], *, g1_tol: float = G1_TOL, dxfattribs: Optional[Dict] = None ) -> Iterable[Union[Spline, Polyline]]: """ Convert the given `paths` into :class:`~ezdxf.entities.Spline` and 3D :class:`~ezdxf.entities.Polyline` entities. Args: paths: iterable of :class:`Path` objects g1_tol: tolerance for G1 continuity check dxfattribs: additional DXF attribs Returns: iterable of :class:`~ezdxf.entities.Line` objects .. versionadded:: 0.16 """ if isinstance(paths, Path): paths = [paths] dxfattribs = dxfattribs or {} for path in paths: for data in to_bsplines_and_vertices(path, g1_tol): if isinstance(data, BSpline): spline = Spline.new(dxfattribs=dxfattribs) spline.apply_construction_tool(data) yield spline else: attribs = dict(dxfattribs) attribs['flags'] = const.POLYLINE_3D_POLYLINE polyline = Polyline.new(dxfattribs=dxfattribs) polyline.append_vertices(data) yield polyline