Ejemplo n.º 1
0
    def testGetClosestPointShape(self):
        poly = Poly()

        poly.add_point(Point(1, 1, 0).normalize())
        self.assertPointApproxEq(Point(0.707106781187, 0.707106781187, 0),
                                 poly.get_point(0))

        point = Point(0, 1, 1).normalize()
        self.assertPointApproxEq(
            Point(1, 1, 0).normalize(),
            poly.get_closest_point(point)[0])

        poly.add_point(Point(0, 1, 1).normalize())

        self.assertPointApproxEq(
            Point(0, 1, 1).normalize(),
            poly.get_closest_point(point)[0])
Ejemplo n.º 2
0
    def testPolyMatch(self):
        poly = Poly()
        poly.add_point(Point(0, 1, 0).normalize())
        poly.add_point(Point(0, 0.5, 0.5).normalize())
        poly.add_point(Point(0, 0, 1).normalize())

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

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

        poly = Poly()
        poly.add_point(Point.from_lat_lng(45.585212, -122.586136))
        poly.add_point(Point.from_lat_lng(45.586654, -122.587595))
        collection = PolyCollection()
        collection.add_poly(poly)

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

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

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

        match = collection.find_matching_polys(
            Point.from_lat_lng(45.587212, -122.586136),
            Point.from_lat_lng(45.586654, -122.587595))
        self.assert_(len(match) == 0)
Ejemplo n.º 3
0
    def testMergePolys(self):
        poly1 = Poly(name="Foo")
        poly1.add_point(Point(0, 1, 0).normalize())
        poly1.add_point(Point(0, 0.5, 0.5).normalize())
        poly1.add_point(Point(0, 0, 1).normalize())
        poly1.add_point(Point(1, 1, 1).normalize())

        poly2 = Poly()
        poly3 = Poly(name="Bar")
        poly3.add_point(Point(1, 1, 1).normalize())
        poly3.add_point(Point(2, 0.5, 0.5).normalize())

        merged1 = Poly.merge_polys([poly1, poly2])
        self.assertPointsApproxEq(poly1.get_points(), merged1.get_points())
        self.assertEqual("Foo;", merged1.get_name())

        merged2 = Poly.merge_polys([poly2, poly3])
        self.assertPointsApproxEq(poly3.get_points(), merged2.get_points())
        self.assertEqual(";Bar", merged2.get_name())

        merged3 = Poly.merge_polys([poly1, poly2, poly3],
                                   merge_point_threshold=0)
        mergedPoints = poly1.get_points()[:]
        mergedPoints.append(poly3.get_point(-1))
        self.assertPointsApproxEq(mergedPoints, merged3.get_points())
        self.assertEqual("Foo;;Bar", merged3.get_name())

        merged4 = Poly.merge_polys([poly2])
        self.assertEqual("", merged4.get_name())
        self.assertEqual(0, merged4.get_num_points())

        # test merging two nearby points
        newPoint = poly1.get_point(-1).plus(Point(0.000001, 0, 0)).normalize()
        poly1.add_point(newPoint)
        distance = poly1.get_point(-1).get_distance_meters(poly3.get_point(0))
        self.assertTrue(distance <= 10)
        self.assertTrue(distance > 5)

        merged5 = Poly.merge_polys([poly1, poly2, poly3],
                                   merge_point_threshold=10)
        mergedPoints = poly1.get_points()[:]
        mergedPoints.append(poly3.get_point(-1))
        self.assertPointsApproxEq(mergedPoints, merged5.get_points())
        self.assertEqual("Foo;;Bar", merged5.get_name())

        merged6 = Poly.merge_polys([poly1, poly2, poly3],
                                   merge_point_threshold=5)
        mergedPoints = poly1.get_points()[:]
        mergedPoints += poly3.get_points()
        self.assertPointsApproxEq(mergedPoints, merged6.get_points())
        self.assertEqual("Foo;;Bar", merged6.get_name())
Ejemplo n.º 4
0
    def testCutAtClosestPoint(self):
        poly = Poly()
        poly.add_point(Point(0, 1, 0).normalize())
        poly.add_point(Point(0, 0.5, 0.5).normalize())
        poly.add_point(Point(0, 0, 1).normalize())

        (before, after) = \
            poly.cut_at_closest_point(Point(0, 0.3, 0.7).normalize())

        self.assert_(2 == before.get_num_points())
        self.assert_(2 == before.get_num_points())
        self.assertPointApproxEq(Point(0, 0.707106781187, 0.707106781187),
                                 before.get_point(1))

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

        poly = Poly()
        poly.add_point(
            Point.from_lat_lng(40.527035999999995, -74.191265999999999))
        poly.add_point(
            Point.from_lat_lng(40.526859999999999, -74.191140000000004))
        poly.add_point(
            Point.from_lat_lng(40.524681000000001, -74.189579999999992))
        poly.add_point(
            Point.from_lat_lng(40.523128999999997, -74.188467000000003))
        poly.add_point(
            Point.from_lat_lng(40.523054999999999, -74.188676000000001))
        pattern = Poly()
        pattern.add_point(Point.from_lat_lng(40.52713, -74.191146000000003))
        self.assertApproxEq(14.564268281551,
                            pattern.greedy_poly_match_dist(poly))