Ejemplo n.º 1
0
    def testCutAtClosestPoint(self):
        poly = Poly()
        poly.AddPoint(Point(0, 1, 0).Normalize())
        poly.AddPoint(Point(0, 0.5, 0.5).Normalize())
        poly.AddPoint(Point(0, 0, 1).Normalize())

        (before,
         after) = poly.CutAtClosestPoint(Point(0, 0.3, 0.7).Normalize())

        self.assert_(2 == before.GetNumPoints())
        self.assert_(2 == before.GetNumPoints())
        self.assertPointApproxEq(Point(0, 0.707106781187, 0.707106781187),
                                 before.GetPoint(1))

        self.assertPointApproxEq(Point(0, 0.393919298579, 0.919145030018),
                                 after.GetPoint(0))

        poly = Poly()
        poly.AddPoint(Point.FromLatLng(40.527035999999995,
                                       -74.191265999999999))
        poly.AddPoint(Point.FromLatLng(40.526859999999999,
                                       -74.191140000000004))
        poly.AddPoint(Point.FromLatLng(40.524681000000001,
                                       -74.189579999999992))
        poly.AddPoint(Point.FromLatLng(40.523128999999997,
                                       -74.188467000000003))
        poly.AddPoint(Point.FromLatLng(40.523054999999999,
                                       -74.188676000000001))
        pattern = Poly()
        pattern.AddPoint(Point.FromLatLng(40.52713, -74.191146000000003))
        self.assertApproxEq(14.564268281551, pattern.GreedyPolyMatchDist(poly))
Ejemplo n.º 2
0
    def testPolyMatch(self):
        poly = Poly()
        poly.AddPoint(Point(0, 1, 0).Normalize())
        poly.AddPoint(Point(0, 0.5, 0.5).Normalize())
        poly.AddPoint(Point(0, 0, 1).Normalize())

        collection = PolyCollection()
        collection.AddPoly(poly)
        match = collection.FindMatchingPolys(Point(0, 1, 0), Point(0, 0, 1))
        self.assert_(len(match) == 1 and match[0] == poly)

        match = collection.FindMatchingPolys(Point(0, 1, 0), Point(0, 1, 0))
        self.assert_(len(match) == 0)

        poly = Poly()
        poly.AddPoint(Point.FromLatLng(45.585212, -122.586136))
        poly.AddPoint(Point.FromLatLng(45.586654, -122.587595))
        collection = PolyCollection()
        collection.AddPoly(poly)

        match = collection.FindMatchingPolys(
            Point.FromLatLng(45.585212, -122.586136),
            Point.FromLatLng(45.586654, -122.587595),
        )
        self.assert_(len(match) == 1 and match[0] == poly)

        match = collection.FindMatchingPolys(
            Point.FromLatLng(45.585219, -122.586136),
            Point.FromLatLng(45.586654, -122.587595),
        )
        self.assert_(len(match) == 1 and match[0] == poly)

        self.assertApproxEq(0.0, poly.GreedyPolyMatchDist(poly))

        match = collection.FindMatchingPolys(
            Point.FromLatLng(45.587212, -122.586136),
            Point.FromLatLng(45.586654, -122.587595),
        )
        self.assert_(len(match) == 0)