def testLengthNthSelector_UnitEdgeAndWire(self): """ Checks that key() method of LengthNthSelector calculates lengths of unit edge correctly """ unit_edge = Edge.makeLine(Vector(0, 0, 0), Vector(0, 0, 1)) self.assertAlmostEqual(1, selectors.LengthNthSelector(0).key(unit_edge), 5) unit_edge = Wire.assembleEdges([unit_edge]) self.assertAlmostEqual(1, selectors.LengthNthSelector(0).key(unit_edge), 5)
def testLengthNthSelector_Faces(self): """ LengthNthSelector should produce empty list when applied to list of unsupported Shapes (Faces) """ with self.assertRaises(IndexError): Workplane().box(1, 1, 1).faces(selectors.LengthNthSelector(0))
def testLengthNthSelector_EmptyEdgesList(self): """ LengthNthSelector should raise ValueError when applied to an empty list """ with self.assertRaises(ValueError): Workplane().edges(selectors.LengthNthSelector(0))
def testLengthNthSelector_UnsupportedShapes(self): """ No length defined for a face, shell, solid or compound """ w0 = Workplane().rarray(2, 2, 2, 1).box(1, 1, 1) for val in [w0.faces().val(), w0.shells().val(), w0.compounds().val()]: with self.assertRaises(ValueError): selectors.LengthNthSelector(0).key(val)
def testLengthNthSelector_EdgesOfUnitCube(self): """ Selecting all edges of unit cube """ w1 = Workplane(makeUnitCube()).edges(selectors.LengthNthSelector(0)) self.assertEqual( 12, w1.size(), msg="Failed to select edges of a unit cube: wrong number of edges", )
def testLengthNthSelector_PlateWithHoles(self): """ Creating 10x10 plate with 4 holes (dia=1) and using LengthNthSelector to select hole rims and plate perimeter wire on the top surface/ """ w2 = (Workplane().box(10, 10, 1).faces(">Z").workplane().rarray( 4, 4, 2, 2).hole(1).faces(">Z")) hole_rims = w2.wires(selectors.LengthNthSelector(0)) self.assertEqual(4, hole_rims.size()) self.assertEqual( 4, hole_rims.size(), msg="Failed to select hole rims: wrong N edges", ) hole_circumference = math.pi * 1 self.assertTupleAlmostEquals( [hole_circumference] * 4, (edge.Length() for edge in hole_rims.vals()), 5, msg="Failed to select hole rims: wrong length", ) plate_perimeter = w2.wires(selectors.LengthNthSelector(1)) self.assertEqual( 1, plate_perimeter.size(), msg="Failed to select plate perimeter wire: wrong N wires", ) self.assertAlmostEqual( 10 * 4, plate_perimeter.val().Length(), 5, msg="Failed to select plate perimeter wire: wrong length", )
def testLengthNthSelector_EdgesOf123Cube(self): """ Selecting 4 edges of length 2 belonging to 1x2x3 box """ w1 = Workplane().box(1, 2, 3).edges(selectors.LengthNthSelector(1)) self.assertEqual( 4, w1.size(), msg= "Failed to select edges of length 2 belonging to 1x2x3 box: wrong number of edges", ) self.assertTupleAlmostEquals( (2, 2, 2, 2), (edge.Length() for edge in w1.vals()), 5, msg= "Failed to select edges of length 2 belonging to 1x2x3 box: wrong length", )