47TEST(OrientedBoundingBoxTest, WriteMeshBox3D)
50 const Real
tol = 1e-8;
53 const Real s = 1.0 / std::sqrt(2.0);
54 const Point origin(10.0, 20.0, 30.0);
55 const Point d0(s, s, 0.0), d1(-s, s, 0.0), d2(0.0, 0.0, 1.0);
56 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
58 const std::vector<std::pair<Point, Point>> axis_pairs{
59 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
62 const std::string file =
"oriented_bounding_box_test_3d.e";
65 ReplicatedMesh
mesh(comm);
68 EXPECT_EQ(
mesh.n_nodes(), 8u);
69 EXPECT_EQ(
mesh.n_elem(), 1u);
70 for (
const auto * elem :
mesh.active_element_ptr_range())
71 EXPECT_EQ(elem->type(), HEX8);
73 const std::vector<Point> nodes = nodeLocations(
mesh);
74 for (
unsigned int mask = 0; mask < 8u; ++mask)
76 Point corner = origin;
83 EXPECT_TRUE(containsPoint(nodes, corner,
tol)) <<
"missing corner, mask=" << mask;
86 std::remove(file.c_str());
90TEST(OrientedBoundingBoxTest, WriteMeshBox2D)
93 const Real
tol = 1e-8;
95 const Real s = 1.0 / std::sqrt(2.0);
96 const Point origin(5.0, 6.0, 0.0);
97 const Point d0(s, s, 0.0), d1(-s, s, 0.0);
98 const Real l0 = 2.0, l1 = 3.0;
100 const std::vector<std::pair<Point, Point>> axis_pairs{{origin, origin + l0 * d0},
101 {origin, origin + l1 * d1}};
104 const std::string file =
"oriented_bounding_box_test_2d.e";
107 ReplicatedMesh
mesh(comm);
110 EXPECT_EQ(
mesh.n_nodes(), 4u);
111 EXPECT_EQ(
mesh.n_elem(), 1u);
112 for (
const auto * elem :
mesh.active_element_ptr_range())
113 EXPECT_EQ(elem->type(), QUAD4);
115 const std::vector<Point> nodes = nodeLocations(
mesh);
116 for (
unsigned int mask = 0; mask < 4u; ++mask)
118 Point corner = origin;
123 EXPECT_TRUE(containsPoint(nodes, corner,
tol)) <<
"missing corner, mask=" << mask;
126 std::remove(file.c_str());
130TEST(OrientedBoundingBoxTest, WriteRay)
133 const Real
tol = 1e-8;
135 const Real s = 1.0 / std::sqrt(2.0);
136 const Point origin(0.0, 0.0, 0.0);
137 const Point d0(s, s, 0.0), d1(-s, s, 0.0), d2(0.0, 0.0, 1.0);
138 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
140 const std::vector<std::pair<Point, Point>> axis_pairs{
141 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
144 const std::string file =
"oriented_bounding_box_test_ray.e";
147 ReplicatedMesh
mesh(comm);
150 EXPECT_EQ(
mesh.n_nodes(), 2u);
151 EXPECT_EQ(
mesh.n_elem(), 1u);
152 for (
const auto * elem :
mesh.active_element_ptr_range())
153 EXPECT_EQ(elem->type(), EDGE2);
156 const Point start = origin + 0.5 * l0 * d0 + 0.5 * l1 * d1;
157 const Point end = start + l2 * d2;
159 const std::vector<Point> nodes = nodeLocations(
mesh);
160 EXPECT_TRUE(containsPoint(nodes, start,
tol));
161 EXPECT_TRUE(containsPoint(nodes, end,
tol));
163 std::remove(file.c_str());
168TEST(OrientedBoundingBoxTest, QueryApiAxisAligned)
170 const Point origin(0.0, 0.0, 0.0);
171 const Point d0(1.0, 0.0, 0.0), d1(0.0, 1.0, 0.0), d2(0.0, 0.0, 1.0);
172 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
173 const std::vector<std::pair<Point, Point>> axis_pairs{
174 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
178 EXPECT_NEAR((obb.
getMaximalCorner() - Point(2.0, 3.0, 1.0)).norm(), 0.0, 1e-12);
179 EXPECT_NEAR((obb.
centroid() - Point(1.0, 1.5, 0.5)).norm(), 0.0, 1e-12);
188 EXPECT_TRUE(obb.
contains(Point(1.0, 1.5, 0.5)));
190 EXPECT_TRUE(obb.
contains(Point(2.0, 3.0, 1.0)));
191 EXPECT_FALSE(obb.
contains(Point(2.5, 1.5, 0.5)));
192 EXPECT_FALSE(obb.
contains(Point(1.0, -0.1, 0.5)));
201TEST(OrientedBoundingBoxTest, QueryApiRotated)
203 const Real s = 1.0 / std::sqrt(2.0);
204 const Point origin(1.0, 2.0, 3.0);
205 const Point d0(s, s, 0.0), d1(-s, s, 0.0), d2(0.0, 0.0, 1.0);
206 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
207 const std::vector<std::pair<Point, Point>> axis_pairs{
208 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
215 const Point inside = origin + 1.5 * d0 + 2.0 * d1 + 0.5 * d2;
221 const Point outside = origin + 2.5 * d0 + 1.0 * d1 + 0.5 * d2;
223 EXPECT_FALSE(obb.
contains(outside));