MCPcopy
hub / github.com/CadQuery/cadquery / test_mirror_equivalence

Method test_mirror_equivalence

tests/test_workplanes.py:208–235  ·  view source on GitHub ↗

test that the plane string, plane normal and face object perform a mirror operation in the same way

(self)

Source from the content-addressed store, hash-verified

206 self.assertAlmostEqual(b2.findSolid().Volume(), 8, 5)
207
208 def test_mirror_equivalence(self):
209 """test that the plane string, plane normal and face object perform a mirror operation in the same way"""
210 boxes = []
211 boxDims = 1
212 for i in range(3): # create 3 sets of identical boxes
213 boxTmp = Workplane("XY").box(boxDims, boxDims, boxDims)
214 boxTmp = boxTmp.translate([i * 2, 0, boxDims / 2])
215 boxes.append(boxTmp)
216
217 # 3 different types of plane definition
218 planeArg = ["XY", (0, 0, 1), boxes[0].faces("<Z")]
219 planeOffset = (0, 0, 0.5) # use the safe offset for each
220 boxResults = [] # store the resulting mirrored objects
221 for b, p in zip(boxes, planeArg):
222 boxResults.append(b.mirror(p, planeOffset, union=True))
223
224 # all resulting boxes should be equal to each other
225 for i in range(len(boxResults) - 1):
226 curBoxDims = boxResults[i].findSolid().BoundingBox() # get bbox dims
227 nextBoxDims = boxResults[i + 1].findSolid().BoundingBox() # get bbox dims
228 cbd = (curBoxDims.xlen, curBoxDims.ylen, curBoxDims.zlen)
229 nbd = (nextBoxDims.xlen, nextBoxDims.ylen, nextBoxDims.zlen)
230 self.assertTupleAlmostEquals(cbd, nbd, 4)
231 self.assertAlmostEqual(
232 boxResults[i].findSolid().Volume(),
233 boxResults[i + 1].findSolid().Volume(),
234 5,
235 )
236
237 def test_mirror_face(self):
238 """Create a triangle and mirror into a unit box"""

Callers

nothing calls this directly

Calls 10

WorkplaneClass · 0.85
boxMethod · 0.80
appendMethod · 0.80
findSolidMethod · 0.80
VolumeMethod · 0.80
translateMethod · 0.45
facesMethod · 0.45
mirrorMethod · 0.45
BoundingBoxMethod · 0.45

Tested by

no test coverage detected