Test extrude
(self)
| 3669 | self.assertTrue(px_face in faces[-2:]) |
| 3670 | |
| 3671 | def testExtrude(self): |
| 3672 | """ |
| 3673 | Test extrude |
| 3674 | """ |
| 3675 | r = 1.0 |
| 3676 | h = 1.0 |
| 3677 | decimal_places = 9.0 |
| 3678 | |
| 3679 | # extrude in one direction |
| 3680 | s = Workplane("XY").circle(r).extrude(h, both=False) |
| 3681 | |
| 3682 | top_face = s.faces(">Z") |
| 3683 | bottom_face = s.faces("<Z") |
| 3684 | |
| 3685 | # calculate the distance between the top and the bottom face |
| 3686 | delta = top_face.val().Center().sub(bottom_face.val().Center()) |
| 3687 | |
| 3688 | self.assertTupleAlmostEquals(delta.toTuple(), (0.0, 0.0, h), decimal_places) |
| 3689 | |
| 3690 | # extrude symmetrically |
| 3691 | s = Workplane("XY").circle(r).extrude(h, both=True) |
| 3692 | |
| 3693 | self.assertTrue(len(s.val().Solids()) == 1) |
| 3694 | |
| 3695 | top_face = s.faces(">Z") |
| 3696 | bottom_face = s.faces("<Z") |
| 3697 | |
| 3698 | # calculate the distance between the top and the bottom face |
| 3699 | delta = top_face.val().Center().sub(bottom_face.val().Center()) |
| 3700 | |
| 3701 | self.assertTupleAlmostEquals( |
| 3702 | delta.toTuple(), (0.0, 0.0, 2.0 * h), decimal_places |
| 3703 | ) |
| 3704 | |
| 3705 | # check that non-conplanar extrusion raises |
| 3706 | with self.assertRaises(ValueError): |
| 3707 | Workplane().box(1, 1, 1).faces().circle(0.1).extrude(0.1) |
| 3708 | |
| 3709 | # check that extruding nested geometry raises |
| 3710 | with self.assertRaises(ValueError): |
| 3711 | Workplane().rect(2, 2).rect(1, 1).extrude(2, taper=4) |
| 3712 | |
| 3713 | # Test extrude with combine="cut" |
| 3714 | box = Workplane().box(5, 5, 5) |
| 3715 | r = box.faces(">Z").workplane(invert=True).circle(0.5).extrude(4, combine="cut") |
| 3716 | self.assertGreater(box.val().Volume(), r.val().Volume()) |
| 3717 | |
| 3718 | # Test extrude with both=True and combine="cut" |
| 3719 | wp_ref = Workplane("XY").rect(40, 40).extrude(20, both=True) |
| 3720 | |
| 3721 | wp_ref_regular_cut = ( |
| 3722 | wp_ref.workplane(offset=-20).rect(20, 20).extrude(40, combine="s") |
| 3723 | ) |
| 3724 | |
| 3725 | wp = wp_ref.workplane().rect(20, 20).extrude(20, both=True, combine="s") |
| 3726 | |
| 3727 | assert wp.faces().size() == 6 + 4 |
| 3728 | self.assertAlmostEqual(wp_ref_regular_cut.val().Volume(), wp.val().Volume()) |
nothing calls this directly
no test coverage detected