34 #include <boost/container/static_vector.hpp> 43 #ifndef DOXYGEN_SHOULD_SKIP_THIS 66 template<
typename U, std::
size_t N>
96 template<
typename T,
typename U =
float, std::
size_t Size = 16>
98 static_assert(Size > 0,
"Size can not be 0");
119 Node *node = m_root.chooseNode(bounds);
121 if (node ==
nullptr) {
125 return node->insert(std::move(value), bounds);
137 return m_root.query(bounds, callback, kind);
149 std::vector<SpatialStructure<U, 2>> structures;
150 m_root.appendToStructure(structures, 0);
163 : m_children(
nullptr)
165 m_entries.reserve(Size);
170 , m_children(
nullptr)
172 m_entries.reserve(Size);
175 bool isLeaf()
const {
176 return m_children ==
nullptr;
180 if (!m_bounds.contains(bounds)) {
185 if (m_entries.size() < Size) {
192 if (m_entries.size() < Size) {
197 for (std::size_t i = 0; i < 4; ++i) {
198 if (m_children[i].chooseNode(bounds) !=
nullptr) {
199 return &m_children[i];
203 clearChildrenIfEmpty();
208 bool insert(
T&& value,
const Box<U, 2>& bounds) {
209 m_entries.push_back({ std::move(value), bounds });
214 if (!m_bounds.intersects(bounds)) {
218 std::size_t found = 0;
220 for (
auto& entry : m_entries) {
223 if (bounds.
contains(entry.bounds)) {
224 callback(entry.value);
231 callback(entry.value);
239 for (std::size_t i = 0; i < 4; ++i) {
240 found += m_children[i].query(bounds, callback, kind);
251 m_children =
nullptr;
257 for (
auto& entry : m_entries) {
262 for (std::size_t i = 0; i < 4; ++i) {
263 m_children[i].appendToStructure(structures, level + 1);
270 m_children = std::make_unique<Node[]>(4);
277 std::vector<Entry> entries;
279 for (
auto& entry : m_entries) {
280 bool inserted =
false;
282 for (std::size_t i = 0; i < 4; ++i) {
283 if (m_children[i].m_bounds.contains(entry.bounds)) {
284 m_children[i].m_entries.push_back(std::move(entry));
291 entries.push_back(std::move(entry));
295 std::swap(m_entries, entries);
298 void clearChildrenIfEmpty() {
301 for (std::size_t i = 0; i < 4; ++i) {
302 if (!m_children[i].m_entries.empty()) {
307 m_children =
nullptr;
312 std::vector<Entry> m_entries;
313 std::unique_ptr<Node[]> m_children;
329 template<
typename T,
typename U =
float, std::
size_t N = 2, std::
size_t MaxSize = 16, std::
size_t MinSize = 4>
331 static_assert(
N > 0,
"N can not be 0");
332 static_assert(2 <= MinSize,
"MinSize must be at least 2");
333 static_assert(MinSize <= MaxSize / 2,
"MinSize must be less than MaxSize/2");
359 m_root = std::exchange(other.m_root,
nullptr);
366 std::swap(m_root, other.m_root);
385 Leaf *leaf = m_root->chooseSubtree(bounds);
387 Node *splitted = leaf->tryInsert(std::move(value), bounds);
388 Node *current = leaf;
390 while (splitted !=
nullptr) {
391 auto splittedBounds = splitted->computeBounds();
392 splitted->updateOriginalBounds(splittedBounds);
394 auto currentBounds = current->computeBounds();
395 current->updateOriginalBounds(currentBounds);
397 if (current == m_root) {
398 auto branch =
new Branch;
400 current->setParent(branch);
401 branch->tryInsert(current, currentBounds);
403 splitted->setParent(branch);
404 branch->tryInsert(splitted, splittedBounds);
406 branch->updateOriginalBounds(branch->computeBounds());
412 Branch *parent = current->getParent();
413 assert(parent !=
nullptr);
415 parent->updateBoundsForChild(currentBounds, current);
417 splitted->setParent(parent);
418 splitted = parent->tryInsert(splitted, splittedBounds);
424 while (current != m_root) {
425 auto currentBounds = current->computeBounds();
427 Branch *parent = current->getParent();
428 assert(parent !=
nullptr);
430 parent->updateBoundsForChild(currentBounds, current);
447 return m_root->query(bounds, callback, kind);
459 std::vector<SpatialStructure<U, N>> structures;
460 m_root->appendToStructure(structures, 0);
465 static constexpr std::size_t Size = MaxSize + 1;
497 Branch *getParent() noexcept {
501 void setParent(Branch *parent) {
505 bool hasOriginalBounds()
const {
506 return !m_orig.isEmpty();
509 U getOriginalCenterAxisValue(std::size_t axis)
const {
510 return (m_orig.min[axis] + m_orig.max[axis]) / 2;
513 void updateOriginalBounds(
Box<U, N> orig) {
517 virtual ~
Node() =
default;
519 virtual Leaf *chooseSubtree(
const Box<U, N>& bounds) = 0;
521 virtual Box<U, N> computeBounds()
const = 0;
534 struct LeafEntry : Entry {
538 class Leaf :
public Node {
541 std::size_t found = 0;
545 for (
auto& entry : m_entries) {
546 if (bounds.
contains(entry.bounds)) {
547 callback(entry.value);
554 for (
auto& entry : m_entries) {
556 callback(entry.value);
567 virtual Leaf *chooseSubtree(
const Box<U, N>& bounds)
override {
572 virtual Box<U,N> computeBounds()
const override {
573 assert(!m_entries.empty());
576 for (
auto& entry : m_entries) {
577 res.extend(entry.bounds);
583 virtual void appendToStructure(std::vector<
SpatialStructure<U, N>>& structures,
int level)
const override {
584 for (
auto& entry : m_entries) {
589 Leaf *tryInsert(
T&& value,
const Box<U, N>& bounds) {
591 entry.bounds = bounds;
592 entry.value = std::move(value);
593 m_entries.push_back(std::move(entry));
595 if (m_entries.size() < Size) {
599 std::vector<Box<U, N>> boxes;
601 std::transform(m_entries.begin(), m_entries.end(), std::back_inserter(boxes), [](
const Entry& entry) {
605 SplitResult split = computeSplit(boxes);
607 switch (split.order) {
608 case SplitOrder::Min:
609 std::sort(m_entries.begin(), m_entries.end(), EntryMinAxisComparator<LeafEntry>(split.axis));
611 case SplitOrder::Max:
612 std::sort(m_entries.begin(), m_entries.end(), EntryMaxAxisComparator<LeafEntry>(split.axis));
616 auto leaf =
new Leaf;
618 auto splitIteratorBegin = std::next(m_entries.begin(), split.index + 1);
619 auto splitIteratorEnd = m_entries.end();
621 std::move(splitIteratorBegin, splitIteratorEnd, std::back_inserter(leaf->m_entries));
622 m_entries.erase(splitIteratorBegin, splitIteratorEnd);
628 SplitResult computeSplit(std::vector<
Box<U, N>>& boxes) {
630 std::tie(split.axis, split.order) = computeSplitAxis(boxes);
632 switch (split.order) {
633 case SplitOrder::Min:
634 std::sort(boxes.begin(), boxes.end(), MinAxisComparator(split.axis));
636 case SplitOrder::Max:
637 std::sort(boxes.begin(), boxes.end(), MaxAxisComparator(split.axis));
641 split.index = computeSplitIndex(boxes, split.axis);
645 std::tuple<std::size_t, SplitOrder> computeSplitAxis(std::vector<
Box<U, N>>& boxes) {
646 std::size_t currentAxis = 0;
647 U currentValue = std::numeric_limits<U>::max();
648 SplitOrder currentOrder = SplitOrder::Min;
650 for (std::size_t axis = 0; axis <
N; ++axis) {
651 std::sort(boxes.begin(), boxes.end(), MinAxisComparator(axis));
653 U value = computeAxisValue(boxes);
655 if (value < currentValue) {
657 currentValue = value;
658 currentOrder = SplitOrder::Min;
661 std::sort(boxes.begin(), boxes.end(), MaxAxisComparator(axis));
663 value = computeAxisValue(boxes);
665 if (value < currentValue) {
667 currentValue = value;
668 currentOrder = SplitOrder::Max;
672 return std::make_tuple(currentAxis, currentOrder);
675 U computeAxisValue(
const std::vector<
Box<U, N>>& boxes) {
676 std::vector<Box<U, N>> firstBounds;
678 std::partial_sum(boxes.begin(), boxes.end(), std::back_inserter(firstBounds), [](
const Box<U, N>& lhs,
const Box<U, N>& rhs) {
682 std::vector<Box<U, N>> secondBounds;
684 std::partial_sum(boxes.rbegin(), boxes.rend(), std::back_inserter(secondBounds), [](
const Box<U, N>& lhs,
const Box<U, N>& rhs) {
690 for (std::size_t j = MinSize; j <= MaxSize - MinSize + 1; ++j) {
691 value += firstBounds[j].getExtentLength() + secondBounds[Size - j].getExtentLength();
697 std::size_t computeSplitIndex(
const std::vector<
Box<U, N>>& boxes, std::size_t axis) {
698 std::vector<Box<U, N>> firstBounds;
700 std::partial_sum(boxes.begin(), boxes.end(), std::back_inserter(firstBounds), [](
const Box<U, N>& lhs,
const Box<U, N>& rhs) {
704 std::vector<Box<U, N>> secondBounds;
706 std::partial_sum(boxes.rbegin(), boxes.rend(), std::back_inserter(secondBounds), [](
const Box<U, N>& lhs,
const Box<U, N>& rhs) {
713 const auto& bounds = firstBounds.back();
716 if (Node::hasOriginalBounds()) {
717 asym = 2.0f * ((bounds.max[axis] + bounds.min[axis]) / 2 - Node::getOriginalCenterAxisValue(axis)) / (bounds.max[axis] - bounds.min[axis]);
720 assert(-1.0f <= asym && asym <= 1.0f);
722 static constexpr
float S = 0.5f;
723 const float mu = (1 - 2.0f * MinSize / (MaxSize + 1)) * asym;
724 const float rho = S * (1 + std::abs(mu));
725 const float y1 = std::exp(- 1 / (S * S));
726 const float ys = 1 / (1 - y1);
728 auto wf = [mu,rho,y1,ys](std::size_t i) {
729 const float xi = 2.0f * i / (MaxSize + 1.0f) - 1.0f;
730 return ys * (std::exp(-
gf::square((xi - mu) / rho) - y1));
735 std::size_t currentIndex = 0;
736 U currentValue = std::numeric_limits<U>::max();
740 if (firstBounds[MinSize].getVolume() == 0 || secondBounds[MinSize].getVolume() == 0) {
748 bool overlapFree =
false;
750 U perimeterMax = 2 * bounds.getExtentLength() - bounds.getMinimumEdge();
752 for (std::size_t index = MinSize; index <= MaxSize - MinSize + 1; ++index) {
753 auto weight = (firstBounds[index].*overlapFn)(secondBounds[Size - index - 1]);
759 auto value = weight * wf(index);
761 if (value < currentValue) {
762 currentValue = value;
763 currentIndex = index;
768 if (overlapFree && weight == 0) {
769 weight = firstBounds[index].getExtentLength() + secondBounds[Size - index - 1].getExtentLength() - perimeterMax;
772 auto value = weight / wf(index);
774 if (value < currentValue) {
775 currentValue = value;
776 currentIndex = index;
785 boost::container::static_vector<LeafEntry, Size> m_entries;
792 struct BranchEntry : Entry {
796 class Branch :
public Node {
799 for (
auto& entry : m_entries) {
805 std::size_t found = 0;
807 for (
auto& entry : m_entries) {
809 found += entry.child->query(bounds, callback, kind);
816 virtual Leaf *chooseSubtree(
const Box<U, N>& bounds)
override {
817 return chooseNode(bounds)->chooseSubtree(bounds);
821 Node *bestNodeForVolume =
nullptr;
822 U bestVolume = std::numeric_limits<U>::max();
824 Node *bestNodeForExtentLength =
nullptr;
825 U bestExtentLength = std::numeric_limits<U>::max();
827 for (
auto& entry : m_entries) {
828 if (entry.bounds.getIntersection(bounds) == bounds) {
829 U volume = entry.bounds.getVolume();
831 if (bestNodeForVolume ==
nullptr || volume < bestVolume) {
833 bestNodeForVolume = entry.child;
836 U extentDistance = entry.bounds.getExtentLength();
838 if (bestNodeForExtentLength ==
nullptr || extentDistance < bestExtentLength) {
839 bestExtentLength = extentDistance;
840 bestNodeForExtentLength = entry.child;
845 if (bestNodeForVolume !=
nullptr) {
846 if (bestVolume > 0) {
847 return bestNodeForVolume;
850 assert(bestNodeForExtentLength);
851 return bestNodeForExtentLength;
858 Node *covering = searchForCoveringNode(bounds);
860 if (covering !=
nullptr) {
864 std::sort(m_entries.begin(), m_entries.end(), ExtentLengthEnlargement(bounds));
866 OverlapExtentLengthEnlargement extentDistanceEnlargement(bounds, m_entries.front());
870 for (p = m_entries.size() - 1; p > 0; --p) {
871 if (extentDistanceEnlargement(m_entries[p]) != 0) {
877 return m_entries[0].child;
880 std::vector<Candidate> candidates(p + 1, { 0,
false,
U() });
881 Node *node =
nullptr;
883 if (existsEmptyVolumeExtension(bounds)) {
884 node = findCandidates<OverlapExtentLengthEnlargement>(0, p, bounds, candidates);
886 node = findCandidates<OverlapVolumeEnlargement>(0, p, bounds, candidates);
889 if (node !=
nullptr) {
893 candidates.erase(std::remove_if(candidates.begin(), candidates.end(), [](
const Candidate& candidate) {
894 return !candidate.isCandidate;
895 }), candidates.end());
897 assert(!candidates.empty());
899 auto it = std::min_element(candidates.begin(), candidates.end(), [](
const Candidate& lhs,
const Candidate& rhs) {
900 return lhs.overlap < rhs.overlap;
903 return m_entries[it->index].child;
906 virtual Box<U,N> computeBounds()
const override {
907 assert(!m_entries.empty());
910 for (
auto& entry : m_entries) {
911 res.extend(entry.bounds);
917 virtual void appendToStructure(std::vector<
SpatialStructure<U, N>>& structures,
int level)
const override {
918 for (
auto& entry : m_entries) {
920 entry.child->appendToStructure(structures, level + 1);
924 void updateBoundsForChild(
const Box<U, N>& bounds,
Node *child) {
925 for (
auto& entry : m_entries) {
926 if (entry.child == child) {
927 entry.bounds = bounds;
937 entry.bounds = bounds;
939 m_entries.push_back(std::move(entry));
941 if (m_entries.size() < Size) {
945 std::vector<Box<U, N>> boxes;
947 std::transform(m_entries.begin(), m_entries.end(), std::back_inserter(boxes), [](
const Entry& entry) {
951 SplitResult split = computeSplit(boxes);
953 switch (split.order) {
954 case SplitOrder::Min:
955 std::sort(m_entries.begin(), m_entries.end(), EntryMinAxisComparator<BranchEntry>(split.axis));
957 case SplitOrder::Max:
958 std::sort(m_entries.begin(), m_entries.end(), EntryMaxAxisComparator<BranchEntry>(split.axis));
962 auto branch =
new Branch;
964 auto splitIteratorBegin = std::next(m_entries.begin(), split.index + 1);
965 auto splitIteratorEnd = m_entries.end();
967 std::move(splitIteratorBegin, splitIteratorEnd, std::back_inserter(branch->m_entries));
968 m_entries.erase(splitIteratorBegin, splitIteratorEnd);
970 for (
auto& entry : branch->m_entries) {
971 entry.child->setParent(branch);
984 bool existsEmptyVolumeExtension(
const Box<U, N>& bounds) {
985 for (
auto& entry : m_entries) {
986 if (entry.bounds.getExtended(bounds).getVolume() == 0) {
994 template<
typename OverlapEnlargement>
995 Node *findCandidates(std::size_t t, std::size_t p,
const Box<U, N>& bounds, std::vector<Candidate>& candidates) {
996 candidates[t].index = t;
997 candidates[t].isCandidate =
true;
999 OverlapEnlargement enlargement(bounds, m_entries[t]);
1003 for (std::size_t i = 0; i <= p; ++i) {
1008 U localOverlap = enlargement(m_entries[i]);
1009 overlap += localOverlap;
1011 if (localOverlap == 0 && !candidates[i].isCandidate) {
1012 Node *node = findCandidates<OverlapEnlargement>(i, p, bounds, candidates);
1014 if (node !=
nullptr) {
1021 return m_entries[t].child;
1024 candidates[t].overlap = overlap;
1028 struct SplitStatus {
1029 bool overlapFree =
false;
1030 U currentValue = std::numeric_limits<U>::max();
1033 SplitResult computeSplit(std::vector<
Box<U, N>>& boxes) {
1037 for (std::size_t axis = 0; axis <
N; ++axis) {
1038 std::sort(boxes.begin(), boxes.end(), MinAxisComparator(axis));
1039 computeBestSplitValue(boxes, result, status, axis, SplitOrder::Min);
1041 std::sort(boxes.begin(), boxes.end(), MaxAxisComparator(axis));
1042 computeBestSplitValue(boxes, result, status, axis, SplitOrder::Max);
1048 void computeBestSplitValue(std::vector<
Box<U, N>>& boxes, SplitResult& result, SplitStatus& status, std::size_t axis, SplitOrder order) {
1049 std::vector<Box<U, N>> firstBounds;
1051 std::partial_sum(boxes.begin(), boxes.end(), std::back_inserter(firstBounds), [](
const Box<U, N>& lhs,
const Box<U, N>& rhs) {
1055 std::vector<Box<U, N>> secondBounds;
1057 std::partial_sum(boxes.rbegin(), boxes.rend(), std::back_inserter(secondBounds), [](
const Box<U, N>& lhs,
const Box<U, N>& rhs) {
1063 const auto& bounds = firstBounds.back();
1066 if (Node::hasOriginalBounds()) {
1067 asym = 2.0f * ((bounds.max[axis] + bounds.min[axis]) / 2 - Node::getOriginalCenterAxisValue(axis)) / (bounds.max[axis] - bounds.min[axis]);
1070 assert(-1.0f <= asym && asym <= 1.0f);
1072 static constexpr
float S = 0.5f;
1073 const float mu = (1 - 2.0f * MinSize / (MaxSize + 1)) * asym;
1074 const float rho = S * (1 + std::abs(mu));
1075 const float y1 = std::exp(- 1 / (S * S));
1076 const float ys = 1 / (1 - y1);
1078 auto wf = [mu,rho,y1,ys](std::size_t i) {
1079 const float xi = 2.0f * i / (MaxSize + 1.0f) - 1.0f;
1080 return ys * (std::exp(-
gf::square((xi - mu) / rho) - y1));
1087 if (firstBounds[MinSize].getVolume() == 0 || secondBounds[MinSize].getVolume() == 0) {
1095 U perimeterMax = 2 * bounds.getExtentLength() - bounds.getMinimumEdge();
1097 for (std::size_t index = MinSize; index <= MaxSize - MinSize + 1; ++index) {
1098 auto weight = (firstBounds[index].*overlapFn)(secondBounds[Size - index - 1]);
1100 if (!status.overlapFree) {
1102 status.overlapFree =
true;
1104 auto value = weight * wf(index);
1106 if (value < status.currentValue) {
1107 status.currentValue = value;
1108 result.index = index;
1110 result.order = order;
1115 if (status.overlapFree && weight == 0) {
1116 weight = firstBounds[index].getExtentLength() + secondBounds[Size - index - 1].getExtentLength() - perimeterMax;
1117 assert(weight <= 0);
1119 auto value = weight / wf(index);
1121 if (value < status.currentValue) {
1122 status.currentValue = value;
1123 result.index = index;
1125 result.order = order;
1132 boost::container::static_vector<BranchEntry, Size> m_entries;
1139 class ExtentLengthEnlargement {
1141 ExtentLengthEnlargement(
const Box<U, N>& bounds)
1147 bool operator()(
const Entry& lhs,
const Entry& rhs)
const {
1148 return getExtentLengthEnlargement(lhs) < getExtentLengthEnlargement(rhs);
1151 U getExtentLengthEnlargement(
const Entry& entry)
const {
1152 return entry.bounds.getExtended(m_bounds).getExtentLength() - entry.bounds.getExtentLength();
1159 class OverlapExtentLengthEnlargement {
1161 OverlapExtentLengthEnlargement(
const Box<U, N>& bounds,
const Entry& reference)
1163 , m_reference(reference)
1164 , m_extended(reference.bounds.getExtended(bounds))
1169 U operator()(
const Entry& entry)
const {
1170 return getOverlapExtentLengthEnlargement(entry);
1173 U getOverlapExtentLengthEnlargement(
const Entry& entry)
const {
1174 return m_extended.getIntersectionExtentLength(entry.bounds) - m_reference.bounds.getIntersectionExtentLength(entry.bounds);
1179 const Entry& m_reference;
1184 class OverlapVolumeEnlargement {
1186 OverlapVolumeEnlargement(
const Box<U, N>& bounds,
const Entry& reference)
1188 , m_reference(reference)
1189 , m_extended(reference.bounds.getExtended(bounds))
1194 U operator()(
const Entry& entry)
const {
1195 return getOverlapVolumeEnlargement(entry);
1198 U getOverlapVolumeEnlargement(
const Entry& entry)
const {
1199 return m_extended.getIntersectionVolume(entry.bounds) - m_reference.bounds.getIntersectionVolume(entry.bounds);
1204 const Entry& m_reference;
1208 class MinAxisComparator {
1210 MinAxisComparator(std::size_t axis)
1217 return std::make_tuple(lhs.
min[m_axis], lhs.
max[m_axis]) < std::make_tuple(rhs.
min[m_axis], rhs.
max[m_axis]);
1224 template<
typename Entry>
1225 class EntryMinAxisComparator {
1227 EntryMinAxisComparator(std::size_t axis)
1233 bool operator()(
const Entry& lhs,
const Entry& rhs) {
1234 return std::make_tuple(lhs.bounds.min[m_axis], lhs.bounds.max[m_axis]) < std::make_tuple(rhs.bounds.min[m_axis], rhs.bounds.max[m_axis]);
1241 class MaxAxisComparator {
1243 MaxAxisComparator(std::size_t axis)
1250 return std::make_tuple(lhs.
max[m_axis], lhs.
min[m_axis]) < std::make_tuple(rhs.
max[m_axis], rhs.
min[m_axis]);
1257 template<
typename Entry>
1258 class EntryMaxAxisComparator {
1260 EntryMaxAxisComparator(std::size_t axis)
1266 bool operator()(
const Entry& lhs,
const Entry& rhs) {
1267 return std::make_tuple(lhs.bounds.max[m_axis], lhs.bounds.min[m_axis]) < std::make_tuple(rhs.bounds.max[m_axis], rhs.bounds.min[m_axis]);
1275 void updateBounds(
Node *node) {
1276 while (node !=
nullptr) {
1277 Box<U, N> bounds = node->computeBounds();
1279 Branch *parent = node->getParent();
1281 if (parent !=
nullptr) {
1282 parent->updateBoundsForChild(bounds, node);
1294 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1299 #endif // GF_SPATIAL_H constexpr Box< T, N > getExtended(const Box< T, N > &other) const noexcept
Get the box extended by another box.
Definition: Box.h:335
bool insert(T value, const Box< U, N > &bounds)
Insert an object in the tree.
Definition: Spatial.h:384
constexpr bool intersects(const Box< T, N > &other) const noexcept
Check if two boxes interset.
Definition: Box.h:203
Upper-right quarter.
Definition: Quarter.h:35
The structure represents an internal node.
void clear()
Remove all the objects from the tree.
Definition: Spatial.h:143
std::size_t query(const Box< U, N > &bounds, SpatialQueryCallback< T > callback, SpatialQuery kind=SpatialQuery::Intersect) const
Query objects in the tree.
Definition: Spatial.h:446
std::function< void(const T &)> SpatialQueryCallback
A callback for spatial query.
Definition: Spatial.h:87
std::vector< SpatialStructure< U, N > > getStructure() const
Definition: Spatial.h:458
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:323
SpatialStructureType type
The type of the structure.
Definition: Spatial.h:69
SpatialStructureType
A type of spatial structure.
Definition: Spatial.h:53
Box< U, N > bounds
The bounds of the structure.
Definition: Spatial.h:68
Vector< T, N > min
The minimum point of the box.
Definition: Box.h:53
Search for all objects that contain the given bounds.
constexpr Box< T, 2 > computeBoxQuarter(const Box< T, 2 > &box, Quarter quarter)
Divide a box in quarters.
Definition: Box.h:466
~RStarTree()
Destructor.
Definition: Spatial.h:373
Lower-right quarter.
Definition: Quarter.h:36
A spatial structure.
Definition: Spatial.h:67
Upper-left quarter.
Definition: Quarter.h:34
std::vector< SpatialStructure< U, 2 > > getStructure() const
Definition: Spatial.h:148
constexpr T square(T val)
Square function.
Definition: Math.h:289
std::size_t query(const Box< U, 2 > &bounds, SpatialQueryCallback< T > callback, SpatialQuery kind=SpatialQuery::Intersect) const
Query objects in the tree.
Definition: Spatial.h:136
Search for all objects that intersect the given bounds.
RStarTree & operator=(RStarTree &&other) noexcept
Move assignement.
Definition: Spatial.h:365
void clear()
Remove all the objects from the tree.
Definition: Spatial.h:453
The namespace for gf classes.
Definition: Action.h:35
QuadTree(const Box< U, 2 > &bounds)
Constructor.
Definition: Spatial.h:105
RStarTree()
Constructor.
Definition: Spatial.h:338
An implementation of quadtree.
Definition: Spatial.h:97
Lower-left quarter.
Definition: Quarter.h:37
The structure represents an actuel object.
Vector< T, N > max
The maximum point of the box.
Definition: Box.h:54
int level
The level of the structure.
Definition: Spatial.h:70
RStarTree(RStarTree &&other) noexcept
Move constructor.
Definition: Spatial.h:357
An implemntation of a R* tree.
Definition: Spatial.h:330
SpatialQuery
A kind of spatial query.
Definition: Spatial.h:77
bool insert(T value, const Box< U, 2 > &bounds)
Insert an object in the tree.
Definition: Spatial.h:118
constexpr bool contains(Vector< T, N > point) const noexcept
Check if a point is inside the box.
Definition: Box.h:171
constexpr void unused(Args &&...)
A simple way to avoid warnings about unused variables.
Definition: Unused.h:35