pcod-common v1.0.0
Shared preprocessing and postprocessing for point-cloud object detection
Loading...
Searching...
No Matches
test_bounding_box.cpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
5
6#include <cassert>
7#include <cmath>
8
9namespace {
10
19pcod_common::BoundingBox MakeBox(float x, float y, float length, float width, float yaw) {
21 box.center = {x, y};
22 box.length = length;
23 box.width = width;
24 box.yaw = yaw;
25 return box;
26}
27
28} // namespace
29
31int main() {
32 const pcod_common::BoundingBox base = MakeBox(0.0f, 0.0f, 4.0f, 2.0f, 0.0f);
33
34 {
35 const pcod_common::BoundingBox same = MakeBox(0.0f, 0.0f, 4.0f, 2.0f, 0.0f);
36 const float area_a = base.intersection_area(same);
37 const float area_b = same.intersection_area(base);
38 assert(std::abs(area_a - area_b) < 1e-6f);
39 assert(std::abs(area_a - (base.length * base.width)) < 1e-6f);
40 assert(base.overlaps(same, 0.99f));
41 }
42
43 {
44 const pcod_common::BoundingBox far = MakeBox(100.0f, 100.0f, 4.0f, 2.0f, 0.0f);
45 assert(base.intersection_area(far) == 0.0f);
46 assert(!base.overlaps(far, 0.0f));
47 }
48
49 {
50 const pcod_common::BoundingBox shifted = MakeBox(1.0f, 0.0f, 4.0f, 2.0f, 0.0f);
51 const float area_forward = base.intersection_area(shifted);
52 const float area_reverse = shifted.intersection_area(base);
53 assert(area_forward > 0.0f);
54 assert(std::abs(area_forward - area_reverse) < 1e-6f);
55 }
56
57 {
58 const pcod_common::BoundingBox rotated = MakeBox(0.0f, 0.0f, 4.0f, 2.0f, 1.57079632679f);
59 const float area = base.intersection_area(rotated);
60 assert(area > 0.0f);
61 assert(area < base.length * base.width);
62 }
63
64 return 0;
65}
float length
Length along the local X axis.
float intersection_area(const BoundingBox &other) const
std::array< float, 2 > center
XY center in metres.
float width
Width along the local Y axis.
bool overlaps(const BoundingBox &other, float iou_threshold) const
float yaw
Heading in radians.
int main()