Fixing Mirror change geomtype #80

This commit is contained in:
Roger Maitland 2023-01-06 14:33:18 -05:00
parent 07193a844a
commit 6ccc738523
2 changed files with 22 additions and 14 deletions

View file

@ -26,8 +26,9 @@ license:
limitations under the License.
"""
from typing import Union
import copy
import logging
from typing import Union
from build123d.build_enums import Mode, Kind, Keep
from build123d.direct_api import (
Edge,
@ -330,17 +331,7 @@ class Mirror(Compound):
self.about = about
self.mode = mode
scale_matrix = Matrix(
[
[1.0, 0.0, 00.0, 0.0],
[0.0, 1.0, 00.0, 0.0],
[0.0, 0.0, -1.0, 0.0],
[0.0, 0.0, 00.0, 1.0],
]
)
localized = [about.to_local_coords(o) for o in objects]
local_mirrored = [o.transform_geometry(scale_matrix) for o in localized]
mirrored = [about.from_local_coords(o) for o in local_mirrored]
mirrored = [copy.deepcopy(o).mirror(about) for o in objects]
context._add_to_context(*mirrored, mode=mode)
super().__init__(Compound.make_compound(mirrored).wrapped)

View file

@ -216,7 +216,7 @@ class ChamferTests(unittest.TestCase):
Rectangle(10, 10)
Chamfer(
*test.vertices().filter_by_position(Axis.X, minimum=0, maximum=20),
length=1
length=1,
)
self.assertAlmostEqual(test.sketch.area, 200 - 4 * 0.5, 5)
@ -244,7 +244,7 @@ class FilletTests(unittest.TestCase):
Rectangle(10, 10)
Fillet(
*test.vertices().filter_by_position(Axis.X, minimum=0, maximum=20),
radius=1
radius=1,
)
self.assertAlmostEqual(test.sketch.area, 200 - 4 + pi, 5)
@ -323,6 +323,23 @@ class MirrorTests(unittest.TestCase):
len(test.solids().filter_by_position(Axis.X, minimum=-10, maximum=0)), 1
)
def test_changing_object_type(self):
"""Using gp_GTrsf for the mirror operation may change the nature of the object"""
ring_r, ring_t = 9, 2
wheel_r, wheel_t = 10, 6
with BuildPart() as p:
with BuildSketch(Plane.XZ) as side:
Trapezoid(wheel_r, wheel_t / 2, 90, 45, centered=(False, False))
with Locations((ring_r, ring_t / 2)):
Circle(ring_t / 2, centered=(True, True), mode=Mode.SUBTRACT)
with Locations((wheel_r, ring_t / 2)):
Rectangle(2, 2, centered=(True, True), mode=Mode.SUBTRACT)
Revolve(axis=Axis.Z)
Mirror(about=Plane.XY)
construction_face = p.faces().sort_by(Axis.Z)[0]
self.assertEqual(construction_face.geom_type(), "PLANE")
class ScaleTests(unittest.TestCase):
def test_line(self):