-
Notifications
You must be signed in to change notification settings - Fork 0
/
PermutationAabbIndexTest.cpp
134 lines (101 loc) · 4.21 KB
/
PermutationAabbIndexTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "gtest/gtest.h"
#include "PermutationAabbIndex.hpp"
#include "TestsForAllIndexes.hpp"
namespace geoIndex {
static const int expectedIndexSize = 5; // Anything would do. We don't care about performance here.
TEST(PermutationAabbIndex, pointsWithinDistance_samePoint) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_samePoint(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_coincidentPoints) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_coincidentPoints(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_noPoints) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_noPoints(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_onlyFarPoints) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_onlyFarPoints(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_inAndOutPoints) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_inAndOutPoints(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_exactDistance) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_exactDistance(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_outputOrder) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_outputOrder(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_squareDistance) {
PermutationAabbIndex<Point> index;
pointsWithinDistance_squareDistance(index);
}
#ifdef GEO_INDEX_SAFETY_CHECKS
TEST(PermutationAabbIndex, index_duplicatedIndex) {
PermutationAabbIndex<Point> index(expectedIndexSize);
index_duplicatedIndex(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_negativeDistance) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_negativeDistance(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_zeroDistance) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_zeroDistance(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_NanDistance) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_NanDistance(index);
}
TEST(PermutationAabbIndex, pointsWithinDistance_overflowDistance) {
PermutationAabbIndex<Point> index(expectedIndexSize);
pointsWithinDistance_overflowDistance(index);
}
#endif
/* Specific tests for this algorithm only. */
TEST(PermutationAabbIndex, pointsWithinDistance_aabbBoundaries) {
const double approxSqrtOf2 = 1.414;
const Point inCorner{approxSqrtOf2, approxSqrtOf2, 1.414};
const Point centerOfTopFace{0, 0, 1};
const Point origin{0, 0, 0};
const double searchDistance = 1.01; // The search is strictly inside the distance, need to go "a bit farther" to find centerOfTopFace.
PermutationAabbIndex<Point> gi;
gi.index(inCorner, 1);
gi.index(centerOfTopFace, 2);
gi.completed();
std::vector<IndexAndSquaredDistance<Point>> result;
gi.pointsWithinDistance(origin, searchDistance, result);
ASSERT_EQ(1, result.size());
ASSERT_INDEX_PRESENT(result, 2);
}
#ifdef GEO_INDEX_SAFETY_CHECKS
TEST(PermutationAabbIndex, pointsWithinDistance_incorrectOrderOfUsage_lookupOfNothing) {
const Point anyPoint{1, 55, 2};
PermutationAabbIndex<Point> gi;
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_NO_THROW(gi.pointsWithinDistance(anyPoint, 0.01, result));
}
TEST(PermutationAabbIndex, pointsWithinDistance_incorrectOrderOfUsage_lookupWithoutPreparation) {
const Point anyPoint{1, 55, 2};
PermutationAabbIndex<Point> gi;
gi.index(anyPoint, 1);
// No call to completed();
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_ANY_THROW(gi.pointsWithinDistance(anyPoint, 0.01, result));
}
TEST(PermutationAabbIndex, pointsWithinDistance_incorrectOrderOfUsage_addPointsAfterCompletition) {
const Point anyPoint{1, 55, 2};
PermutationAabbIndex<Point> gi;
gi.index(anyPoint, 1);
gi.completed();
gi.index(anyPoint, 2);
std::vector<IndexAndSquaredDistance<Point>> result;
ASSERT_ANY_THROW(gi.pointsWithinDistance(anyPoint, 0.01, result));
}
#endif
}