def test_remove_points_in_segments(self): "" pts = Points(Point(0,0), Point(1,0)) segments = Segments(Segment(Point(0,0), Point(0,1))) pts.remove_points_in_segments(segments) self.assertEqual(pts, Points(Point(1.0,0.0)))
def test_points(self): "" P0, P1 = Point(0, 0), Point(1, 1) s = Segment(P0, P1) self.assertEqual(s.points, Points(P0, P1)) P0, P1 = Point(0, 0, 0), Point(1, 1, 1) s = Segment(P0, P1) self.assertEqual(s.points, Points(P0, P1))
def test___init__(self): "" pg = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)) self.assertIsInstance(pg, Polygon) self.assertEqual( pg.points, Points(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)))
def test_order(self): "" s = Segment3D(P0, P1) self.assertEqual(s.order.points, s.points) s = Segment3D(P1, P0) self.assertEqual(s.order.points, Points(Point3D(0, 0, 0), Point3D(1, 1, 1)))
def _test_intersect_segment(self): "" s = Segments(*segments) # no intersection self.assertEqual( s.intersect_segment(Segment2D(Point2D(-1, 0), Point2D(-0.5, 0))), (Points(), Segments())) # single point intersection self.assertEqual( s.intersect_segment(Segment2D(Point2D(-1, 0), Point2D(0, 0))), (Points(Point2D(0, 0)), Segments())) # two point intersection self.assertEqual( s.intersect_segment(Segment2D(Point2D(0, 0), Point2D(1, 1))), (Points(Point2D(0, 0), Point2D(1, 1)), Segments())) # segment intersection self.assertEqual( s.intersect_segment(Segment2D(Point2D(0, 0), Point2D(1, 0))), (Points(), Segments(Segment2D(Point2D(0, 0), Point2D(1, 0))))) self.assertEqual( s.intersect_segment(Segment2D(Point2D(-1, 0), Point2D(1, 0))), (Points(), Segments(Segment2D(Point2D(0, 0), Point2D(1, 0))))) self.assertEqual( s.intersect_segment(Segment2D(Point2D(0, 0), Point2D(2, 0))), (Points(), Segments(Segment2D(Point2D(0, 0), Point2D(1, 0))))) self.assertEqual( s.intersect_segment(Segment2D(Point2D(-1, 0), Point2D(2, 0))), (Points(), Segments(Segment2D(Point2D(0, 0), Point2D(1, 0)))))
def test_intersect_polyline(self): "" pv = PlaneVolume3D(P0, N) # single point intersection pl = Polyline3D(P0, P0 + N, Point3D(1, 0, 0) + N) self.assertEqual(pv.intersect_polyline(pl), (Points(Point3D(0, 0, 0)), Polylines())) # two point intersection pl = Polyline3D(P0, P0 + N, Point3D(1, 0, 0) + N, Point3D(1, 0, 0)) self.assertEqual( pv.intersect_polyline(pl), (Points(Point3D(0, 0, 0), Point3D(1, 0, 0)), Polylines())) # full intersection pl = Polyline3D(P0, P0 - N, Point3D(1, 0, 0) - N, Point3D(1, 0, 0)) self.assertEqual(pv.intersect_polyline(pl), (Points(), Polylines(pl)))
def test___init__(self): "" pt=Point(0,0) pts=Points(pt) self.assertIsInstance(pts, Points) self.assertEqual(pts[0], pt) self.assertEqual(len(pts), 1) pt1=Point(1,1) pts.append(pt1) self.assertEqual(pts[1], pt1) del pts[0] self.assertEqual(pts[0], pt1)
def test_points(self): "" ph = Polyhedron( Polygon(Point(0, 1, 0), Point(1, 1, 0), Point(0, 0, 0)), Polygon(Point(0, 0, 0), Point(1, 1, 0), Point(0, 1, 1)), Polygon(Point(0, 1, 1), Point(0, 1, 0), Point(0, 0, 0)), Polygon(Point(1, 1, 0), Point(0, 1, 0), Point(0, 1, 1))) self.assertEqual( ph.points, Points(Point(0.0, 1.0, 0.0), Point(1.0, 1.0, 0.0), Point(0.0, 0.0, 0.0), Point(0.0, 1.0, 1.0)))
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_intersect_segments(self): "" s = Segments(*segments) self.assertEqual(s.intersect_segments(s), (Points(), s))
"" 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())
def test_plot(self): "" return pts = Points(Point(0.5, 0.5), Point(1.5, 0.5)) pts.plot()
def test_points(self): "" s = Segment3D(P0, P1) self.assertEqual(s.points, Points(P0, P1))