Esempio n. 1
0
    def test___eq__(self):
        ""
        pgs = Polygons(*polygons)
        self.assertTrue(pgs == pgs)

        pgs1 = Polygons(polygons[0])
        self.assertFalse(pgs == pgs1)
Esempio n. 2
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))
Esempio n. 3
0
    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))))
Esempio n. 4
0
    def test_bounds(self):
        ""
        pgs = Polygons(Polygon(Point(0, 0), Point(1, 0), Point(1, 1)),
                       Polygon(Point(2, 0), Point(2, 1), Point(1, 0)))
        self.assertEqual(pgs.bounds, (0.0, 0.0, 2.0, 1.0))

        pgs = Polygons(Polygon(Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 0)),
                       Polygon(Point(0, 0, 1), Point(0, 1, 1), Point(1, 1, 1)))
        self.assertEqual(pgs.bounds, (0.0, 0.0, 0.0, 1.0, 1.0, 1.0))
Esempio n. 5
0
    def test___eq__(self):
        ""
        pg = Polygon(Point(0, 0), Point(1, 0), Point(1, 1))
        pg1 = Polygon(Point(2, 0), Point(1, 0), Point(1, 1))
        pgs = Polygons(pg, pg1)

        self.assertEqual(pgs, pgs)

        self.assertFalse(pgs == Polygons(pg))
Esempio n. 6
0
 def test___repr__(self):
     ""
     pgs = Polygons(*polygons)
     self.assertEqual(
         str(pgs),
         '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)))'
     )
Esempio n. 7
0
    def test_plot(self):
        ""
        return
        pgs = Polygons(Polygon(Point(0, 0), Point(1, 0), Point(1, 1)),
                       Polygon(Point(2, 0), Point(2, 1), Point(1, 0)))
        pgs.plot()

        pgs = Polygons(Polygon(Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 0)),
                       Polygon(Point(0, 0, 1), Point(0, 1, 1), Point(1, 1, 1)))
        pgs.plot()
Esempio n. 8
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))))
Esempio n. 9
0
    def test_append(self):
        ""
        pgs = Polygons(*polygons)

        pgs.append(polygons[0])
        self.assertEqual(len(pgs), 3)

        pgs.append(polygons[1])
        self.assertEqual(len(pgs), 4)

        pgs.append(polygons[1], unique=True)
        self.assertEqual(len(pgs), 4)
Esempio n. 10
0
 def test_tetrahedron_from_points(self):
     ""
     ph = tetrahedron_from_points(Point(0, 0, 0), Point(1, 1, 0),
                                  Point(0, 1, 0), Point(0, 1, 1))
     self.assertIsInstance(ph, Polyhedron)
     self.assertEqual(
         ph.polygons,
         Polygons(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))))
Esempio n. 11
0
 def test__shapely(self):
     ""
     pgs = Polygons(Polygon(Point(0, 0), Point(1, 0), Point(1, 1)),
                    Polygon(Point(2, 0), Point(1, 0), Point(1, 1)))
     #print(pgs._shapely); return
     self.assertEqual(
         pgs._shapely,
         shapely.geometry.MultiPolygon([
             shapely.geometry.Polygon(((0, 0), (1, 0), (1, 1))),
             shapely.geometry.Polygon(((2, 0), (1, 0), (1, 1)))
         ]))
Esempio n. 12
0
    def test_polygons(self):
        ""
        pg = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
        #print(pg.polygons); return
        self.assertEqual(
            pg.polygons,
            Polygons(
                Polygon(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0),
                        Point(0.0, 1.0))))

        hole = Polygon(Point(0, 0), Point(0.5, 0), Point(0.5, 0.5),
                       Point(0, 0.5))
        pg = Polygon(Point(0, 0),
                     Point(1, 0),
                     Point(1, 1),
                     Point(0, 1),
                     holes=[hole])
        #print(pg.polygons); return
        self.assertEqual(
            pg.polygons,
            Polygons(
                Polygon(Point(1.0, 0.0), Point(0.5, 0.0), Point(0.5, 0.5),
                        Point(0.0, 0.5), Point(0.0, 1.0), Point(1.0, 1.0))))

        hole = Polygon(Point(0.25, 0.25), Point(0.75, 0.25), Point(0.75, 0.75),
                       Point(0.25, 0.75))
        pg = Polygon(Point(0, 0),
                     Point(1, 0),
                     Point(1, 1),
                     Point(0, 1),
                     holes=[hole])
        #print(pg.polygons); return
        self.assertEqual(
            pg.polygons,
            Polygons(
                Polygon(Point(1.0, 0.25), Point(1.0, 0.0), Point(0.0, 0.0),
                        Point(0.0, 0.25), Point(0.25, 0.25), Point(0.75,
                                                                   0.25)),
                Polygon(Point(0.0, 0.25), Point(0.0, 1.0), Point(1.0, 1.0),
                        Point(1.0, 0.25), Point(0.75, 0.25), Point(0.75, 0.75),
                        Point(0.25, 0.75), Point(0.25, 0.25))))
