| 1 |
#include "stk_middle_mesh/predicates/element_xi_classifier.hpp" |
| 2 |
#include "gtest/gtest.h" |
| 3 |
|
| 4 |
namespace stk { |
| 5 |
namespace middle_mesh { |
| 6 |
namespace impl { |
| 7 |
|
| 8 |
namespace { |
| 9 |
using namespace predicates::impl; |
| 10 |
using namespace utils; |
| 11 |
|
| 12 |
void test_record(const predicates::impl::PointRecordForTriangle& r, PointClassification type, int id) |
| 13 |
{ |
| 14 |
EXPECT_EQ(r.type, type); |
| 15 |
EXPECT_EQ(r.id, id); |
| 16 |
} |
| 17 |
|
| 18 |
} // namespace |
| 19 |
|
| 20 |
TEST(ElementXiClassifier, TriangleVerts) |
| 21 |
{ |
| 22 |
double eps = 0.1; // make this large so testing is easier |
| 23 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 24 |
|
| 25 |
test_record(classifier.classify_triangle(Point(0, 0)), PointClassification::Vert, 0); |
| 26 |
test_record(classifier.classify_triangle(Point(eps / 2, 0)), PointClassification::Vert, 0); |
| 27 |
test_record(classifier.classify_triangle(Point(0, eps / 2)), PointClassification::Vert, 0); |
| 28 |
|
| 29 |
test_record(classifier.classify_triangle(Point(1, 0)), PointClassification::Vert, 1); |
| 30 |
test_record(classifier.classify_triangle(Point(1 - eps / 2, 0)), PointClassification::Vert, 1); |
| 31 |
test_record(classifier.classify_triangle(Point(1, eps / 2)), PointClassification::Vert, 1); |
| 32 |
|
| 33 |
test_record(classifier.classify_triangle(Point(0, 1)), PointClassification::Vert, 2); |
| 34 |
test_record(classifier.classify_triangle(Point(eps / 2, 1)), PointClassification::Vert, 2); |
| 35 |
test_record(classifier.classify_triangle(Point(0, 1 + eps / 2)), PointClassification::Vert, 2); |
| 36 |
} |
| 37 |
|
| 38 |
TEST(ElementXiClassifier, TriangleEdges) |
| 39 |
{ |
| 40 |
double eps = 0.1; // make this large so testing is easier |
| 41 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 42 |
|
| 43 |
test_record(classifier.classify_triangle(Point(0.5, 0)), PointClassification::Edge, 0); |
| 44 |
test_record(classifier.classify_triangle(Point(0.5, eps / 2)), PointClassification::Edge, 0); |
| 45 |
test_record(classifier.classify_triangle(Point(2 * eps, 0)), PointClassification::Edge, 0); |
| 46 |
test_record(classifier.classify_triangle(Point(1 - 2 * eps, 0)), PointClassification::Edge, 0); |
| 47 |
|
| 48 |
Point offset = 2 * eps * Point(-1, 1) / std::sqrt(2); |
| 49 |
test_record(classifier.classify_triangle(Point(0.5, 0.5)), PointClassification::Edge, 1); |
| 50 |
test_record(classifier.classify_triangle(Point(0.5, 0.5) + offset), PointClassification::Edge, 1); |
| 51 |
test_record(classifier.classify_triangle(Point(1, 0) + offset), PointClassification::Edge, 1); |
| 52 |
test_record(classifier.classify_triangle(Point(0, 1) - offset), PointClassification::Edge, 1); |
| 53 |
} |
| 54 |
|
| 55 |
TEST(ElementXiClassifier, TriangleInterior) |
| 56 |
{ |
| 57 |
double eps = 0.1; // make this large so testing is easier |
| 58 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 59 |
|
| 60 |
test_record(classifier.classify_triangle(Point(2 * eps, 2 * eps)), PointClassification::Interior, 0); |
| 61 |
test_record(classifier.classify_triangle(Point(1 - 4 * eps, 2 * eps)), PointClassification::Interior, 0); |
| 62 |
test_record(classifier.classify_triangle(Point(2 * eps, 1 - 4 * eps)), PointClassification::Interior, 0); |
| 63 |
|
| 64 |
test_record(classifier.classify_triangle(Point(0.5, 2 * eps)), PointClassification::Interior, 0); |
| 65 |
test_record(classifier.classify_triangle(Point(0.5, 0.5 - 2 * eps)), PointClassification::Interior, 0); |
| 66 |
test_record(classifier.classify_triangle(Point(0.5 - 2 * eps, 0.5)), PointClassification::Interior, 0); |
| 67 |
test_record(classifier.classify_triangle(Point(0 + 2 * eps, 0.5)), PointClassification::Interior, 0); |
| 68 |
} |
| 69 |
|
| 70 |
TEST(ElementXiClassifier, TriangleExterior) |
| 71 |
{ |
| 72 |
double eps = 0.1; // make this large so testing is easier |
| 73 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 74 |
|
| 75 |
test_record(classifier.classify_triangle(Point(-2 * eps, -2 * eps)), PointClassification::Exterior, -1); |
| 76 |
test_record(classifier.classify_triangle(Point(1 + 4 * eps, -2 * eps)), PointClassification::Exterior, -1); |
| 77 |
test_record(classifier.classify_triangle(Point(-2 * eps, 1 + 4 * eps)), PointClassification::Exterior, -1); |
| 78 |
|
| 79 |
test_record(classifier.classify_triangle(Point(0.5, -2 * eps)), PointClassification::Exterior, -1); |
| 80 |
test_record(classifier.classify_triangle(Point(0.5, 0.5 + 2 * eps)), PointClassification::Exterior, -1); |
| 81 |
test_record(classifier.classify_triangle(Point(0.5 + 2 * eps, 0.5)), PointClassification::Exterior, -1); |
| 82 |
test_record(classifier.classify_triangle(Point(0 - 2 * eps, 0.5)), PointClassification::Exterior, -1); |
| 83 |
} |
| 84 |
|
| 85 |
TEST(ElementXiClassifier, QuadVerts) |
| 86 |
{ |
| 87 |
double eps = 0.1; // make this large so testing is easier |
| 88 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 89 |
|
| 90 |
test_record(classifier.classify_quad(Point(0, 0)), PointClassification::Vert, 0); |
| 91 |
test_record(classifier.classify_quad(Point(eps / 2, 0)), PointClassification::Vert, 0); |
| 92 |
test_record(classifier.classify_quad(Point(-eps / 2, 0)), PointClassification::Vert, 0); |
| 93 |
test_record(classifier.classify_quad(Point(0, eps / 2)), PointClassification::Vert, 0); |
| 94 |
test_record(classifier.classify_quad(Point(0, -eps / 2)), PointClassification::Vert, 0); |
| 95 |
|
| 96 |
test_record(classifier.classify_quad(Point(1, 0)), PointClassification::Vert, 1); |
| 97 |
test_record(classifier.classify_quad(Point(1 - eps / 2, 0)), PointClassification::Vert, 1); |
| 98 |
test_record(classifier.classify_quad(Point(1 + eps / 2, 0)), PointClassification::Vert, 1); |
| 99 |
test_record(classifier.classify_quad(Point(1, eps / 2)), PointClassification::Vert, 1); |
| 100 |
test_record(classifier.classify_quad(Point(1, -eps / 2)), PointClassification::Vert, 1); |
| 101 |
|
| 102 |
test_record(classifier.classify_quad(Point(1, 1)), PointClassification::Vert, 2); |
| 103 |
test_record(classifier.classify_quad(Point(1 - eps / 2, 1)), PointClassification::Vert, 2); |
| 104 |
test_record(classifier.classify_quad(Point(1 + eps / 2, 1)), PointClassification::Vert, 2); |
| 105 |
test_record(classifier.classify_quad(Point(1, 1 - eps / 2)), PointClassification::Vert, 2); |
| 106 |
test_record(classifier.classify_quad(Point(1, 1 + eps / 2)), PointClassification::Vert, 2); |
| 107 |
|
| 108 |
test_record(classifier.classify_quad(Point(0, 1)), PointClassification::Vert, 3); |
| 109 |
test_record(classifier.classify_quad(Point(0 - eps / 2, 1)), PointClassification::Vert, 3); |
| 110 |
test_record(classifier.classify_quad(Point(0 + eps / 2, 1)), PointClassification::Vert, 3); |
| 111 |
test_record(classifier.classify_quad(Point(0, 1 - eps / 2)), PointClassification::Vert, 3); |
| 112 |
test_record(classifier.classify_quad(Point(0, 1 + eps / 2)), PointClassification::Vert, 3); |
| 113 |
} |
| 114 |
|
| 115 |
TEST(ElementXiClassifier, QuadEdges) |
| 116 |
{ |
| 117 |
double eps = 0.1; // make this large so testing is easier |
| 118 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 119 |
|
| 120 |
test_record(classifier.classify_quad(Point(0.5, 0)), PointClassification::Edge, 0); |
| 121 |
test_record(classifier.classify_quad(Point(0.5, eps / 2)), PointClassification::Edge, 0); |
| 122 |
test_record(classifier.classify_quad(Point(0.5, -eps / 2)), PointClassification::Edge, 0); |
| 123 |
test_record(classifier.classify_quad(Point(0 + 2 * eps, 0)), PointClassification::Edge, 0); |
| 124 |
test_record(classifier.classify_quad(Point(1 - 2 * eps, 0)), PointClassification::Edge, 0); |
| 125 |
|
| 126 |
test_record(classifier.classify_quad(Point(1, 0.5)), PointClassification::Edge, 1); |
| 127 |
test_record(classifier.classify_quad(Point(1 + eps / 2, 0.5)), PointClassification::Edge, 1); |
| 128 |
test_record(classifier.classify_quad(Point(1 - eps / 2, 0.5)), PointClassification::Edge, 1); |
| 129 |
test_record(classifier.classify_quad(Point(1, 2 * eps)), PointClassification::Edge, 1); |
| 130 |
test_record(classifier.classify_quad(Point(1, 1 - 2 * eps)), PointClassification::Edge, 1); |
| 131 |
|
| 132 |
test_record(classifier.classify_quad(Point(0.5, 1)), PointClassification::Edge, 2); |
| 133 |
test_record(classifier.classify_quad(Point(0.5, 1 + eps / 2)), PointClassification::Edge, 2); |
| 134 |
test_record(classifier.classify_quad(Point(0.5, 1 - eps / 2)), PointClassification::Edge, 2); |
| 135 |
test_record(classifier.classify_quad(Point(0 + 2 * eps, 1)), PointClassification::Edge, 2); |
| 136 |
test_record(classifier.classify_quad(Point(1 - 2 * eps, 1)), PointClassification::Edge, 2); |
| 137 |
|
| 138 |
test_record(classifier.classify_quad(Point(0, 0.5)), PointClassification::Edge, 3); |
| 139 |
test_record(classifier.classify_quad(Point(0 + eps / 2, 0.5)), PointClassification::Edge, 3); |
| 140 |
test_record(classifier.classify_quad(Point(0 - eps / 2, 0.5)), PointClassification::Edge, 3); |
| 141 |
test_record(classifier.classify_quad(Point(0, 2 * eps)), PointClassification::Edge, 3); |
| 142 |
test_record(classifier.classify_quad(Point(0, 1 - 2 * eps)), PointClassification::Edge, 3); |
| 143 |
} |
| 144 |
|
| 145 |
TEST(ElementXiClassifier, QuadInterior) |
| 146 |
{ |
| 147 |
double eps = 0.1; // make this large so testing is easier |
| 148 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 149 |
|
| 150 |
test_record(classifier.classify_quad(Point(2 * eps, 2 * eps)), PointClassification::Interior, 0); |
| 151 |
test_record(classifier.classify_quad(Point(1 - 2 * eps, 2 * eps)), PointClassification::Interior, 0); |
| 152 |
test_record(classifier.classify_quad(Point(1 - 2 * eps, 1 - 2 * eps)), PointClassification::Interior, 0); |
| 153 |
test_record(classifier.classify_quad(Point(2 * eps, 1 - 2 * eps)), PointClassification::Interior, 0); |
| 154 |
|
| 155 |
test_record(classifier.classify_quad(Point(0.5, 2 * eps)), PointClassification::Interior, 0); |
| 156 |
test_record(classifier.classify_quad(Point(1 - 2 * eps, 0.5)), PointClassification::Interior, 0); |
| 157 |
test_record(classifier.classify_quad(Point(0.5, 1 - 2 * eps)), PointClassification::Interior, 0); |
| 158 |
test_record(classifier.classify_quad(Point(2 * eps, 0.5)), PointClassification::Interior, 0); |
| 159 |
} |
| 160 |
|
| 161 |
TEST(ElementXiClassifier, QuadExterior) |
| 162 |
{ |
| 163 |
double eps = 0.1; // make this large so testing is easier |
| 164 |
predicates::impl::ElementXiClassifier classifier(eps); |
| 165 |
|
| 166 |
test_record(classifier.classify_quad(Point(-2 * eps, -2 * eps)), PointClassification::Exterior, -1); |
| 167 |
test_record(classifier.classify_quad(Point(1 + 2 * eps, -2 * eps)), PointClassification::Exterior, -1); |
| 168 |
test_record(classifier.classify_quad(Point(1 + 2 * eps, 1 + 2 * eps)), PointClassification::Exterior, -1); |
| 169 |
test_record(classifier.classify_quad(Point(-2 * eps, 1 + 2 * eps)), PointClassification::Exterior, -1); |
| 170 |
|
| 171 |
test_record(classifier.classify_quad(Point(0.5, -2 * eps)), PointClassification::Exterior, -1); |
| 172 |
test_record(classifier.classify_quad(Point(1 + 2 * eps, 0.5)), PointClassification::Exterior, -1); |
| 173 |
test_record(classifier.classify_quad(Point(0.5, 1 + 2 * eps)), PointClassification::Exterior, -1); |
| 174 |
test_record(classifier.classify_quad(Point(-2 * eps, 0.5)), PointClassification::Exterior, -1); |
| 175 |
} |
| 176 |
} // namespace impl |
| 177 |
} // namespace middle_mesh |
| 178 |
} // namespace stk |