Skip to content

Commit

Permalink
fix bezier approximation again
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyer committed Jan 11, 2025
1 parent 01daade commit 17978e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ocpsvg/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ def curve_to_beziers(
else:
bspline = curve_to_bspline(curve)
bspline.Segment(adaptor.FirstParameter(), adaptor.LastParameter())
if isinstance(adaptor, BRepAdaptor_Curve):
bspline.Transform(adaptor.Trsf())
yield from bspline_to_beziers(
bspline,
max_degree=max_degree,
Expand Down
19 changes: 18 additions & 1 deletion tests/test_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

import pytest
import svgelements
from OCP.BRepBuilderAPI import BRepBuilderAPI_Transform
from OCP.GC import GC_MakeArcOfCircle
from OCP.Geom import Geom_Circle, Geom_Curve, Geom_Ellipse, Geom_TrimmedCurve
from OCP.GeomAbs import GeomAbs_CurveType
from OCP.gp import gp_Ax2, gp_Circ, gp_Pnt, gp_Vec
from OCP.gp import gp_Ax2, gp_Circ, gp_Pnt, gp_Trsf, gp_Vec
from OCP.TopoDS import TopoDS, TopoDS_Edge, TopoDS_Face, TopoDS_Shape, TopoDS_Wire
from pytest import approx, raises

Expand Down Expand Up @@ -199,6 +200,22 @@ def test_trimmed_arc_to_cubics_reversed():
assert svg_with_arcs[-1][-2:] == approx(svg_with_cubics_only[-1][-2:])


def test_arc_to_cubic_transformed():
edge = edge_from_curve(circle_curve(2))

t = gp_Trsf()
t.SetTranslationPart(gp_Vec(8, 4, 0))
transformed_edge = TopoDS.Edge_s(
BRepBuilderAPI_Transform(edge, t, False, False).Shape()
)

cmd1 = next(edge_to_svg_path(edge, tolerance=0.1, use_arcs=False))
cmd2 = next(edge_to_svg_path(transformed_edge, tolerance=0.1, use_arcs=False))
assert cmd1[0] == "M" and cmd2[0] == "M"
assert cmd2[1] == approx(cmd1[1] + 8)
assert cmd2[2] == approx(cmd1[2] + 4)


@pytest.mark.parametrize(
"wire, svg_d, opts",
[
Expand Down

0 comments on commit 17978e9

Please sign in to comment.