Esempio n. 13
0
 def test_polyhedron_from_base_polygon_and_extrud_vector(self):
     ""
     ph = polyhedron_from_base_polygon_and_extrud_vector(
         Polygon(Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 0),
                 Point(0, 1, 0)), Vector(0, 0, 1))
     self.assertEqual(
         ph.polygons,
         Polygons(
             Polygon(Point(0, 1, 0), Point(1, 1, 0), Point(1, 0, 0),
                     Point(0, 0, 0)),
             Polygon(Point(0, 0, 1), Point(1, 0, 1), Point(1, 1, 1),
                     Point(0, 1, 1)),
             Polygon(Point(0, 1, 1), Point(1, 1, 1), Point(1, 1, 0),
                     Point(0, 1, 0)),
             Polygon(Point(1, 1, 1), Point(1, 0, 1), Point(1, 0, 0),
                     Point(1, 1, 0)),
             Polygon(Point(1, 0, 1), Point(0, 0, 1), Point(0, 0, 0),
                     Point(1, 0, 0)),
             Polygon(Point(0, 0, 1), Point(0, 1, 1), Point(0, 1, 0),
                     Point(0, 0, 0))))
     self.assertEqual(len(ph.polygons[0].triangles), 2)
     self.assertEqual(len(ph.tetrahedrons), 6)
Esempio n. 14
0
 def test___init__(self):
     ""
     pgs = Polygons(*polygons)
     self.assertIsInstance(pgs, Polygons)
     self.assertEqual(pgs._polygons, list(polygons))
