|
9 | 9 |
|
10 | 10 | import pytest
|
11 | 11 | import svgelements
|
| 12 | +from OCP.GC import GC_MakeArcOfCircle |
12 | 13 | from OCP.Geom import Geom_Circle, Geom_Curve, Geom_Ellipse, Geom_TrimmedCurve
|
13 | 14 | from OCP.GeomAbs import GeomAbs_CurveType
|
14 |
| -from OCP.gp import gp_Pnt, gp_Vec |
| 15 | +from OCP.gp import gp_Ax2, gp_Circ, gp_Pnt, gp_Vec |
15 | 16 | from OCP.TopoDS import TopoDS, TopoDS_Edge, TopoDS_Face, TopoDS_Shape, TopoDS_Wire
|
16 | 17 | from pytest import approx, raises
|
17 | 18 |
|
|
33 | 34 | SvgPathCommand,
|
34 | 35 | _SegmentInPath, # type: ignore private usage
|
35 | 36 | bezier_to_svg_path,
|
| 37 | + curve_to_svg_path, |
36 | 38 | edge_to_svg_path,
|
37 | 39 | edges_from_svg_path,
|
38 | 40 | face_to_svg_path,
|
@@ -159,6 +161,44 @@ def test_polyline_apprx(curve: Geom_Curve):
|
159 | 161 | assert set(seg[0] for seg in path).issubset(set("MLZ"))
|
160 | 162 |
|
161 | 163 |
|
| 164 | +def test_trimmed_arc_to_cubics(): |
| 165 | + radius = 10 |
| 166 | + circ = gp_Circ(gp_Ax2(), radius) |
| 167 | + trimmed_arc = GC_MakeArcOfCircle( |
| 168 | + circ, gp_Pnt(-radius, 0, 0), gp_Pnt(0, +radius, 0), True |
| 169 | + ).Value() |
| 170 | + |
| 171 | + svg_with_arcs = list(curve_to_svg_path(trimmed_arc, tolerance=1e-6)) |
| 172 | + svg_with_cubics_only = list( |
| 173 | + curve_to_svg_path( |
| 174 | + trimmed_arc, use_arcs=False, use_quadratics=False, tolerance=1e-6 |
| 175 | + ) |
| 176 | + ) |
| 177 | + assert svg_with_arcs[0][-2:] == approx(svg_with_cubics_only[0][-2:]) |
| 178 | + assert svg_with_arcs[-1][-2:] == approx(svg_with_cubics_only[-1][-2:]) |
| 179 | + |
| 180 | + |
| 181 | +def test_trimmed_arc_to_cubics_reversed(): |
| 182 | + radius = 10 |
| 183 | + circ = gp_Circ(gp_Ax2(), radius) |
| 184 | + trimmed_arc = GC_MakeArcOfCircle( |
| 185 | + circ, gp_Pnt(-radius, 0, 0), gp_Pnt(0, +radius, 0), True |
| 186 | + ).Value() |
| 187 | + |
| 188 | + svg_with_arcs = list(curve_to_svg_path(trimmed_arc, reverse=True, tolerance=1e-6)) |
| 189 | + svg_with_cubics_only = list( |
| 190 | + curve_to_svg_path( |
| 191 | + trimmed_arc, |
| 192 | + reverse=True, |
| 193 | + use_arcs=False, |
| 194 | + use_quadratics=False, |
| 195 | + tolerance=1e-6, |
| 196 | + ) |
| 197 | + ) |
| 198 | + assert svg_with_arcs[0][-2:] == approx(svg_with_cubics_only[0][-2:]) |
| 199 | + assert svg_with_arcs[-1][-2:] == approx(svg_with_cubics_only[-1][-2:]) |
| 200 | + |
| 201 | + |
162 | 202 | @pytest.mark.parametrize(
|
163 | 203 | "wire, svg_d, opts",
|
164 | 204 | [
|
|
0 commit comments