def test_reverse(self): "" pl = Polyline2D(*points) self.assertEqual( pl.reverse, Polyline2D(Point2D(1, 1), Point2D(0, 1), Point2D(0, 0)))
def test___eq__(self): "" pl = Polyline2D(*points) self.assertTrue(pl == pl) self.assertTrue( pl == Polyline2D(Point2D(1, 1), Point2D(0, 1), Point2D(0, 0)))
def test_segments(self): "" pl = Polyline2D(*points) self.assertEqual( pl.segments, Segments(Segment2D(Point2D(0, 0), Point2D(0, 1)), Segment2D(Point2D(0, 1), Point2D(1, 1))))
def test_add_all(self): "" pgs = Polygons(*polygons) self.assertEqual( pgs.add_all, Polygons( Polygon2D(Point2D(0.0, 1.0), Point2D(0.0, 0.0), Point2D(1.0, 0.0), Point2D(1.0, 1.0))))
def test___eq__(self): "" pls=Polylines(*polylines) self.assertTrue(pls==pls) pls1=Polylines(*polylines) pls1.append(Polyline2D(Point2D(1,1), Point2D(0,1))) self.assertFalse(pls==pls1)
def test_polylines(self): "" pgs = Polygons(*polygons) self.assertEqual( pgs.polylines, Polylines( Polyline2D(Point2D(0.0, 0.0), Point2D(1.0, 0.0), Point2D(0.0, 1.0), Point2D(0.0, 0.0)), Polyline2D(Point2D(1.0, 0.0), Point2D(1.0, 1.0), Point2D(0.0, 1.0), Point2D(1.0, 0.0))))
def test_add_first(self): "" pgs = Polygons(*polygons) pg = Polygon2D(Point2D(0, 0), Point2D(1, 0), Point2D(1, -1)) self.assertEqual(pgs.add_first(pg), (Polygon2D(Point2D(1, 0), Point2D(1, -1), Point2D( 0, 0), Point2D(0.0, 1.0)), 0))
def test_append(self): "" pls=Polylines(*polylines) pls.append(Polyline2D(Point2D(1,1), Point2D(0,1))) self.assertEqual(len(pls),3) pls.append(Polyline2D(Point2D(1,1), Point2D(0,1))) self.assertEqual(len(pls),4) pls.append(Polyline2D(Point2D(0,1), Point2D(1,1)), unique=True) self.assertEqual(len(pls),4)
10))), (Points(), Segments(Segment2D(Point2D(1.5, 0), Point2D(1.5, 0.5)), Segment2D(Point2D(1.5, 1.5), Point2D(1.5, 2))))) def test_plot(self): "" def test_polylines(self): "" pgs = Polygons(*polygons) self.assertEqual( pgs.polylines, Polylines( Polyline2D(Point2D(0.0, 0.0), Point2D(1.0, 0.0), Point2D(0.0, 1.0), Point2D(0.0, 0.0)), Polyline2D(Point2D(1.0, 0.0), Point2D(1.0, 1.0), Point2D(0.0, 1.0), Point2D(1.0, 0.0)))) def test_project_3D(self): "" if __name__ == '__main__': polygons = (Polygon2D(Point2D(0.0, 0.0), Point2D(1.0, 0.0), Point2D(0.0, 1.0)), Polygon2D(Point2D(1.0, 0.0), Point2D(1.0, 1.0), Point2D(0.0, 1.0))) unittest.main(Test_Polygons())
def test_add_first(self): "" pls=Polylines(*polylines) self.assertEqual(pls.add_first(Polyline2D(Point2D(-1,0), Point2D(0,0))), (Polyline2D(Point2D(-1,0), Point2D(0,0), Point2D(1,0)), 0)) self.assertEqual(pls.add_first(Polyline2D(Point2D(0,0), Point2D(-1,0))), (Polyline2D(Point2D(-1,0), Point2D(0,0), Point2D(1,0)), 0)) self.assertEqual(pls.add_first(Polyline2D(Point2D(1,1), Point2D(1,2))), (Polyline2D(Point2D(1,0), Point2D(1,1), Point2D(1,2)), 1)) self.assertEqual(pls.add_first(Polyline2D(Point2D(1,2), Point2D(1,1))), (Polyline2D(Point2D(1,0), Point2D(1,1), Point2D(1,2)), 1))
def test_add_all(self): pls=Polylines(*polylines) # no additions self.assertEqual(pls.add_all, Polylines(Polyline2D(Point2D(0,0), Point2D(1,0), Point2D(1,1)))) pls=Polylines(Polyline2D(Point2D(0,0),Point2D(1,0)), Polyline2D(Point2D(1,0),Point2D(1,1)), Polyline2D(Point2D(10,0),Point2D(11,0)), Polyline2D(Point2D(11,0),Point2D(11,1))) self.assertEqual(pls.add_all, Polylines(Polyline2D(Point2D(0,0), Point2D(1,0), Point2D(1,1)), Polyline2D(Point2D(10,0), Point2D(11,0), Point2D(11,1)))) pls=Polylines(Polyline2D(Point2D(0,0),Point2D(1,0)), Polyline2D(Point2D(1,0),Point2D(1,1)), Polyline2D(Point2D(1,1),Point2D(0,1)), Polyline2D(Point2D(0,1),Point2D(0,0))) self.assertEqual(pls.add_all, Polylines(Polyline2D(Point2D(0,0), Point2D(1,0), Point2D(1,1), Point2D(0,1), Point2D(0,0))))
Point2D(0,1))) self.assertEqual(len(pls),3) pls.append(Polyline2D(Point2D(1,1), Point2D(0,1))) self.assertEqual(len(pls),4) pls.append(Polyline2D(Point2D(0,1), Point2D(1,1)), unique=True) self.assertEqual(len(pls),4) def test_segments(self): "" pls=Polylines(*polylines) self.assertEqual(pls.segments, Segments(Segment2D(Point2D(0,0),Point2D(1,0)), Segment2D(Point2D(1,0),Point2D(1,1)))) if __name__=='__main__': polylines=(Polyline2D(Point2D(0,0), Point2D(1,0)), Polyline2D(Point2D(1,0), Point2D(1,1))) unittest.main(Test_Polylines())
def test_difference_polyline(self): "" pl = Polyline2D(*points) # no intersection pl1 = Polyline2D(Point2D(10, 0), Point2D(10, 1)) self.assertEqual(pl.difference_polyline(pl1), Polylines(pl)) # full overlap self.assertEqual(pl.difference_polyline(pl), Polylines()) # overlap 1 segment self.assertEqual( pl.difference_polyline(Polyline2D(Point2D(0, 1), Point2D(1, 1))), Polylines(Polyline2D(Point2D(0, 0), Point2D(0, 1)))) # partial overlap 1 segment self.assertEqual( pl.difference_polyline(Polyline2D(Point2D(0, 1), Point2D(0.5, 1))), Polylines(Polyline2D(Point2D(0, 0), Point2D(0, 1)), Polyline2D(Point2D(0.5, 1.0), Point2D(1, 1))))
def test_add_segments(self): "" pl = Polyline2D(*points) self.assertEqual(pl.add_segments, pl) pl = Polyline2D(Point2D(0, 0), Point2D(1, 0), Point2D(2, 0)) self.assertEqual(pl.add_segments, Polyline2D(Point2D(0, 0), Point2D(2, 0))) pl = Polyline2D(Point2D(0, 0), Point2D(1, 0), Point2D(2, 0), Point2D(2, 1)) self.assertEqual( pl.add_segments, Polyline2D(Point2D(0, 0), Point2D(2, 0), Point2D(2, 1)))
def test___add__(self): "" pl = Polyline2D(*points) # # no union # self.assertEqual(pl+Polyline2D(Point2D(2,2), # Point2D(3,3)), # None) # now raises a ValueError # union self.assertEqual( pl + Polyline2D(Point2D(1, 1), Point2D(1, 2), Point2D(2, 2)), Polyline2D(Point2D(0, 0), Point2D(0, 1), Point2D(1, 1), Point2D(1, 2), Point2D(2, 2))) self.assertEqual( pl + Polyline2D(Point2D(2, 2), Point2D(1, 2), Point2D(1, 1)), Polyline2D(Point2D(0, 0), Point2D(0, 1), Point2D(1, 1), Point2D(1, 2), Point2D(2, 2))) self.assertEqual( pl + Polyline2D(Point2D(1, 0), Point2D(0, 0)), Polyline2D(Point2D(1, 0), Point2D(0, 0), Point2D(0, 1), Point2D(1, 1))) self.assertEqual( pl + Polyline2D(Point2D(0, 0), Point2D(1, 0)), Polyline2D(Point2D(1, 0), Point2D(0, 0), Point2D(0, 1), Point2D(1, 1)))
def test_intersect_segment(self): "" pg = Polygon2D(Point2D(0, 0), Point2D(2, 0), Point2D(1, 1), Point2D(2, 2), Point2D(0, 2)) pgs = pg._triangulate self.assertEqual( pgs.intersect_segment(Segment2D(Point2D(1.5, 0), Point2D(1.5, 10))), (Points(), Segments(Segment2D(Point2D(1.5, 0), Point2D(1.5, 0.5)), Segment2D(Point2D(1.5, 1.5), Point2D(1.5, 2)))))
def test_segments(self): "" pls=Polylines(*polylines) self.assertEqual(pls.segments, Segments(Segment2D(Point2D(0,0),Point2D(1,0)), Segment2D(Point2D(1,0),Point2D(1,1))))
"" if plot: pl = Polyline3D(*points) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') pl.plot(ax) def test_reverse(self): "" pl = Polyline3D(*points) self.assertEqual( pl.reverse, Polyline3D(Point3D(1, 1, 0), Point3D(0, 1, 0), Point3D(0, 0, 0))) def test_segments(self): "" pl = Polyline3D(*points) self.assertEqual( pl.segments, Segments(Segment3D(Point3D(0, 0, 0), Point3D(0, 1, 0)), Segment3D(Point3D(0, 1, 0), Point3D(1, 1, 0)))) if __name__ == '__main__': points = Points(Point2D(0, 0), Point2D(0, 1), Point2D(1, 1)) unittest.main(Test_Polyline2D()) points = Points(Point3D(0, 0, 0), Point3D(0, 1, 0), Point3D(1, 1, 0)) unittest.main(Test_Polyline3D())