예제 #1
0
    def testAreaNthSelector_NonplanarWire(self):
        """
        AreaNthSelector should raise ValueError when
        used on non-planar wires so that they are ignored by
        _NthSelector.

        Non-planar wires in stack should not prevent selection of
        planar wires.
        """
        wp = Workplane("XY").circle(10).extrude(50)

        with self.assertRaises(IndexError):
            wp.wires(selectors.AreaNthSelector(1))

        cylinder_flat_ends = wp.wires(selectors.AreaNthSelector(0))
        self.assertEqual(
            len(cylinder_flat_ends.vals()),
            2,
            msg="Failed to select cylinder flat end wires: wrong N wires",
        )
        self.assertTupleAlmostEquals(
            [math.pi * 10**2] * 2,
            [
                Face.makeFromWires(wire).Area()
                for wire in cylinder_flat_ends.vals()
            ],
            5,
            msg="Failed to select cylinder flat end wires: wrong area",
        )
예제 #2
0
    def testAreaNthSelector_Solids(self):
        """
        Selecting 2 of 3 solids by surface area
        """

        sizes_iter = iter([10.0, 20.0, 20.0])

        def next_box(loc):
            size = next(sizes_iter)
            return Workplane().box(size, size, size).val().located(loc)

        workplane_solids = Workplane().rarray(30, 1, 3, 1).eachpoint(next_box)

        selected_solids = workplane_solids.solids(selectors.AreaNthSelector(1))

        self.assertEqual(
            len(selected_solids.vals()),
            2,
            msg="Failed to select two larger solids: wrong N shells",
        )
        self.assertTupleAlmostEquals(
            [20 * 20 * 6] * 2,
            [solid.Area() for solid in selected_solids.vals()],
            5,
            msg="Failed to select two larger solids: wrong area",
        )
예제 #3
0
    def testAreaNthSelector_Shells(self):
        """
        Selecting one of three shells with the smallest surface area
        """

        sizes_iter = iter([10.0, 20.0, 30.0])

        def next_box_shell(loc):
            size = next(sizes_iter)
            return Workplane().box(size, size, size).val().located(loc)

        workplane_shells = Workplane().rarray(10, 1, 3,
                                              1).eachpoint(next_box_shell)

        selected_shells = workplane_shells.shells(selectors.AreaNthSelector(0))

        self.assertEqual(
            len(selected_shells.vals()),
            1,
            msg="Failed to select the smallest shell: wrong N shells",
        )
        self.assertAlmostEqual(
            selected_shells.val().Area(),
            10 * 10 * 6,
            msg="Failed to select the smallest shell: wrong area",
        )
예제 #4
0
 def testAreaNthSelector_Edges(self):
     """
     Using AreaNthSelector on unsupported Shapes (Edges)
     should produce empty list
     """
     with self.assertRaises(IndexError):
         Workplane("XY").box(10, 10, 10).edges(selectors.AreaNthSelector(0))
예제 #5
0
    def testAreaNthSelector_Faces(self):
        """
        Selecting two faces of 10x20x30 box with intermediate area.
        """
        wp = Workplane("XY").box(10, 20,
                                 30).faces(selectors.AreaNthSelector(1))

        self.assertEqual(
            len(wp.vals()),
            2,
            msg="Failed to select two faces of 10-20-30 box "
            "with intermediate area: wrong N faces",
        )
        self.assertTupleAlmostEquals(
            (wp.vals()[0].Area(), wp.vals()[1].Area()),
            (10 * 30, 10 * 30),
            7,
            msg="Failed to select two faces of 10-20-30 box "
            "with intermediate area: wrong area",
        )
예제 #6
0
    def testAreaNthSelector_NestedWires(self):
        """
        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 seam
        """
        # selecting top outermost wire of square box
        wp = (Workplane("XY").rect(50, 50).extrude(50).faces(">Z").shell(
            -5,
            "intersection").faces(">Z").wires(selectors.AreaNthSelector(-1)))

        self.assertEqual(
            len(wp.vals()),
            1,
            msg="Failed to select top outermost wire of the box: wrong N wires",
        )
        self.assertAlmostEqual(
            Face.makeFromWires(wp.val()).Area(),
            50 * 50,
            msg=
            "Failed to select top outermost wire of the box: wrong wire area",
        )

        # preparing to add an inside lip to the box
        wp = wp.toPending().workplane().offset2D(-2).extrude(1).faces(">Z[-2]")
        # workplane now has 2 faces selected:
        # a square and a thin rectangular frame

        wp_outer_wire = wp.wires(selectors.AreaNthSelector(-1))
        self.assertEqual(
            len(wp_outer_wire.vals()),
            1,
            msg="Failed to select outermost wire of 2 faces: wrong N wires",
        )
        self.assertAlmostEqual(
            Face.makeFromWires(wp_outer_wire.val()).Area(),
            50 * 50,
            msg="Failed to select outermost wire of 2 faces: wrong area",
        )

        wp_mid_wire = wp.wires(selectors.AreaNthSelector(1))
        self.assertEqual(
            len(wp_mid_wire.vals()),
            1,
            msg="Failed to select middle wire of 2 faces: wrong N wires",
        )
        self.assertAlmostEqual(
            Face.makeFromWires(wp_mid_wire.val()).Area(),
            (50 - 2 * 2) * (50 - 2 * 2),
            msg="Failed to select middle wire of 2 faces: wrong area",
        )

        wp_inner_wire = wp.wires(selectors.AreaNthSelector(0))
        self.assertEqual(
            len(wp_inner_wire.vals()),
            1,
            msg="Failed to select inner wire of 2 faces: wrong N wires",
        )
        self.assertAlmostEqual(
            Face.makeFromWires(wp_inner_wire.val()).Area(),
            (50 - 5 * 2) * (50 - 5 * 2),
            msg="Failed to select inner wire of 2 faces: wrong area",
        )