Beispiel #1
0
    def test_asymmetric_curves(self):
        c1 = PolygonalCurve2D([
            Point2D(-5.0, 1.0),
            Point2D(-4.0, 4.0),
            Point2D(-2.0, -1.0)
        ])

        c2 = PolygonalCurve2D([
            Point2D(-6.0, 0.0),
            Point2D(-3.0, -2.0),
            Point2D(-2.0, 1.0)
        ])

        self.perform_test(c1, c2, 6.08)
Beispiel #2
0
    def test_query_square_curve(self):
        tree = CurveRangeTree2D(
            PolygonalCurve2D([
                Point2D(0.0, 0.0),
                Point2D(5.0, 0.0),
                Point2D(5.0, 5.0),
                Point2D(1.0, 5.0),
                Point2D(1.0, 1.0),
                Point2D(4.0, 1.0),
                Point2D(4.0, 4.0),
                Point2D(2.0, 4.0),
                Point2D(2.0, 2.0),
                Point2D(3.0, 2.0),
                Point2D(3.0, 3.0)
            ]), self.error, self.delta)

        # Create query parameters
        x = Point2D(2.5, 0.0)
        x_edge = Edge2D(Point2D(0.0, 0.0), Point2D(5.0, 0.0))
        y = Point2D(3.0, 2.5)
        y_edge = Edge2D(Point2D(3.0, 2.0), Point2D(3.0, 3.0))

        # Query various edges against this tree
        q_edge = Edge2D(Point2D(2.5, -2.0), Point2D(5.5, -0.5))
        assert tree.is_approximate(q_edge, x, y, x_edge, y_edge)

        q_edge = Edge2D(Point2D(-1.1, 5.0), Point2D(-1.1, 1))
        assert not tree.is_approximate(q_edge, x, y, x_edge, y_edge)

        q_edge = Edge2D(Point2D(1.0, 2.5), Point2D(5.0, 2.5))
        assert not tree.is_approximate(q_edge, x, y, x_edge, y_edge)

        q_edge = Edge2D(Point2D(0.0, 0.0), Point2D(5.0, 5.0))
        assert not tree.is_approximate(q_edge, x, y, x_edge, y_edge)
Beispiel #3
0
    def test_symmetric_curves(self):
        c1 = PolygonalCurve2D([
            Point2D(0.0, 1.0),
            Point2D(3.0, 2.0),
            Point2D(5.0, 2.0),
            Point2D(7.0, 1.0)
        ])

        c2 = PolygonalCurve2D([
            Point2D(0.0, 0.0),
            Point2D(3.0, 1.0),
            Point2D(5.0, 1.0),
            Point2D(7.0, 0.0)
        ])

        self.perform_test(c1, c2, 1.0)
        def create_curve(s):
            s.insert(0, s[0].parent)

            if embedded_nodes:
                curve = PolygonalCurve2D([n.point for n in s])
                curves.append(curve)

                # Fix a pointer to the curve for each node in the stack
                for n in s:
                    n.decomp_curves.append(curve)
            else:
                curves.append(s)

            for n in s:
                n.gpar = s[0]
Beispiel #5
0
    def test_query_trivial_curve(self):
        tree = CurveRangeTree2D(
            PolygonalCurve2D(
                [Point2D(0.0, 0.0),
                 Point2D(3.0, 0.0),
                 Point2D(3.0, 3.0)]), self.error, self.delta)

        # Create query parameters
        q_edge = Edge2D(Point2D(0.0, -1.0), Point2D(3.0, -1.0))
        x = Point2D(0.25, 0.0)
        x_edge = Edge2D(Point2D(0.0, 0.0), Point2D(3.0, 0.0))
        y = Point2D(3.0, 2.5)
        y_edge = Edge2D(Point2D(3.0, 0.0), Point2D(3.0, 3.0))

        assert tree.is_approximate(q_edge, x, y, x_edge, y_edge)
    def test_curve(self):
        curve = PolygonalCurve2D(
            [Point2D(-5.0, 1.0),
             Point2D(-4.0, 4.0),
             Point2D(-2.0, -1.0)])
        e = Edge2D(Point2D(-20.0, -22.0), Point2D(5.0, 5.0))
        grid = FrechetGrid2D(curve, self.error)

        real = discrete_frechet(e.get_steiner_curve(STEINER_SPACING),
                                curve.get_steiner_curve(STEINER_SPACING))
        estimate = grid.approximate_frechet(e)

        # Test for (1 + epsilon) property of grid estimate
        assert estimate <= real or \
            real <= (1 + self.error) * estimate
Beispiel #7
0
    def __find_decomposed_curves(start, end):
        paths = list()

        searching = True
        stack = list()
        prev = None
        curr = start
        while searching:
            if curr == end:
                searching = False

            stack.append(curr)

            if prev and prev.gpar == curr:
                paths.append(PolygonalCurve2D([n.point for n in stack]))
                stack = [curr]

            prev = curr
            curr = curr.parent

        return paths
Beispiel #8
0
    def test_small_float_values(self):
        tree = CurveRangeTree2D(
            PolygonalCurve2D([
                Point2D(0.0, 0.0),
                Point2D(1.0, 0.0),
                Point2D(0.0, -0.01),
                Point2D(1.0, -0.01),
                Point2D(0.0, -0.02),
                Point2D(1.0, -0.02)
            ]), self.error, 0.55)

        # Create query parameters
        q_edge = Edge2D(Point2D(0.0, 0.0), Point2D(1.0, -0.02))
        x = Point2D(0.0, 0.0)
        x_edge = Edge2D(Point2D(0.0, 0.0), Point2D(1.0, 0.0))
        y = Point2D(1.0, -0.02)
        y_edge = Edge2D(Point2D(0.0, -0.02), Point2D(1.0, -0.02))

        assert tree.is_approximate(q_edge, x, y, x_edge, y_edge)

        q_edge = Edge2D(Point2D(2.2, 0.0), Point2D(2.2, -0.02))
        assert not tree.is_approximate(q_edge, x, y, x_edge, y_edge)