def runTest(self): subpath = geom.Subpath() subpath.AddSegment(('L', (0.0, 0.0), (3.0, 0.0))) subpath.AddSegment(('L', (3.0, 0.0), (3.0, 5.0))) subpath.AddSegment( ('B', (3.0, 5.0), (0.0, 5.0), (2.0, 6.0), (1.0, 6.0))) subpath.closed = True opt = art2polyarea.ConvertOptions() pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(pa.points.pos, [(0.0, 0.0), (3.0, 0.0), (3.0, 5.0), (1.5, 5.75), (0.0, 5.0)]) self.assertEqual(pa.poly, [0, 1, 2, 3, 4]) subpath = geom.Subpath() subpath.AddSegment(('L', (0.0, 0.0), (1.0, 0.0))) opt = art2polyarea.ConvertOptions() opt.smoothness = 0 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(pa.poly, []) subpath = _MakePolySubpath([(0.0, 0.0), (0.000001, 0.0), (1.0, 0.0), (2.0, 2.0), (2.0, 2.0004), (3.0, 5.0), (0.0, -0.00003)]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(pa.points.pos, [(0.0, 0.0), (1.0, 0.0), (2.0, 2.0), (3.0, 5.0)]) self.assertEqual(pa.poly, [0, 1, 2, 3])
def runTest(self): # pa0 is square, containing triangles pa1 and pa2 # pa3 is triangle outside them all pa0 = geom.PolyArea( geom.Points([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]), [0, 3, 2, 1]) pa1 = geom.PolyArea(geom.Points([(0.2, 0.2), (0.8, 0.2), (0.5, 0.5)]), [0, 1, 2]) pa2 = geom.PolyArea(geom.Points([(0.3, 0.6), (0.7, 0.6), (0.5, 0.9)]), [0, 1, 2]) pa3 = geom.PolyArea(geom.Points([(2.0, 0.0), (3.0, 0.0), (3.0, 1.0)]), [0, 1, 2]) ans = art2polyarea.CombineSimplePolyAreas([pa0, pa1, pa2, pa3]) self.assertEqual(len(ans), 2) a1 = ans[0] a2 = ans[1] self.assertEqual(a1.points.pos, [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.2, 0.2), (0.8, 0.2), (0.5, 0.5), (0.3, 0.6), (0.7, 0.6), (0.5, 0.9)]) self.assertEqual(a1.poly, [0, 3, 2, 1]) self.assertEqual(len(a1.holes), 2) self.assertIn([6, 5, 4], a1.holes) self.assertIn([9, 8, 7], a1.holes) self.assertEqual(a2.points.pos, [(2.0, 0.0), (3.0, 0.0), (3.0, 1.0)]) self.assertEqual(a2.poly, [0, 1, 2]) self.assertEqual(a2.holes, [])
def runTest(self): subpath = geom.Subpath() m = 0.551784 # magic number for circle approx by 4 beziers subpath.AddSegment( ('B', (0.0, 0.0), (1.0, 1.0), (m, 0.0), (1.0, 1.0 - m))) subpath.AddSegment( ('B', (1.0, 1.0), (0.0, 2.0), (1.0, 1.0 + m), (m, 2.0))) subpath.AddSegment(('L', (0.0, 2.0), (0.0, 0.0))) subpath.closed = True path = geom.Path() path.AddSubpath(subpath) opt = art2polyarea.ConvertOptions() opt.subdiv_kind = "EVEN" opt.smoothness = 0 art2polyarea._SetEvenLength(opt, [path]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 10) opt.smoothness = 1 art2polyarea._SetEvenLength(opt, [path]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 18) opt.smoothness = 2 art2polyarea._SetEvenLength(opt, [path]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 26)
def runTest(self): pts = geom.Points() pts.AddPoint((0.0, 0.0)) pts.AddPoint((1.0, 2.0)) pts.AddPoint((3.0, 4.0)) pts2 = geom.Points([(1.0, 2.0), (10.0, 10.0)]) vmap = pts.AddPoints(pts2) self.assertEqual(len(pts.pos), 4) self.assertEqual(vmap, [1, 3]) self.assertEqual(pts.pos[3], (10.0, 10.0))
def testTwoHoles(self): pa = geom.PolyArea(Vs1, F1square) pahole1 = geom.PolyArea( geom.Points([(0.2, 0.5, 0.0), (0.4, 0.65, 0.0), (0.45, 0.8, 0.0)]), [0, 1, 2]) pa.AddHole(pahole1) pahole2 = geom.PolyArea( geom.Points([(0.5, 0.3, 0.0), (0.8, 0.35, 0.0), (0.75, 0.65, 0.0)]), [0, 1, 2]) pa.AddHole(pahole2) o = offset.Offset(pa, 0.0, 0.0) o.Build() self.assertEqual(len(o.inneroffsets), 1) if SHOW: ShowOffset(o)
def testReversededges(self): pts = geom.Points([(0.0,0.0),(1.0,0.0),(0.2,1.0),(1.2,1.0),(1.5,0.0)]) tris = [[0,1,3], [0,3,2], [1,4,3]] bord = triquad._BorderEdges([[0,1,4,3,2]]) td = triquad._TriDict(tris) ans = triquad._ReveresedEdges(tris, td, bord, pts) self.assertEqual(ans, [(0,3)])
def runTest(self): pts = geom.Points([(0.0, -2.0), (0.5, 0.0), (1.0, 0.0), (2.0, 1.0), (3.0, 0.0)]) pa = geom.PolyArea(pts, [0, 1, 2, 3, 4]) o = offset.Offset(pa, 0.0, 0.0) sp = o.facespokes[0][1] ev = sp.VertexEvent(o.facespokes[0][2], pa.points) self.assertEqual(ev, None)
def runTest(self): subpath = geom.Subpath() m = 0.551784 # magic number for circle approx by 4 beziers subpath.AddSegment( ('B', (0.0, 0.0), (1.0, 1.0), (m, 0.0), (1.0, 1.0 - m))) subpath.AddSegment( ('B', (1.0, 1.0), (0.0, 2.0), (1.0, 1.0 + m), (m, 2.0))) subpath.AddSegment( ('B', (0.0, 2.0), (-1.0, 1.0), (-m, 2.0), (-1.0, 1.0 + m))) subpath.AddSegment( ('B', (-1.0, 1.0), (0.0, 0.0), (-1.0, 1.0 - m), (-m, 0.0))) subpath.closed = True opt = art2polyarea.ConvertOptions() opt.subdiv_kind = "ADAPTIVE" opt.smoothness = 0 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 4) opt.smoothness = 1 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 8) opt.smoothness = 2 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 16) opt.smoothness = 3 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 32) opt.smoothness = 4 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 64) opt.smoothness = 5 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 128) opt.smoothness = 6 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 128)
def runTest(self): pts = geom.Points([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.2, 0.2), (1.1, 0.1), (0.8, 0.5)]) a = geom.PolyArea(pts, [0, 1, 2, 3]) b = geom.PolyArea(pts, [4, 5, 2, 6]) ans = art2polyarea._ClassifyPathPairs(a, b) self.assertEqual(ans, (2, 1)) ans = art2polyarea._ClassifyPathPairs(b, a) self.assertEqual(ans, (0, 1))
def runTest(self): pts = geom.Points() self.assertEqual(len(pts.pos), 0) v0 = pts.AddPoint((0.5, -1.0)) self.assertEqual(len(pts.pos), 1) self.assertEqual(v0, 0) self.assertEqual(pts.pos[0], (0.5, -1.0)) v1 = pts.AddPoint((0.5003, -1.0)) self.assertEqual(v1, 0)
def testIsreversed(self): pts = geom.Points([(0.0,0.0),(1.0,0.0),(0.2,1.0),(1.2,1.0)]) tris1 = [[0,1,3],[0,3,2]] tris2 = [[0,1,2],[1,3,2]] td1 = triquad._TriDict(tris1) td2 = triquad._TriDict(tris2) self.assertTrue(triquad._IsReversed((0,3), td1, pts)) self.assertFalse(triquad._IsReversed((1,2), td2, pts)) self.assertFalse(triquad._IsReversed((0,1), td1, pts))
def testCCW1(self): pts = geom.Points([(0.0,0.0),(5.0,1.0),(2.0,3.0),(2.0,-3.0),(8.0, 4.0),(10.0,2.0)]) self.assertTrue(triquad.Ccw(0, 1, 2, pts)) self.assertTrue(triquad.Ccw(2, 0, 1, pts)) self.assertTrue(triquad.Ccw(1, 2, 0, pts)) self.assertFalse(triquad.Ccw(0, 1, 3, pts)) self.assertTrue(triquad.Ccw(0, 1, 4, pts)) self.assertFalse(triquad.Ccw(0, 1, 1, pts)) self.assertFalse(triquad.Ccw(0, 1, 5, pts))
def testTri(self): pa = geom.PolyArea( geom.Points([(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.5, 0.25, 0.0)]), [0, 1, 2]) o = offset.Offset(pa, 0.0, 0.0) o.Build() m = geom.Model() m.points = pa.points model.AddOffsetFacesToModel(m, o) if SHOW: showfaces.ShowFaces(m.faces, m.points, "Tri")
def runTest(self): # a parallelogram with base 6, height 3 pts = geom.Points([(0.0, 0.0), (6.0, 0.0), (7.0, 3.0), (1.0, 3.0)]) polygon = [0, 1, 2] a = geom.SignedArea(polygon, pts) self.assertEqual(a, 9.0) polygon = [2, 1, 0] a = geom.SignedArea(polygon, pts) self.assertEqual(a, -9.0) polygon = [0, 1, 2, 3] a = geom.SignedArea(polygon, pts) self.assertEqual(a, 18.0)
def testIrreg(self): pa = geom.PolyArea( geom.Points([(0.0, 0.1, 0.0), (-0.1, -0.2, 0.0), (0.1, -0.25, 0.0), (0.3, 0.05, 0.0), (1.0, 0.0, 0.0), (1.1, 1.0, 0.0), (-0.1, 1.2, 0.0)]), list(range(0, 7))) o = offset.Offset(pa, 0.0, 0.0) o.Build() m = geom.Model() m.points = pa.points model.AddOffsetFacesToModel(m, o) if SHOW: showfaces.ShowFaces(m.faces, m.points, "Irreg")
def testIncircle(self): pts = geom.Points([(math.cos(.1),math.sin(.1)), (math.cos(1.1),math.sin(1.1)), (math.cos(5.0),math.sin(5.0)), (1.1*math.cos(2.0),1.1*math.sin(2.0)), (.9*math.cos(6.0),.9*math.sin(6.0)), (math.cos(6.1),math.sin(6.1))]) self.assertTrue(triquad.InCircle(0, 1, 2, 4, pts)) self.assertFalse(triquad.InCircle(0, 1, 2, 3, pts)) self.assertFalse(triquad.InCircle(0, 1, 2, 5, pts)) self.assertFalse(triquad.InCircle(0, 2, 1, 4, pts)) self.assertTrue(triquad.InCircle(0, 2, 1, 3, pts)) self.assertFalse(triquad.InCircle(0, 2, 1, 5, pts))
def testYZ(self): points = geom.Points([(0., 0., 0.), (0., 1., 0.), (0., 1., 1.), (0., 0., 1.)]) pa = geom.PolyArea(points, [0, 1, 2, 3]) norm = pa.Normal() self.assertEqual(norm, (1.0, 0.0, 0.0)) (pa, transform, newv2oldv) = model._RotatedPolyAreaToXY(pa, norm) self.assertEqual(pa.points.pos, [(0.0, 0.0, 0.0), (0.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 0.0, 0.0)]) for i in range(4): newc = pa.points.pos[i] oldc = points.pos[newv2oldv[i]] self.assertEqual(geom.MulPoint3(newc, transform), oldc)
def runTest(self): pts = geom.Points([(0.0, 0.0), (5.0, 0.0), (5.0, 4.0), (2.0, 2.0), (0.0, 4.0)]) polygon = [0, 1, 2, 3, 4] ans = geom.PointInside((0.1, 0.1), polygon, pts) self.assertEqual(ans, 1) ans = geom.PointInside((1.0, 2.0), polygon, pts) self.assertEqual(ans, 1) ans = geom.PointInside((2.0, 3.0), polygon, pts) self.assertEqual(ans, -1) ans = geom.PointInside((5.0, 0.0), polygon, pts) self.assertEqual(ans, 0) ans = geom.PointInside((0.0, 4.0), polygon, pts) self.assertEqual(ans, 0)
def Cube(): points = geom.Points([(-1., -1., -1.), (1., -1., -1.), (1., 1., -1.), (-1., 1., -1.), (-1., -1., 1.), (1., -1., 1.), (1., 1., 1.), (-1., 1., 1.)]) faces = [ [0, 3, 2, 1], # bottom (XY plane) [4, 5, 6, 7], # top (XY plane) [0, 1, 5, 4], # back (XZ plane) [3, 7, 6, 2], # front (XZ plane) [1, 2, 6, 5], # left (YZ plane) [0, 4, 7, 3] # right (YZ plane) ] m = geom.Model() m.points = points m.faces = faces m.colors = [(1., 0., 0.)] * 6 return m
from vec import triquad from vec import showfaces Show = True # set True if want to see display of triangulations # Some test data sets # Points in pattern: # 4 3 # # # 2 # 0 1 Vs1 = geom.Points([(0.0,0.0), (1.0,0.0), (0.5,0.25), (1.0,1.0), (0.0,1.0)]) F1tri = [0,1,2] F1square = [0,1,3,4] F1concave = [0,2,1,3,4] F1crosses = [0,1,4,3] # Points in pattern # 0 1 # 2 3 4 5 # 6 7 # 8 9 10 11 # 12 13 14 15 Vs2 = geom.Points([(0.0,1.0), (1.75,1.0),
def GridPoints(cols, rows): points = geom.Points() for x in range(cols): for y in range(rows): points.AddPoint((float(x), float(y), 0.0)) return points
def testSegsintersect2(self): pts = geom.Points([(0.0,0.0), (1.0,1.0),(1.0,0.0),(0.0,1.0)]) self.assertFalse(triquad.SegsIntersect(0,2,1,3,pts)) self.assertFalse(triquad.SegsIntersect(2,0,3,1,pts)) self.assertFalse(triquad.SegsIntersect(0,0,0,1,pts)) self.assertFalse(triquad.SegsIntersect(0,1,1,1,pts))
def testSegsintersect3(self): pts = geom.Points([(0.0,0.0), (1.0,0.0),(-0.5,-0.5),(0.5,0.5),(0.5,0.1)]) self.assertFalse(triquad.SegsIntersect(0,1,2,3,pts)) self.assertTrue(triquad.SegsIntersect(0,1,2,4,pts))
def testSegsintersect4(self): pts = geom.Points([(0.0,0.0),(1.0,0.5),(0.25,0.25),(0.75,-1.0)]) self.assertTrue(triquad.SegsIntersect(0,1,2,3,pts))
def testIncircle2(self): pts = geom.Points([(0.92387900000000001, -0.38268400000000002), (0.382683, 0.92388000000000003), (2.6794900000000001e-08, 1.0), (0.70710700000000004, 0.70710700000000004)]) self.assertTrue(triquad.InCircle(0, 1, 2, 3, pts))
import tkinter import vec from vec import offset from vec import geom SHOW = True # should we show interactive display of built offsets? # Some test data sets # Points in pattern: # 4 3 # # # 2 # 0 1 Vs1 = geom.Points([(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.5, 0.25, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0)]) F1tri = [0, 1, 2] F1square = [0, 1, 3, 4] F1concave = [0, 2, 1, 3, 4] # Points in pattern # 0 1 # 2 3 4 5 # 6 7 # 8 9 10 11 # 12 13 14 15 Vs2 = geom.Points([(0.0, 1.0, 0.0), (1.75, 1.0, 0.0), (0.25, 0.75, 0.0), (0.5, 0.75, 0.0), (1.25, 0.75, 0.0), (1.5, 0.75, 0.0), (0.75, 0.5, 0.0), (1.0, 0.5, 0.0), (0.25, 0.25, 0.0), (0.5, 0.25, 0.0), (1.25, 0.25, 0.0), (1.5, 0.25, 0.0),
def testAnglekind(self): pts = geom.Points([(0.0,0.0), (1.0,0.5), (2.0, 0.0), (1.0,1.0), (0.0,1.0), (-1.0, 1.0)]) self.assertEqual(triquad._AngleKind(0, 1, 2, pts), triquad.Angreflex) self.assertEqual(triquad._AngleKind(1, 2, 3, pts), triquad.Angconvex) self.assertEqual(triquad._AngleKind(3, 4, 5, pts), triquad.Angtangential) self.assertEqual(triquad._AngleKind(0, 1, 0, pts), triquad.Ang0)
def testIncone(self): pts = geom.Points([(0.0,0.0), (1.0,0.0), (1.0,1.0), (2.0,0.0), (2.0,2.0), (0.0,2.0)]) self.assertTrue(triquad._InCone(5, 0, 1, 2, triquad.Angconvex, pts)) self.assertTrue(triquad._InCone(5, 1, 2, 3, triquad.Angreflex, pts))
def testCDT1(self): pts = geom.Points([(0.0,0.0),(1.0,0.0),(0.2,1.0),(1.2,1.0),(1.5,0.0)]) tris = [(0,1,3), (0,3,2), (1,4,3)] bord = triquad._BorderEdges([[0,1,4,3,2]]) ans = triquad._CDT(tris, bord, pts) self.assertEqual(ans, [(1, 4, 3), (2, 0, 1), (2, 1, 3)])
def testSegsintersect1(self): pts = geom.Points([(0.0,0.0), (1.0,1.0),(1.0,0.0),(0.0,1.0)]) self.assertTrue(triquad.SegsIntersect(0,1,2,3,pts)) self.assertTrue(triquad.SegsIntersect(0,1,3,2,pts))