Skip to content

Commit

Permalink
Fixed geom tests (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-Olegovich authored Jun 2, 2024
1 parent 9c9d70d commit fae4b95
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
2 changes: 2 additions & 0 deletions packages/geom/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ ament_add_gtest(
angle_tests.cpp
angle_vector_tests.cpp
arc_tests.cpp
bounding_box_tests.cpp
distance_tests.cpp
line_tests.cpp
main.cpp
polygon_tests.cpp
ray_tests.cpp
segment_tests.cpp
uniform_stepper_tests.cpp
vector_tests.cpp
vector3_tests.cpp
)
Expand Down
41 changes: 9 additions & 32 deletions packages/geom/test/bounding_box_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST(BoundingBox, constructor) {
ASSERT_GEOM_EQUAL(bb3.max.y, 24., eps);
}

TEST(Vector3, extend) {
TEST(BoundingBox, extend) {
// Arrange.
auto bb1 = BoundingBox({1, 3});
auto bb2 = BoundingBox({1, 3});
Expand Down Expand Up @@ -69,36 +69,13 @@ TEST(Vector3, extend) {
ASSERT_GEOM_EQUAL(bb2.max.x, 7., eps);
ASSERT_GEOM_EQUAL(bb2.max.y, 4., eps);

ASSERT_GEOM_EQUAL(bb3.min.x, 3., eps);
ASSERT_GEOM_EQUAL(bb3.min.y, -5., eps);
ASSERT_GEOM_EQUAL(bb3.max.x, 10., eps);
ASSERT_GEOM_EQUAL(bb3.max.y, 2., eps);
ASSERT_GEOM_EQUAL(bb3.min.x, -5., eps);
ASSERT_GEOM_EQUAL(bb3.min.y, 2., eps);
ASSERT_GEOM_EQUAL(bb3.max.x, 3., eps);
ASSERT_GEOM_EQUAL(bb3.max.y, 10., eps);

ASSERT_GEOM_EQUAL(bb4.min.x, 3., eps);
ASSERT_GEOM_EQUAL(bb4.min.y, -5., eps);
ASSERT_GEOM_EQUAL(bb4.max.x, 10., eps);
ASSERT_GEOM_EQUAL(bb4.max.y, 2., eps);
}

TEST(BoundingBox, makeBoundingBox) {
// Arrange.
const auto p1 = Polygon{{0, 0}, {0, 1}, {1, 0}};
const auto p2 = Polygon{{-1, -7}, {-2, 8}, {14, 6}, {5, -1}};

// Act.
const auto bb1 = makeBoundingBox(p1);
const auto bb2 = makeBoundingBox(p2);

// Assert.
constexpr double eps = 1e-9;

ASSERT_GEOM_EQUAL(bb1.min.x, 0., eps);
ASSERT_GEOM_EQUAL(bb1.min.y, 0., eps);
ASSERT_GEOM_EQUAL(bb1.max.x, 1., eps);
ASSERT_GEOM_EQUAL(bb1.max.y, 1., eps);

ASSERT_GEOM_EQUAL(bb2.min.x, -2., eps);
ASSERT_GEOM_EQUAL(bb2.min.y, -7., eps);
ASSERT_GEOM_EQUAL(bb2.max.x, 14., eps);
ASSERT_GEOM_EQUAL(bb2.max.y, 5., eps);
ASSERT_GEOM_EQUAL(bb4.min.x, -5., eps);
ASSERT_GEOM_EQUAL(bb4.min.y, 2., eps);
ASSERT_GEOM_EQUAL(bb4.max.x, 3., eps);
ASSERT_GEOM_EQUAL(bb4.max.y, 10., eps);
}
23 changes: 23 additions & 0 deletions packages/geom/test/polygon_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,26 @@ TEST(Polygon, intersect) {
ASSERT_EQ(intersect(poly, seg), true);
}
}

TEST(Polygon, makeBoundingBox) {
// Arrange.
const auto p1 = Polygon{{0, 0}, {0, 1}, {1, 0}};
const auto p2 = Polygon{{-1, -7}, {-2, 8}, {14, 6}, {5, -1}};

// Act.
const auto bb1 = makeBoundingBox(p1);
const auto bb2 = makeBoundingBox(p2);

// Assert.
constexpr double eps = 1e-9;

ASSERT_GEOM_EQUAL(bb1.min.x, 0., eps);
ASSERT_GEOM_EQUAL(bb1.min.y, 0., eps);
ASSERT_GEOM_EQUAL(bb1.max.x, 1., eps);
ASSERT_GEOM_EQUAL(bb1.max.y, 1., eps);

ASSERT_GEOM_EQUAL(bb2.min.x, -2., eps);
ASSERT_GEOM_EQUAL(bb2.min.y, -7., eps);
ASSERT_GEOM_EQUAL(bb2.max.x, 14., eps);
ASSERT_GEOM_EQUAL(bb2.max.y, 8., eps);
}
1 change: 1 addition & 0 deletions packages/geom/test/uniform_stepper_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>

#include "geom/test/equal_assert.h"
#include "geom/polygon.h"
#include "geom/polyline.h"
#include "geom/uniform_stepper.h"

Expand Down

0 comments on commit fae4b95

Please sign in to comment.