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_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__(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_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_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_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)
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___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_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_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___repr__(self): "" pl = Polyline2D(*points) self.assertEqual(str(pl), 'Polyline2D(Point2D(0,0),Point2D(0,1),Point2D(1,1))')
def test___init__(self): "" pl = Polyline2D(*points) self.assertIsInstance(pl, Polyline2D) self.assertEqual(pl.points, points)
def test_plot(self): "" if plot: pl = Polyline2D(*points) fig, ax = plt.subplots() pl.plot(ax)
def test_is_intersecting(self): "" pl = Polyline2D(*points) self.assertFalse(pl.is_intersecting)