Esempio n. 15
0
    def test_triangles(self):
        ""
        # convex polygon
        pg = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
        #print(pg.triangles); return
        self.assertEqual(
            pg.triangles,
            Polygons(Polygon(Point(0, 1), Point(0, 0), Point(1, 0)),
                     Polygon(Point(1, 0), Point(1, 1), Point(0, 1))))
        # concave polygon
        pg = Polygon(Point(0, 0), Point(2, 0), Point(1, 1), Point(2, 2),
                     Point(0, 2))
        #print(pg.triangles); return
        self.assertEqual(
            pg.triangles,
            Polygons(
                Polygon(Point(0.0, 2.0), Point(0.0, 0.0), Point(1.0, 1.0)),
                Polygon(Point(2.0, 0.0), Point(1.0, 1.0), Point(0.0, 0.0)),
                Polygon(Point(1.0, 1.0), Point(2.0, 2.0), Point(0.0, 2.0))))

        #return
        # example
        #print('test')
        pg = Polygon(Point(221.7423, -84.20669, 6.0),
                     Point(221.7423, -53.63377, 6.0),
                     Point(221.7423, -53.63377, 14.0),
                     Point(221.7423, -54.0921, 14.0),
                     Point(221.7423, -54.0921, 9.02132),
                     Point(221.7423, -60.6546, 9.02132),
                     Point(221.7423, -60.6546, 14.0),
                     Point(221.7423, -63.91502, 14.0),
                     Point(221.7423, -63.91502, 9.02132),
                     Point(221.7423, -70.83169, 9.02132),
                     Point(221.7423, -70.83169, 14.0),
                     Point(221.7423, -73.91502, 14.0),
                     Point(221.7423, -73.91502, 9.02132),
                     Point(221.7423, -80.83169, 9.02132),
                     Point(221.7423, -80.83169, 14.0),
                     Point(221.7423, -84.20669, 14.0),
                     holes=Polygons(
                         Polygon(Point(221.7423, -80.68064, 8.969236),
                                 Point(221.7423, -74.06606, 8.969236),
                                 Point(221.7423, -74.06606, 9.02132),
                                 Point(221.7423, -80.68064, 9.02132)),
                         Polygon(Point(221.7423, -70.68064, 8.969236),
                                 Point(221.7423, -64.06606, 8.969236),
                                 Point(221.7423, -64.06606, 9.02132),
                                 Point(221.7423, -70.68064, 9.02132)),
                         Polygon(Point(221.7423, -60.68064, 8.969236),
                                 Point(221.7423, -54.06606, 8.969236),
                                 Point(221.7423, -54.06606, 14.0),
                                 Point(221.7423, -54.0921, 14.0),
                                 Point(221.7423, -54.0921, 9.02132),
                                 Point(221.7423, -60.6546, 9.02132),
                                 Point(221.7423, -60.6546, 14.0),
                                 Point(221.7423, -60.68064, 14.0))))
        return
        pg.plot(set_lims=True)
        pg.triangles.plot(set_lims=True)
        print(pg.triangles)
        return
        return
        pg.polylines[0].plot()
        pg.holes[0].polylines.plot()
        pg.holes[1].polylines.plot()
        pg.holes[2].polylines.plot()

        print(pg.holes[0].reverse.area)
        print(pg.holes[1].area)
        print(pg.holes[2].area)

        print(pg.holes[0].intersection(pg.exterior)[0].area)
        print(pg.holes[1].intersection(pg.exterior)[0].area)
        print(pg.holes[2].intersection(pg.exterior)[0].area)

        return

        #return

        pg = Polygon(Point(220.7528, -63.91502, 9.02132),
                     Point(221.7423, -63.91502, 9.02132),
                     Point(221.7423, -63.91502, 14.0),
                     Point(220.7528, -63.91502, 14.0))
        #print(pg.triangles); return

        pg = Polygon(Point(221.7423, -84.20669, 6.0),
                     Point(221.7423, -53.63377, 6.0),
                     Point(221.7423, -53.63377, 14.0),
                     Point(221.7423, -54.0921, 14.0),
                     Point(221.7423, -54.0921, 9.02132),
                     Point(221.7423, -60.6546, 9.02132),
                     Point(221.7423, -60.6546, 14.0),
                     Point(221.7423, -63.91502, 14.0),
                     Point(221.7423, -63.91502, 9.02132),
                     Point(221.7423, -70.83169, 9.02132),
                     Point(221.7423, -70.83169, 14.0),
                     Point(221.7423, -73.91502, 14.0),
                     Point(221.7423, -73.91502, 9.02132),
                     Point(221.7423, -80.83169, 9.02132),
                     Point(221.7423, -80.83169, 14.0),
                     Point(221.7423, -84.20669, 14.0),
                     holes=Polygons(
                         Polygon(Point(221.7423, -80.68064, 8.969236),
                                 Point(221.7423, -74.06606, 8.969236),
                                 Point(221.7423, -74.06606, 9.02132),
                                 Point(221.7423, -80.68064, 9.02132)),
                         Polygon(Point(221.7423, -70.68064, 8.969236),
                                 Point(221.7423, -64.06606, 8.969236),
                                 Point(221.7423, -64.06606, 9.02132),
                                 Point(221.7423, -70.68064, 9.02132)),
                         Polygon(Point(221.7423, -60.68064, 8.969236),
                                 Point(221.7423, -54.06606, 8.969236),
                                 Point(221.7423, -54.06606, 14.0),
                                 Point(221.7423, -54.0921, 14.0),
                                 Point(221.7423, -54.0921, 9.02132),
                                 Point(221.7423, -60.6546, 9.02132),
                                 Point(221.7423, -60.6546, 14.0),
                                 Point(221.7423, -60.68064, 14.0))))
        print(pg.triangles)
        return
