revolve: Fix modulo of revolution_arc to keep expected sign for angle

This commit is contained in:
Jonathan Wagenet 2025-04-17 13:44:11 -04:00
parent b03fa9a7fb
commit 1c129b38ab
2 changed files with 22 additions and 2 deletions

View file

@ -464,8 +464,9 @@ def revolve(
# Make sure we account for users specifying angles larger than 360 degrees, and # Make sure we account for users specifying angles larger than 360 degrees, and
# for OCCT not assuming that a 0 degree revolve means a 360 degree revolve # for OCCT not assuming that a 0 degree revolve means a 360 degree revolve
angle = revolution_arc % 360.0 sign = 1 if revolution_arc >= 0 else -1
angle = 360.0 if angle == 0 else angle angle = revolution_arc % (sign * 360.0)
angle = sign * 360.0 if angle == 0 else angle
if all([s is None for s in profile_list]): if all([s is None for s in profile_list]):
if context is None or (context is not None and not context.pending_faces): if context is None or (context is not None and not context.pending_faces):

View file

@ -412,6 +412,25 @@ class TestRevolve(unittest.TestCase):
self.assertLess(test.part.volume, 244 * pi * 20, 5) self.assertLess(test.part.volume, 244 * pi * 20, 5)
self.assertGreater(test.part.volume, 100 * pi * 20, 5) self.assertGreater(test.part.volume, 100 * pi * 20, 5)
def test_revolve_size(self):
"""Verify revolution result matches revolution_arc size and direction"""
ax = Axis.X
sizes = [30, 90, 150, 180, 200, 360, 500, 720, 750]
sizes = [x * -1 for x in sizes[::-1]] + [0] + sizes
for size in sizes:
profile = RegularPolygon(10, 4, align=(Align.CENTER, Align.MIN))
solid = revolve(profile, axis=ax, revolution_arc=size)
# Find any rotation edge and and the start tangent normal to the profile
edge = solid.edges().filter_by(GeomType.CIRCLE).sort_by(Edge.length)[-1]
sign = (edge % 0).Z
expected = size % (sign * 360)
expected = sign * 360 if expected == 0 else expected
result = edge.length / edge.radius / pi * 180 * sign
self.assertAlmostEqual(expected, result)
# Invalid test # Invalid test
# def test_invalid_axis_origin(self): # def test_invalid_axis_origin(self):
# with BuildPart(): # with BuildPart():