def test_createLine(self): eq = self.assertEqual aeq = self.assertAlmostEqual self.assertRaises(OCCError, Edge().createLine, (0., 0., 0.), (0., 0., 0.)) args = \ ( (Vertex(1.,0.,0.), Vertex(-1.,0.,0.)), ((1.,0.,0.), (-1.,0.,0.)), ((0.,1.,0.), (0.,-1.,0.)), ((0.,0.,1.), (0.,0.,-1.)), ) for start, end in args: e1 = Edge().createLine(start, end) eq(len(e1), 2) eq(e1.isNull(), False) eq(e1.isValid(), True) eq(e1.isDegenerated(), False) eq(e1.hasPlane(), False) aeq(e1.length(), 2)
def test_createFace(self): eq = self.assertAlmostEqual self.assertRaises(OCCError, Face().createFace, Wire()) # square face p1 = Vertex(0., 0., 0.) p2 = Vertex(1., 0., 0.) p3 = Vertex(1., 1., 0.) p4 = Vertex(0., 1., 0.) e1 = Edge().createLine(p1, p2) e2 = Edge().createLine(p2, p3) e3 = Edge().createLine(p3, p4) e4 = Edge().createLine(p4, p1) w1 = Wire().createWire((e1, e1, e1, e1)) self.assertRaises(OCCError, Face().createFace, w1) w2 = Wire().createWire((e1, e2, e3, e4)) face = Face().createFace(w2) self.assertEqual(face.numWires(), 1) self.assertEqual(face.numFaces(), 1) eq(face.area(), 1.) # circular face e1 = Edge() center = (0., 0., 0.) normal = (0., 0., 1.) radius = 1. e1.createCircle(center, normal, radius) face = Face().createFace(e1) eq(face.area(), pi, places=4)
def test_rotate(self): eq = self.almostEqual e1 = Edge().createLine((0., 0., 0.), (1., 0., 0.)) e1.rotate(-.5 * pi, (0., 1., 0.)) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (0., 0., 1.)) e1.rotate(.5 * pi, (0., 1., 0.)) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (1., 0., 0.)) e2 = e1.rotate(-.5 * pi, (0., 1., 0.), copy=True) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (1., 0., 0.)) v1, v2 = e2 eq(v1, (0., 0., 0.)) eq(v2, (0., 0., 1.)) e1 = Edge().createLine((0., 0., 0.), (1., 0., 0.)) e1.rotate(-.5 * pi, (0., 1., 0.), (.5, 0., 0.)) v1, v2 = e1 eq(v1, (.5, 0., -.5)) eq(v2, (.5, 0., .5))
def test_length(self): e1 = Edge() # bug in Cython? #self.assertRaises(OCCError, e1.length) e1 = Edge().createLine((0., 0., 0.), (1., 0., 0.)) self.assertAlmostEqual(e1.length(), 1.)
def test_isClosed(self): eq = self.assertEqual e1 = Edge().createCircle(center=(0., 0., 0.), normal=(0., 0., 1.), radius=1.) eq(e1.isClosed(), True) e1 = Edge().createArc((0., 0., 0.), (1., 0., 1.), (1., 0., 0.)) eq(e1.isClosed(), False)
def test_createEllipse(self): eq = self.assertAlmostEqual self.assertRaises(OCCError, Edge().createEllipse, (0., 0., 0.), (0., 0., 1.), 0., 0.) e1 = Edge().createEllipse(center=(0., 0., 0.), normal=(0., 0., 1.), rMajor=1., rMinor=.5) eq(e1.length(), .5 * sqrt(93. + .5 * sqrt(3.)), 1)
def test_createArc3P(self): eq = self.assertAlmostEqual v1 = (0., 0., 0.) self.assertRaises(OCCError, Edge().createArc3P, v1, v1, v1) args = \ ( (Vertex(1.,0.,0.), Vertex(-1.,0.,0.), (0.,1.,0.)), ((1.,0.,0.), (-1.,0.,0.), (0.,1.,0.)), ((1.,1.,0.), (-1.,1.,0.), (0.,2.,0.)), ) for start, end, pnt in args: e1 = Edge().createArc3P(start, end, pnt) eq(e1.length(), pi)
def test_createCircle(self): eq = self.assertAlmostEqual self.assertRaises(OCCError, Edge().createCircle, (0., 0., 0.), (0., 0., 1.), -1.) self.assertRaises(OCCError, Edge().createCircle, (0., 0., 0.), (0., 0., 1.), 0.) e1 = Edge() center = (0., 0., 0.) normal = (0., 0., 1.) radius = 1. e1.createCircle(center, normal, radius) eq(e1.length(), 2 * pi)
def test_createArc(self): eq = self.assertAlmostEqual v1 = (0., 0., 0.) self.assertRaises(OCCError, Edge().createArc, v1, v1, v1) args = \ ( (Vertex(0.,0.,0.), Vertex(1.,0.,1.), (1.,0.,0.)), ((0.,0.,0.), (1.,0.,1.), (1.,0.,0.)), ((0.,1.,0.), (1.,1.,1.), (1.,1.,0.)), ) for start, end, cen in args: e1 = Edge().createArc(start, end, cen) eq(e1.length(), .5 * pi)
def test_createSpline(self): eq = self.almostEqual pnts = ((0., 0., 0.), (0., 0., 0.), (0., 0., 0.), (0., 0., 0.)) self.assertRaises(OCCError, Edge().createSpline, points=pnts) start = Vertex(0., 0., 0.) end = Vertex(1., 0., 0.) pnts = ((0., 2., 0.), (5., 1.5, 0.)) e1 = Edge().createSpline(start, end, pnts) v1, v2 = e1 eq(v1, start) eq(v2, end) pnts = ((0., 0., 0.), (0., 2., 0.), (5., 1.5, 0.), (1., 0., 0.)) e2 = Edge().createSpline(points=pnts) self.assertAlmostEqual(e1.length(), e2.length())
def test_createHelix(self): eq = self.assertAlmostEqual self.assertRaises(OCCError, Edge().createHelix, pitch=.5, height=0., radius=0., angle=pi / 5.) self.assertRaises(OCCError, Edge().createHelix, pitch=.5, height=0., radius=.25, angle=pi / 5.) e1 = Edge().createHelix(pitch=.5, height=1., radius=.25, angle=pi / 5.) self.assertEqual(e1.length() > 1., True)
def test_base(self): eq = self.assertEqual start, end = Vertex(1., 0., 0.), Vertex(-1., 0., 0.) e1 = Edge().createLine(start, end) eq(e1.shapeType() is Edge, True) eq(e1.isNull(), False) eq(e1.isValid(), True) eq(e1.isDegenerated(), False) eq(e1.hasPlane(), False) e2 = e1.copy() eq(e2.isNull(), False) eq(e2.isValid(), True) eq(e2.isDegenerated(), False) eq(e2.hasPlane(), False) # test hallow copy equallity eq(e2.isEqual(e1), True) eq(e2 == e1, True) eq(e2 != e1, False) eq(e1.hashCode() == e2.hashCode(), True) # test copy of underlying geometry e3 = e1.copy(deepCopy=True) eq(e3.isEqual(e1), False) eq(e1.hashCode() == e3.hashCode(), False) # test serialize e4 = Edge().fromString(e1.toString()) eq(e4.isEqual(e1), False) eq(e1.hashCode() == e4.hashCode(), False) eq(len(e1), 2) vertices = set((start.hashCode(), end.hashCode())) for vertex in e1: hid = vertex.hashCode() if hid in vertices: vertices.remove(hid) eq(len(vertices), 0)
def test_extrude(self): eq = self.assertAlmostEqual # square face p1 = Vertex(0., 0., 0.) p2 = Vertex(1., 0., 0.) e1 = Edge().createLine(p1, p2) face = Face().extrude(e1, (0., 0., 0.), (0., 1., 0.)) eq(face.area(), 1.)
def test_bbox(self): eq = self.assertEqual aeq = self.almostEqual e1 = Edge().createLine((1., -2., 3.), (-1., 2., -3.)) bbox = e1.boundingBox() eq(bbox.isValid(), True) aeq(bbox.min, (-1., -2., -3.)) aeq(bbox.max, (1., 2., 3.))
def test_createWire(self): eq = self.assertEqual aeq = self.assertAlmostEqual p1 = Vertex(0., 0., 0.) p2 = Vertex(1., 0., 0.) p3 = Vertex(1., 1., 0.) p4 = Vertex(0., 1., 0.) e1 = Edge().createLine(p1, p2) e2 = Edge().createLine(p2, p3) e3 = Edge().createLine(p3, p4) e4 = Edge().createLine(p4, p1) w1 = Wire().createWire((e1, e2, e3, e4)) eq(len(w1), 4) eq(w1.numVertices(), 4) eq(w1.isNull(), False) eq(w1.isValid(), True) eq(w1.hasPlane(), True) aeq(w1.length(), 4.)
def test_chamfer(self): aeq = self.assertAlmostEqual w1 = Wire() self.assertRaises(OCCError, w1.chamfer, 1.) w1 = Wire().createRectangle(width=1., height=1.) l = w1.length() w1.chamfer(0.1) self.assertEqual(w1.length() != l, True) p1 = Vertex(0., 0., 0.) p2 = Vertex(1., 0., 0.) p3 = Vertex(1., 1., 0.) p4 = Vertex(0., 1., 0.) e1 = Edge().createLine(p1, p2) e2 = Edge().createLine(p2, p3) e3 = Edge().createLine(p3, p4) e4 = Edge().createLine(p4, p1) w2 = Wire().createWire((e1, e2, e3, e4)) w2.chamfer(0.1, (p1, p2, p3, p4)) aeq(w1.length(), w2.length())
def test_hasPlane(self): eq = self.assertEqual aeq = self.almostEqual e5 = Edge().createCircle(center=(0., 0., 0.), normal=(0., 0., 1.), radius=1.) eq(e5.hasPlane(), True) pnt = Point(-1., -1., -1.) vec = Vector(-1., -1., -1.) e5.hasPlane(pnt, vec) aeq(pnt, (0., 0., 0.)) aeq(vec, (0., 0., 1.))
def test_empty(self): eq = self.assertEqual e1 = Edge() self.assertRaises(OCCError, e1.shapeType) eq(e1.isNull(), True) eq(e1.isValid(), False) eq(e1.isDegenerated(), True) eq(e1.hasPlane(), False) eq(len(e1), 0) eq(tuple(e1), ()) m = Transform().translate(1., 2., 3.) self.assertRaises(OCCError, e1.transform, m) self.assertRaises(OCCError, e1.translate, (1., 2., 3.)) self.assertRaises(OCCError, e1.rotate, pi, (0., 1., 0.)) self.assertRaises(OCCError, e1.scale, (0., 0., 0.), 2.)
def test_mirror(self): eq = self.almostEqual e1 = Edge().createLine((0., 0., 0.), (1., 0., 0.)) plane = Plane.fromNormal((0., 0., 0.), (1., 0., 0.)) e1.mirror(plane) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (-1., 0., 0.)) e2 = e1.mirror(plane, copy=True) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (-1., 0., 0.)) v1, v2 = e2 eq(v1, (0., 0., 0.)) eq(v2, (1., 0., 0.))
def test_translate(self): eq = self.almostEqual e1 = Edge().createLine((-1., -2., -3.), (0., 0., 0.)) e1.translate((1., 2., 3.)) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (1., 2., 3.)) e2 = e1.translate((-1., -2., -3.), copy=True) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (1., 2., 3.)) v1, v2 = e2 eq(v1, (-1., -2., -3.)) eq(v2, (0., 0., 0.))
def test_scale(self): eq = self.almostEqual e1 = Edge().createLine((0., 0., 0.), (1., 0., 1.)) e1.scale((0., 0., 0.), .5) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (.5, 0., .5)) e2 = e1.scale((0., 0., 0.), 2., copy=True) v1, v2 = e1 eq(v1, (0., 0., 0.)) eq(v2, (.5, 0., .5)) v1, v2 = e2 eq(v1, (0., 0., 0.)) eq(v2, (1., 0., 1.))