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

Method test_bezier_curve

tests/test_workplanes.py:254–301  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

252 self.assertAlmostEqual(r.findSolid().Volume(), 1.0, 5)
253
254 def test_bezier_curve(self):
255 # Quadratic bezier
256 r = (
257 Workplane("XZ")
258 .bezier([(0, 0), (1, 2), (5, 0)])
259 .bezier([(1, -2), (0, 0)], includeCurrent=True)
260 .close()
261 .extrude(1)
262 )
263
264 bbBox = r.findSolid().BoundingBox()
265 # Why is the bounding box larger than expected?
266 self.assertTupleAlmostEquals((bbBox.xlen, bbBox.ylen, bbBox.zlen), (5, 1, 2), 1)
267 self.assertAlmostEqual(r.findSolid().Volume(), 6.6666667, 4)
268
269 r = Workplane("XY").bezier([(0, 0), (1, 2), (2, -1), (5, 0)])
270 self.assertTrue(len(r.ctx.pendingEdges) == 1)
271 r = (
272 r.lineTo(5, -0.1)
273 .bezier([(2, -3), (1, 0), (0, 0)], includeCurrent=True)
274 .close()
275 .extrude(1)
276 )
277
278 bbBox = r.findSolid().BoundingBox()
279 self.assertTupleAlmostEquals(
280 (bbBox.xlen, bbBox.ylen, bbBox.zlen), (5, 2.06767, 1), 1
281 )
282 self.assertAlmostEqual(r.findSolid().Volume(), 4.975, 4)
283
284 # Test makewire by translate and loft example like in
285 # the documentation
286 r = Workplane("XY").bezier([(0, 0), (1, 2), (1, -1), (0, 0)], makeWire=True)
287
288 self.assertTrue(len(r.ctx.pendingWires) == 1)
289 r = r.translate((0, 0, 0.2)).toPending().loft()
290 self.assertAlmostEqual(r.findSolid().Volume(), 0.09, 4)
291
292 # Finally test forConstruction
293 r = Workplane("XY").bezier(
294 [(0, 0), (1, 2), (1, -1), (0, 0)], makeWire=True, forConstruction=True
295 )
296 self.assertTrue(len(r.ctx.pendingWires) == 0)
297
298 r = Workplane("XY").bezier(
299 [(0, 0), (1, 2), (2, -1), (5, 0)], forConstruction=True
300 )
301 self.assertTrue(len(r.ctx.pendingEdges) == 0)

Callers

nothing calls this directly

Calls 12

WorkplaneClass · 0.85
extrudeMethod · 0.80
findSolidMethod · 0.80
VolumeMethod · 0.80
lineToMethod · 0.80
loftMethod · 0.80
toPendingMethod · 0.80
closeMethod · 0.45
bezierMethod · 0.45
BoundingBoxMethod · 0.45
translateMethod · 0.45

Tested by

no test coverage detected