MCPcopy Create free account
hub / github.com/CadQuery/cadquery / testCircumscribedPolygon

Method testCircumscribedPolygon

tests/test_cadquery.py:5502–5545  ·  view source on GitHub ↗

Test that circumscribed polygons result in the correct shapes

(self)

Source from the content-addressed store, hash-verified

5500 assert r6.val().isValid()
5501
5502 def testCircumscribedPolygon(self):
5503 """
5504 Test that circumscribed polygons result in the correct shapes
5505 """
5506
5507 def circumradius(n, a):
5508 return a / math.cos(math.pi / n)
5509
5510 a = 1
5511 # Test triangle
5512 w = Workplane("XY").polygon(3, 2 * a, circumscribed=True)
5513 vs = w.vertices().vals()
5514
5515 self.assertEqual(3, len(vs))
5516
5517 R = circumradius(3, a)
5518
5519 vs0 = w.vertices(">X").vertices(">Y").val()
5520 vs1 = w.vertices("<X").val()
5521 vs2 = w.vertices(">X").vertices("<Y").val()
5522
5523 self.assertEqual(vs0.toTuple(), approx((a, a * math.tan(math.radians(60)), 0)))
5524 self.assertEqual(vs1.toTuple(), approx((-R, 0, 0)))
5525 self.assertEqual(vs2.toTuple(), approx((a, -a * math.tan(math.radians(60)), 0)))
5526
5527 # Test square
5528 w = Workplane("XY").polygon(4, 2 * a, circumscribed=True)
5529 vs = w.vertices().vals()
5530
5531 self.assertEqual(4, len(vs))
5532
5533 R = circumradius(4, a)
5534
5535 vs0 = w.vertices(">X").vertices(">Y").val()
5536 vs1 = w.vertices("<X").vertices(">Y").val()
5537 vs2 = w.vertices("<X").vertices("<Y").val()
5538 vs3 = w.vertices(">X").vertices("<Y").val()
5539
5540 self.assertEqual(vs0.toTuple(), approx((a, a * math.tan(math.radians(45)), 0)))
5541 self.assertEqual(vs1.toTuple(), approx((-a, a * math.tan(math.radians(45)), 0)))
5542 self.assertEqual(
5543 vs2.toTuple(), approx((-a, -a * math.tan(math.radians(45)), 0))
5544 )
5545 self.assertEqual(vs3.toTuple(), approx((a, -a * math.tan(math.radians(45)), 0)))
5546
5547 def test_combineWithBase(self):
5548 # Test the helper mehod _combinewith

Callers

nothing calls this directly

Calls 6

WorkplaneClass · 0.85
polygonMethod · 0.45
valsMethod · 0.45
verticesMethod · 0.45
valMethod · 0.45
toTupleMethod · 0.45

Tested by

no test coverage detected