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

Method testEachpoint

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

Source from the content-addressed store, hash-verified

5347 self.assertTrue(Vector(p2.Axis().Direction()) == f2.normalAt())
5348
5349 def testEachpoint(self):
5350
5351 r1 = (
5352 Workplane(origin=(0, 0, 1))
5353 .add(
5354 [
5355 Vector(),
5356 Location(Vector(0, 0, -1,)),
5357 Sketch().rect(1, 1),
5358 Face.makePlane(1, 1),
5359 ]
5360 )
5361 .eachpoint(lambda l: Face.makePlane(1, 1).locate(l))
5362 )
5363
5364 self.assertTrue(len(r1.objects) == 4)
5365
5366 for v in r1.vals():
5367 self.assertTupleAlmostEquals(v.Center().toTuple(), (0, 0, 0), 6)
5368
5369 # test eachpoint with combine = True
5370 box = Workplane().box(2, 1, 1).val()
5371 ref = Workplane().box(5, 5, 5)
5372 r = ref.vertices().eachpoint(lambda loc: box.moved(loc), combine=True)
5373 self.assertGreater(r.val().Volume(), ref.val().Volume())
5374
5375 # test eachpoint with combine = "cut"
5376 r = ref.vertices().eachpoint(lambda loc: box.moved(loc), combine="cut")
5377 self.assertGreater(ref.val().Volume(), r.val().Volume())
5378
5379 # test eachpoint with a wire cutThru()
5380 holeRadius = 1
5381 wire = Wire.makeCircle(holeRadius, (0, 0, 0), (0, 0, 1))
5382 boxHeight = 1
5383 ref = Workplane("XY").box(10, 10, boxHeight)
5384 r = (
5385 ref.faces(">Z")
5386 .rect(7, 7, forConstruction=True)
5387 .vertices()
5388 .eachpoint(wire)
5389 .cutThruAll()
5390 )
5391 holeVolume = math.pi * holeRadius ** 2 * boxHeight
5392 self.assertAlmostEqual(r.val().Volume(), ref.val().Volume() - holeVolume * 4)
5393
5394 # same with useLocalCoordinates, which should give the same result
5395 holeRadius = 1
5396 wire = Wire.makeCircle(holeRadius, (0, 0, 0), (0, 0, 1))
5397 boxHeight = 1
5398 ref = Workplane("XY").box(10, 10, boxHeight)
5399 r = (
5400 ref.faces(">Z")
5401 .rect(7, 7, forConstruction=True)
5402 .vertices()
5403 .eachpoint(wire, useLocalCoordinates=True)
5404 .cutThruAll()
5405 )
5406 holeVolume = math.pi * holeRadius ** 2 * boxHeight

Callers

nothing calls this directly

Calls 15

WorkplaneClass · 0.85
VectorClass · 0.85
LocationClass · 0.85
SketchClass · 0.85
eachpointMethod · 0.80
makePlaneMethod · 0.80
locateMethod · 0.80
boxMethod · 0.80
VolumeMethod · 0.80
cutThruAllMethod · 0.80
sphereMethod · 0.80

Tested by

no test coverage detected