forked from tuxalin/THST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredicates.h
109 lines (90 loc) · 3.51 KB
/
predicates.h
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
//
// predicates.h
//
//
#pragma once
#include "bbox.h"
namespace spatial {
namespace detail {
struct intersects_tag;
struct contains_tag;
struct within_tag;
template <typename T, int Dimension, typename OperationTag>
struct CheckPredicateHelper;
template <typename T, int Dimension>
struct CheckPredicateHelper<T, Dimension, intersects_tag> {
typedef spatial::BoundingBox<T, Dimension> box_t;
inline bool operator()(const box_t &predicateBBox,
const box_t &valueBBox) const {
return predicateBBox.overlaps(valueBBox);
}
};
template <typename T, int Dimension>
struct CheckPredicateHelper<T, Dimension, contains_tag> {
typedef spatial::BoundingBox<T, Dimension> box_t;
inline bool operator()(const box_t &predicateBBox,
const box_t &valueBBox) const {
return predicateBBox.contains(valueBBox);
}
};
template <typename T, int Dimension>
struct CheckPredicateHelper<T, Dimension, within_tag> {
typedef spatial::BoundingBox<T, Dimension> box_t;
inline bool operator()(const box_t &predicateBBox,
const box_t &valueBBox) const {
return predicateBBox.contains(valueBBox.min);
}
};
template <typename T, int Dimension, typename OperationTag>
bool checkPredicate(const spatial::BoundingBox<T, Dimension> &predicateBBox,
const spatial::BoundingBox<T, Dimension> &valueBBox) {
return CheckPredicateHelper<T, Dimension, OperationTag>()(predicateBBox,
valueBBox);
}
};
template <typename T, int Dimension, typename OperationTag>
struct SpatialPredicate {
typedef spatial::BoundingBox<T, Dimension> box_t;
typedef OperationTag op_t;
SpatialPredicate(const box_t &bbox) : bbox(bbox) {}
inline bool operator()(const box_t &valueBBox) const {
return detail::checkPredicate<T, Dimension, OperationTag>(bbox, valueBBox);
}
box_t bbox;
};
template <int Dimension, typename T>
SpatialPredicate<T, Dimension, detail::intersects_tag>
intersects(const spatial::BoundingBox<T, Dimension> &bbox) {
return SpatialPredicate<T, Dimension, detail::intersects_tag>(bbox);
}
template <int Dimension, typename T>
SpatialPredicate<T, Dimension, detail::intersects_tag>
intersects(const T min[Dimension], const T max[Dimension]) {
typedef SpatialPredicate<T, Dimension, detail::intersects_tag> predicate_t;
return predicate_t(typename predicate_t::box_t(min, max));
}
template <int Dimension, typename T>
SpatialPredicate<T, Dimension, detail::contains_tag>
contains(const spatial::BoundingBox<T, Dimension> &bbox) {
return SpatialPredicate<T, Dimension, detail::contains_tag>(bbox);
}
template <int Dimension, typename T>
SpatialPredicate<T, Dimension, detail::contains_tag>
contains(const T min[Dimension], const T max[Dimension]) {
typedef SpatialPredicate<T, Dimension, detail::contains_tag> predicate_t;
return predicate_t(typename predicate_t::box_t(min, max));
}
///@note To be used with points, as it only check the min point of the
/// bounding boxes of the leaves.
template <int Dimension, typename T>
SpatialPredicate<T, Dimension, detail::within_tag>
within(const spatial::BoundingBox<T, Dimension> &bbox) {
return SpatialPredicate<T, Dimension, detail::within_tag>(bbox);
}
template <int Dimension, typename T>
SpatialPredicate<T, Dimension, detail::within_tag>
within(const T min[Dimension], const T max[Dimension]) {
typedef SpatialPredicate<T, Dimension, detail::within_tag> predicate_t;
return predicate_t(typename predicate_t::box_t(min, max));
}
} // namespace spatial