def test_a():
    rectangle_a = np.array([
        [518.54893549, 2660.18852229],
        [516.6680813, 2659.68467469],
        [516.90002051, 2658.81884971],
        [518.7808747, 2659.32269731],
    ])

    rectangle_b = np.array([
        [518.53730179, 2660.30353692],
        [516.60027552, 2659.72004892],
        [516.91754532, 2658.66679687],
        [518.85457159, 2659.25028488],
    ])

    v0 = VectorReference(rectangle_a[0][0], rectangle_a[0][1])
    v1 = VectorReference(rectangle_a[1][0], rectangle_a[1][1])
    v2 = VectorReference(rectangle_a[2][0], rectangle_a[2][1])

    l1 = LineReference(v0, v1)
    l1a = Line([rectangle_a[0][0], rectangle_a[0][1]],
               [rectangle_a[1][0], rectangle_a[1][1]])

    l3 = LineReference(v1, v2)
    l3a = Line([rectangle_a[1][0], rectangle_a[1][1]],
               [rectangle_a[2][0], rectangle_a[2][1]])

    assert l1.a == l1a.a
    assert l1.b == l1a.b
    assert l1.c == l1a.c

    assert l1(v2) == l1a([rectangle_a[2][0], rectangle_a[2][1]])

    assert math.isclose(l1.intersection(l3).x, v1.x, abs_tol=1e-6)
    assert math.isclose(l1.intersection(l3).y, v1.y, abs_tol=1e-6)

    assert math.isclose(l1a.intersection(l3a)[0],
                        rectangle_a[1][0],
                        abs_tol=1e-6)
    assert math.isclose(l1a.intersection(l3a)[1],
                        rectangle_a[1][1],
                        abs_tol=1e-6)

    assert math.isclose(
        intersection_rectangles(rectangle_a, rectangle_b),
        Polygon(rectangle_a).intersection(Polygon(rectangle_b)).area,
        abs_tol=1e-6,
    )
    assert math.isclose(
        intersection_rectangles(rectangle_b, rectangle_a),
        Polygon(rectangle_a).intersection(Polygon(rectangle_b)).area,
        abs_tol=1e-6,
    )
def test_vs_shapely_pi_by_4(length_a, width_a, center_ax, center_ay, length_b,
                            width_b, center_bx, center_by):
    rectangle_a = to_coords((center_ax, center_ay), length_a, width_a, 0)
    rectangle_b = to_coords((center_bx, center_by), length_b, width_b,
                            math.pi / 4)

    rectangle_a_shapely = Polygon(rectangle_a + [rectangle_a[0]])
    rectangle_b_shapely = Polygon(rectangle_b + [rectangle_b[0]])

    assert math.isclose(
        rectangle_a_shapely.intersection(rectangle_b_shapely).area,
        intersection_rectangles(rectangle_a, rectangle_b))

    rectangle_a_shapely = Polygon(rectangle_a + [rectangle_a[0]])
    rectangle_b_shapely = Polygon(rectangle_b + [rectangle_b[0]])

    assert math.isclose(
        rectangle_a_shapely.intersection(rectangle_b_shapely).area,
        intersection_rectangles(rectangle_a, rectangle_b))
def test_vs_shapely_angle(length_a, width_a, center_ax, center_ay, length_b,
                          width_b, center_bx, center_by, angle_x, angle_y):
    rectangle_a = to_coords((center_ax, center_ay), length_a, width_a, angle_x)
    rectangle_b = to_coords((center_bx, center_by), length_b, width_b, angle_y)

    rectangle_a_shapely = Polygon(rectangle_a + [rectangle_a[0]])
    rectangle_b_shapely = Polygon(rectangle_b + [rectangle_b[0]])

    assert math.isclose(
        rectangle_a_shapely.intersection(rectangle_b_shapely).area,
        intersection_rectangles(rectangle_a, rectangle_b),
        abs_tol=1e-4,
    )
def test_simple():
    rectangle_a = np.array([
        [518.54893549, 2660.18852229],
        [516.6680813, 2659.68467469],
        [516.90002051, 2658.81884971],
        [518.7808747, 2659.32269731],
    ])

    rectangle_b = np.array([
        [518.53730179, 2660.30353692],
        [516.60027552, 2659.72004892],
        [516.91754532, 2658.66679687],
        [518.85457159, 2659.25028488],
    ])

    assert intersection_rectangles(rectangle_a,
                                   rectangle_b) == 1.745352555764839
Exemple #5
0
    def get_area_intersection(self, other: "Box3D") -> float:
        self_rectangle = self.get_ground_bbox_coords()
        other_rectangle = other.get_ground_bbox_coords()

        return intersection_rectangles(self_rectangle, other_rectangle)