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

Method testIntersect

tests/test_cadquery.py:1719–1752  ·  view source on GitHub ↗

Tests the intersect function.

(self)

Source from the content-addressed store, hash-verified

1717 s0.cut(toCut.val())
1718
1719 def testIntersect(self):
1720 """
1721 Tests the intersect function.
1722 """
1723 s = Workplane(Plane.XY())
1724 currentS = s.rect(2.0, 2.0).extrude(0.5)
1725 toIntersect = s.rect(1.0, 1.0).extrude(1)
1726
1727 resS = currentS.intersect(toIntersect.val())
1728
1729 self.assertEqual(6, resS.faces().size())
1730 self.assertAlmostEqual(resS.val().Volume(), 0.5)
1731
1732 resS = currentS.intersect(toIntersect)
1733
1734 self.assertEqual(6, resS.faces().size())
1735 self.assertAlmostEqual(resS.val().Volume(), 0.5)
1736
1737 b1 = Workplane("XY").box(1, 1, 1)
1738 b2 = Workplane("XY", origin=(0, 0, 0.5)).box(1, 1, 1)
1739 resS = b1.intersect(b2)
1740
1741 self.assertAlmostEqual(resS.val().Volume(), 0.5)
1742
1743 with self.assertRaises(ValueError):
1744 b1.intersect(b2.faces().val())
1745
1746 # Test syntactic sugar [__mul__ method]
1747 sugar = b1 & b2
1748 self.assertEqual(resS.val().Volume(), sugar.val().Volume())
1749
1750 # raise ValueError when no solid found
1751 with raises(ValueError):
1752 Workplane().intersect(toIntersect)
1753
1754 def testBoundingBox(self):
1755 """

Callers

nothing calls this directly

Calls 10

rectMethod · 0.95
WorkplaneClass · 0.85
XYMethod · 0.80
extrudeMethod · 0.80
VolumeMethod · 0.80
boxMethod · 0.80
intersectMethod · 0.45
valMethod · 0.45
sizeMethod · 0.45
facesMethod · 0.45

Tested by

no test coverage detected