Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_plane_projection.cpp

raw
1 #include "gtest/gtest.h"
2
3 #include "stk_middle_mesh/plane_projection.hpp"
4
5 namespace stk {
6 namespace middle_mesh {
7 namespace impl {
8
9 namespace {
10
11 void expect_float_eq2(const utils::Point& pt, const utils::Point& pt2)
12 {
13 EXPECT_FLOAT_EQ(pt.x, pt2.x);
14 EXPECT_FLOAT_EQ(pt.y, pt2.y);
15 }
16
17 void expect_float_eq3(const utils::Point& pt, const utils::Point& pt2)
18 {
19 EXPECT_FLOAT_EQ(pt.x, pt2.x);
20 EXPECT_FLOAT_EQ(pt.y, pt2.y);
21 EXPECT_FLOAT_EQ(pt.z, pt2.z);
22 }
23
24 void test_projection(utils::impl::PlaneProjection val, const utils::Point& pt)
25 {
26 auto pts = utils::impl::get_plane_projection_points(val);
27 utils::impl::Projection* proj = utils::impl::get_plane_projection(pts);
28
29 auto pt2 = proj->compute_plane_coords(pt);
30 auto pt3 = utils::impl::apply_plane_projection(val, pt);
31
32 expect_float_eq2(pt2, pt3);
33
34 // test inverse function
35 auto pt4 = utils::impl::apply_inverse_plane_projection(val, pt3);
36 expect_float_eq3(pt, pt4);
37
38 delete proj;
39 }
40
41 } // namespace
42
43 TEST(PlaneProjection, apply_plane_projection)
44 {
45 utils::Point pt(1, 2, 3);
46
47 // test equivalence between using Projection and applyutils::impl::PlaneProjection
48 test_projection(utils::impl::PlaneProjection::YzPos, pt);
49 test_projection(utils::impl::PlaneProjection::YzNeg, pt);
50 test_projection(utils::impl::PlaneProjection::XzPos, pt);
51 test_projection(utils::impl::PlaneProjection::XzNeg, pt);
52 test_projection(utils::impl::PlaneProjection::XyPos, pt);
53 test_projection(utils::impl::PlaneProjection::XyNeg, pt);
54 }
55
56 TEST(PlaneProjection, getPlaneProjectionEnum)
57 {
58 utils::Point pt1(-0.7513110251673053, -0.8136577495531562, 0);
59 utils::Point pt2(-0.2847545178640647, -1.081679676310688, 0);
60 utils::Point pt3(-0.2688256750539578, -1.003439971294373, 0);
61
62 EXPECT_EQ(utils::impl::get_plane_projection_enum(pt1, pt2, pt3), utils::impl::PlaneProjection::XyPos);
63 }
64
65 } // namespace impl
66 } // namespace middle_mesh
67 } // namespace stk