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

Method testAreaNthSelector_NestedWires

tests/test_selectors.py:839–910  ·  view source on GitHub ↗

Tests key parts of case seam leap creation algorithm (see example 26) - Selecting top outer wire - Applying Offset2D and extruding a "lid" - Selecting the innermost of three wires in preparation to cut through the lid and leave a lip on the case se

(self)

Source from the content-addressed store, hash-verified

837 Workplane("XY").box(10, 10, 10).edges(selectors.AreaNthSelector(0))
838
839 def testAreaNthSelector_NestedWires(self):
840 """
841 Tests key parts of case seam leap creation algorithm
842 (see example 26)
843
844 - Selecting top outer wire
845 - Applying Offset2D and extruding a "lid"
846 - Selecting the innermost of three wires in preparation to
847 cut through the lid and leave a lip on the case seam
848 """
849 # selecting top outermost wire of square box
850 wp = (
851 Workplane("XY")
852 .rect(50, 50)
853 .extrude(50)
854 .faces(">Z")
855 .shell(-5, "intersection")
856 .faces(">Z")
857 .wires(selectors.AreaNthSelector(-1))
858 )
859
860 self.assertEqual(
861 len(wp.vals()),
862 1,
863 msg="Failed to select top outermost wire of the box: wrong N wires",
864 )
865 self.assertAlmostEqual(
866 Face.makeFromWires(wp.val()).Area(),
867 50 * 50,
868 msg="Failed to select top outermost wire of the box: wrong wire area",
869 )
870
871 # preparing to add an inside lip to the box
872 wp = wp.toPending().workplane().offset2D(-2).extrude(1).faces(">Z[-2]")
873 # workplane now has 2 faces selected:
874 # a square and a thin rectangular frame
875
876 wp_outer_wire = wp.wires(selectors.AreaNthSelector(-1))
877 self.assertEqual(
878 len(wp_outer_wire.vals()),
879 1,
880 msg="Failed to select outermost wire of 2 faces: wrong N wires",
881 )
882 self.assertAlmostEqual(
883 Face.makeFromWires(wp_outer_wire.val()).Area(),
884 50 * 50,
885 msg="Failed to select outermost wire of 2 faces: wrong area",
886 )
887
888 wp_mid_wire = wp.wires(selectors.AreaNthSelector(1))
889 self.assertEqual(
890 len(wp_mid_wire.vals()),
891 1,
892 msg="Failed to select middle wire of 2 faces: wrong N wires",
893 )
894 self.assertAlmostEqual(
895 Face.makeFromWires(wp_mid_wire.val()).Area(),
896 (50 - 2 * 2) * (50 - 2 * 2),

Callers

nothing calls this directly

Calls 13

WorkplaneClass · 0.85
extrudeMethod · 0.80
workplaneMethod · 0.80
toPendingMethod · 0.80
wiresMethod · 0.45
facesMethod · 0.45
shellMethod · 0.45
rectMethod · 0.45
valsMethod · 0.45
AreaMethod · 0.45
makeFromWiresMethod · 0.45
valMethod · 0.45

Tested by

no test coverage detected