Esempio n. 16
0
    def test_difference_polygon_2d(self):
        ""
        # 2D
        pg = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
        # no intersection
        pg1 = Polygon(Point(0, 2), Point(1, 2), Point(1, 3), Point(0, 3))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0)), ))
        # point intersection
        pg1 = Polygon(Point(1, 1), Point(2, 1), Point(2, 2), Point(1, 2))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(1, 1), Point(1, 0), Point(0, 0), Point(0, 1)), ))
        # full edge intersection
        pg1 = Polygon(Point(0, 1), Point(1, 1), Point(1, 2), Point(0, 2))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(1, 1), Point(1, 0), Point(0, 0), Point(0, 1)), ))
        # half edge overlap intersection
        pg1 = Polygon(Point(0.5, 1), Point(1.5, 1), Point(1.5, 2),
                      Point(0.5, 2))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(1, 1), Point(1, 0), Point(0, 0), Point(0, 1),
                        Point(0.5, 1)), ))
        # partial internal edge intersection
        pg1 = Polygon(Point(0.25, 1), Point(0.75, 1), Point(0.75, 2),
                      Point(0.25, 2))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0.75, 1), Point(1, 1), Point(1, 0), Point(0, 0),
                        Point(0, 1), Point(0.25, 1)), ))
        # full intersection
        pg1 = pg
        #print(pg.difference(pg1)); return
        self.assertEqual(pg.difference(pg1), GeometryObjects())
        # half intersection
        pg1 = Polygon(Point(0.5, 0), Point(1.5, 0), Point(1.5, 1),
                      Point(0.5, 1))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0.5, 0), Point(0, 0), Point(0, 1), Point(0.5,
                                                                       1)), ))
        # quarter intersection
        pg1 = Polygon(Point(0.5, 0.5), Point(1.5, 0.5), Point(1.5, 1.5),
                      Point(0.5, 1.5))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(1.0, 0.5), Point(1.0, 0.0), Point(0.0, 0.0),
                        Point(0.0, 1.0), Point(0.5, 1.0), Point(0.5, 0.5)), ))
        # internal intersection, 2 edges
        pg1 = Polygon(Point(0.25, 0), Point(0.75, 0), Point(0.75, 1),
                      Point(0.25, 1))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0.25, 0), Point(0, 0), Point(0, 1),
                        Point(0.25, 1)),
                Polygon(Point(0.75, 1), Point(1, 1), Point(1, 0),
                        Point(0.75, 0))))
        # internal intersection, 1 edges
        pg1 = Polygon(Point(0.25, 0), Point(0.75, 0), Point(0.75, 0.5),
                      Point(0.25, 0.5))
        #print(pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0.25, 0.0), Point(0.0, 0.0), Point(0.0, 1.0),
                        Point(1.0, 1.0), Point(1.0, 0.0), Point(0.75, 0.0),
                        Point(0.75, 0.5), Point(0.25, 0.5)), ))

        #
        pg = Polygon(Point(1.0, 0.25), Point(1.0, 1.0), Point(0.0, 1.0),
                     Point(0.0, 0.25))
        pg1 = Polygon(Point(0.25, 0.25), Point(0.75, 0.25), Point(0.75, 0.75),
                      Point(0.25, 0.75))
        #print('---return---\n',pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0.25, 0.25), Point(0.0, 0.25), Point(0.0, 1.0),
                        Point(1.0, 1.0), Point(1.0, 0.25), Point(0.75, 0.25),
                        Point(0.75, 0.75), Point(0.25, 0.75)), ))

        # internal intersection, no edges
        pg = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
        pg1 = Polygon(Point(0.25, 0.25), Point(0.75, 0.25), Point(0.75, 0.75),
                      Point(0.25, 0.75))
        #print('---return---\n',pg.difference(pg1)); return
        self.assertEqual(
            pg.difference(pg1),
            GeometryObjects(
                Polygon(Point(0.0, 0.0),
                        Point(0.0, 1.0),
                        Point(1.0, 1.0),
                        Point(1.0, 0.0),
                        holes=Polygons(
                            Polygon(Point(0.25, 0.25), Point(0.75, 0.25),
                                    Point(0.75, 0.75), Point(0.25, 0.75)))), ))

        # external intersection, no edges
        pg1 = Polygon(Point(-1, -1), Point(2, -1), Point(2, 2), Point(-1, 2))
        #print(pg.difference(pg1)); return
        self.assertEqual(pg.difference(pg1), GeometryObjects())