示例#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))
示例#2
0
  def testGetClosestPointShape(self):
    poly = Poly()

    poly.AddPoint(Point(1, 1, 0).Normalize())
    self.assertPointApproxEq(Point(
        0.707106781187, 0.707106781187, 0), poly.GetPoint(0))

    point = Point(0, 1, 1).Normalize()
    self.assertPointApproxEq(Point(1, 1, 0).Normalize(),
                                    poly.GetClosestPoint(point)[0])

    poly.AddPoint(Point(0, 1, 1).Normalize())

    self.assertPointApproxEq(
        Point(0, 1, 1).Normalize(),
        poly.GetClosestPoint(point)[0])
示例#3
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)
示例#4
0
    def testMergePolys(self):
        poly1 = Poly(name="Foo")
        poly1.AddPoint(Point(0, 1, 0).Normalize())
        poly1.AddPoint(Point(0, 0.5, 0.5).Normalize())
        poly1.AddPoint(Point(0, 0, 1).Normalize())
        poly1.AddPoint(Point(1, 1, 1).Normalize())

        poly2 = Poly()
        poly3 = Poly(name="Bar")
        poly3.AddPoint(Point(1, 1, 1).Normalize())
        poly3.AddPoint(Point(2, 0.5, 0.5).Normalize())

        merged1 = Poly.MergePolys([poly1, poly2])
        self.assertPointsApproxEq(poly1.GetPoints(), merged1.GetPoints())
        self.assertEqual("Foo;", merged1.GetName())

        merged2 = Poly.MergePolys([poly2, poly3])
        self.assertPointsApproxEq(poly3.GetPoints(), merged2.GetPoints())
        self.assertEqual(";Bar", merged2.GetName())

        merged3 = Poly.MergePolys([poly1, poly2, poly3],
                                  merge_point_threshold=0)
        mergedPoints = poly1.GetPoints()[:]
        mergedPoints.append(poly3.GetPoint(-1))
        self.assertPointsApproxEq(mergedPoints, merged3.GetPoints())
        self.assertEqual("Foo;;Bar", merged3.GetName())

        merged4 = Poly.MergePolys([poly2])
        self.assertEqual("", merged4.GetName())
        self.assertEqual(0, merged4.GetNumPoints())

        # test merging two nearby points
        newPoint = poly1.GetPoint(-1).Plus(Point(0.000001, 0, 0)).Normalize()
        poly1.AddPoint(newPoint)
        distance = poly1.GetPoint(-1).GetDistanceMeters(poly3.GetPoint(0))
        self.assertTrue(distance <= 10)
        self.assertTrue(distance > 5)

        merged5 = Poly.MergePolys([poly1, poly2, poly3],
                                  merge_point_threshold=10)
        mergedPoints = poly1.GetPoints()[:]
        mergedPoints.append(poly3.GetPoint(-1))
        self.assertPointsApproxEq(mergedPoints, merged5.GetPoints())
        self.assertEqual("Foo;;Bar", merged5.GetName())

        merged6 = Poly.MergePolys([poly1, poly2, poly3],
                                  merge_point_threshold=5)
        mergedPoints = poly1.GetPoints()[:]
        mergedPoints += poly3.GetPoints()
        self.assertPointsApproxEq(mergedPoints, merged6.GetPoints())
        self.assertEqual("Foo;;Bar", merged6.GetName())