Exemplo n.º 1
0
    def test_3d_box_constraints(self):
        # Simple case
        ta, tb, intersect = box_intersections([1, 1, 0], [0, 0, 1],
                                              [1, 1, 1], [3, 3, 3])
        assert_array_almost_equal([ta, tb], [1, 1])
        assert_equal(intersect, True)

        # Negative direction
        ta, tb, intersect = box_intersections([1, 1, 0], [0, 0, -1],
                                              [1, 1, 1], [3, 3, 3])
        assert_equal(intersect, False)

        # Interior Point
        ta, tb, intersect = box_intersections([2, 2, 2], [0, -1, 1],
                                              [1, 1, 1], [3, 3, 3])
        assert_array_almost_equal([ta, tb], [0, 1])
        assert_equal(intersect, True)
Exemplo n.º 2
0
    def test_3d_box_constraints(self):
        # Simple case
        ta, tb, intersect = box_intersections([1, 1, 0], [0, 0, 1],
                                              [1, 1, 1], [3, 3, 3])
        assert_array_almost_equal([ta, tb], [1, 1])
        assert_equal(intersect, True)

        # Negative direction
        ta, tb, intersect = box_intersections([1, 1, 0], [0, 0, -1],
                                              [1, 1, 1], [3, 3, 3])
        assert_equal(intersect, False)

        # Interior Point
        ta, tb, intersect = box_intersections([2, 2, 2], [0, -1, 1],
                                              [1, 1, 1], [3, 3, 3])
        assert_array_almost_equal([ta, tb], [0, 1])
        assert_equal(intersect, True)
Exemplo n.º 3
0
    def test_2d_box_constraints_entire_line(self):
        # Box constraint in the direction of vector d
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [0.5, 1.5])
        assert_equal(intersect, True)

        # Negative direction
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [1, -3], [3, -1],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [-1.5, -0.5])
        assert_equal(intersect, True)

        # Some constraints are absent (set to +/- inf)
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-np.inf, 1],
                                              [np.inf, np.inf],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [0.5, np.inf])
        assert_equal(intersect, True)

        # Intersect on the face of the box
        ta, tb, intersect = box_intersections([1, 0], [0, 1],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [1, 3])
        assert_equal(intersect, True)

        # Interior inicial pointoint
        ta, tb, intersect = box_intersections([0, 0], [4, 4],
                                              [-2, -3], [3, 2],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [-0.5, 0.5])
        assert_equal(intersect, True)

        # No intersection between line and box constraints
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-3, -3], [-1, -1],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-3, 3], [-1, 1],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-3, -np.inf],
                                              [-1, np.inf],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([0, 0], [1, 100],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([0.99, 0], [0, 2],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_equal(intersect, False)

        # Inicial point on the boundary
        ta, tb, intersect = box_intersections([2, 2], [0, 1],
                                              [-2, -2], [2, 2],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [-4, 0])
        assert_equal(intersect, True)
Exemplo n.º 4
0
    def test_2d_box_constraints_entire_line(self):
        # Box constraint in the direction of vector d
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [0.5, 1.5])
        assert_equal(intersect, True)

        # Negative direction
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [1, -3], [3, -1],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [-1.5, -0.5])
        assert_equal(intersect, True)

        # Some constraints are absent (set to +/- inf)
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-np.inf, 1],
                                              [np.inf, np.inf],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [0.5, np.inf])
        assert_equal(intersect, True)

        # Intersect on the face of the box
        ta, tb, intersect = box_intersections([1, 0], [0, 1],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [1, 3])
        assert_equal(intersect, True)

        # Interior inicial pointoint
        ta, tb, intersect = box_intersections([0, 0], [4, 4],
                                              [-2, -3], [3, 2],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [-0.5, 0.5])
        assert_equal(intersect, True)

        # No intersection between line and box constraints
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-3, -3], [-1, -1],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-3, 3], [-1, 1],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([2, 0], [0, 2],
                                              [-3, -np.inf],
                                              [-1, np.inf],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([0, 0], [1, 100],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_intersections([0.99, 0], [0, 2],
                                              [1, 1], [3, 3],
                                              entire_line=True)
        assert_equal(intersect, False)

        # Inicial point on the boundary
        ta, tb, intersect = box_intersections([2, 2], [0, 1],
                                              [-2, -2], [2, 2],
                                              entire_line=True)
        assert_array_almost_equal([ta, tb], [-4, 0])
        assert_equal(intersect, True)