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

Method testFuzzyBoolOp

tests/test_cadquery.py:4723–4764  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4721 self.assertEqual(res.faces().size(), 10)
4722
4723 def testFuzzyBoolOp(self):
4724
4725 eps = 1e-3
4726
4727 # test fuse
4728 box1 = Workplane("XY").box(1, 1, 1)
4729 box2 = Workplane("XY", origin=(1 + eps, 0.0)).box(1, 1, 1)
4730 box3 = Workplane("XY", origin=(2, 0, 0)).box(1, 1, 1)
4731
4732 res = box1.union(box2)
4733 res_fuzzy = box1.union(box2, tol=eps)
4734 res_fuzzy2 = box1.union(box3).union(box2, tol=eps)
4735
4736 self.assertEqual(res.solids().size(), 2)
4737 self.assertEqual(res_fuzzy.solids().size(), 1)
4738 self.assertEqual(res_fuzzy2.solids().size(), 1)
4739
4740 # test cut and intersect
4741 box4 = Workplane("XY", origin=(eps, 0.0)).box(1, 1, 1)
4742
4743 res_fuzzy_cut = box1.cut(box4, tol=eps)
4744 res_fuzzy_intersect = box1.intersect(box4, tol=eps)
4745
4746 self.assertAlmostEqual(res_fuzzy_cut.val().Volume(), 0)
4747 self.assertAlmostEqual(res_fuzzy_intersect.val().Volume(), 1)
4748
4749 # test with compounds
4750 box1_cmp = Compound.makeCompound(box1.vals())
4751 box4_cmp = Compound.makeCompound(box4.vals())
4752
4753 res_fuzzy_cut_cmp = box1_cmp.cut(box4_cmp, tol=eps)
4754 res_fuzzy_intersect_cmp = box1_cmp.intersect(box4_cmp, tol=eps)
4755
4756 self.assertAlmostEqual(res_fuzzy_cut_cmp.Volume(), 0)
4757 self.assertAlmostEqual(res_fuzzy_intersect_cmp.Volume(), 1)
4758
4759 # test with solids
4760 res_fuzzy_cut_val = box1.val().cut(box4.val(), tol=eps)
4761 res_fuzzy_intersect_val = box1.val().intersect(box4.val(), tol=eps)
4762
4763 self.assertAlmostEqual(res_fuzzy_cut_val.Volume(), 0)
4764 self.assertAlmostEqual(res_fuzzy_intersect_val.Volume(), 1)
4765
4766 def testLocatedMoved(self):
4767

Callers

nothing calls this directly

Calls 11

WorkplaneClass · 0.85
boxMethod · 0.80
unionMethod · 0.80
VolumeMethod · 0.80
makeCompoundMethod · 0.80
sizeMethod · 0.45
solidsMethod · 0.45
cutMethod · 0.45
intersectMethod · 0.45
valMethod · 0.45
valsMethod · 0.45

Tested by

no test coverage detected