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

Method testBasicBoundingBox

tests/test_cad_objects.py:64–113  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

62 self.assertEqual(Vector, type(v.Center()))
63
64 def testBasicBoundingBox(self):
65 v = Vertex.makeVertex(1, 1, 1)
66 v2 = Vertex.makeVertex(2, 2, 2)
67 self.assertEqual(BoundBox, type(v.BoundingBox()))
68 self.assertEqual(BoundBox, type(v2.BoundingBox()))
69
70 bb1 = v.BoundingBox().add(v2.BoundingBox())
71
72 # OCC uses some approximations
73 self.assertAlmostEqual(bb1.xlen, 1.0, 1)
74
75 # Test adding to an existing bounding box
76 v0 = Vertex.makeVertex(0, 0, 0)
77 bb2 = v0.BoundingBox().add(v.BoundingBox())
78
79 bb3 = bb1.add(bb2)
80 self.assertTupleAlmostEquals((2, 2, 2), (bb3.xlen, bb3.ylen, bb3.zlen), 7)
81
82 bb3 = bb2.add((3, 3, 3))
83 self.assertTupleAlmostEquals((3, 3, 3), (bb3.xlen, bb3.ylen, bb3.zlen), 7)
84
85 bb3 = bb2.add(Vector(3, 3, 3))
86 self.assertTupleAlmostEquals((3, 3, 3), (bb3.xlen, bb3.ylen, bb3.zlen), 7)
87
88 # Test 2D bounding boxes
89 bb1 = (
90 Vertex.makeVertex(1, 1, 0)
91 .BoundingBox()
92 .add(Vertex.makeVertex(2, 2, 0).BoundingBox())
93 )
94 bb2 = (
95 Vertex.makeVertex(0, 0, 0)
96 .BoundingBox()
97 .add(Vertex.makeVertex(3, 3, 0).BoundingBox())
98 )
99 bb3 = (
100 Vertex.makeVertex(0, 0, 0)
101 .BoundingBox()
102 .add(Vertex.makeVertex(1.5, 1.5, 0).BoundingBox())
103 )
104 # Test that bb2 contains bb1
105 self.assertEqual(bb2, BoundBox.findOutsideBox2D(bb1, bb2))
106 self.assertEqual(bb2, BoundBox.findOutsideBox2D(bb2, bb1))
107 # Test that neither bounding box contains the other
108 self.assertIsNone(BoundBox.findOutsideBox2D(bb1, bb3))
109
110 # Test creation of a bounding box from a shape - note the low accuracy comparison
111 # as the box is a little larger than the shape
112 bb1 = BoundBox._fromTopoDS(Solid.makeCylinder(1, 1).wrapped, optimal=False)
113 self.assertTupleAlmostEquals((2, 2, 1), (bb1.xlen, bb1.ylen, bb1.zlen), 1)
114
115 def testEdgeWrapperCenter(self):
116 e = self._make_circle()

Callers

nothing calls this directly

Calls 8

VectorClass · 0.85
makeVertexMethod · 0.80
findOutsideBox2DMethod · 0.80
_fromTopoDSMethod · 0.80
makeCylinderMethod · 0.80
BoundingBoxMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected