Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
r_tree_debug_snapshot_test_helpers.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 https://github.com/lrleon/Aleph-w
6
7 This file is part of Aleph-w library
8
9 Copyright (c) 2002-2026 Leandro Rabindranath Leon
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 SOFTWARE.
28*/
29
35#ifndef TESTS_R_TREE_DEBUG_SNAPSHOT_TEST_HELPERS_H
36#define TESTS_R_TREE_DEBUG_SNAPSHOT_TEST_HELPERS_H
37
38#include <gtest/gtest.h>
39#include <point.H>
40#include <tpl_array.H>
41
43{
52 inline Rectangle union_of(const Rectangle &a, const Rectangle &b)
53 {
54 return Rectangle(a.get_xmin() < b.get_xmin() ? a.get_xmin() : b.get_xmin(),
55 a.get_ymin() < b.get_ymin() ? a.get_ymin() : b.get_ymin(),
56 a.get_xmax() > b.get_xmax() ? a.get_xmax() : b.get_xmax(),
57 a.get_ymax() > b.get_ymax() ? a.get_ymax() : b.get_ymax());
58 }
59
60 namespace detail
61 {
62 template <typename Snapshot>
63 size_t check_snapshot_node_impl(const Snapshot &snap, const size_t idx,
64 const size_t expected_depth, Array<bool> &visited)
65 {
66 if (idx >= snap.nodes.size())
67 {
68 ADD_FAILURE() << "node index " << idx << " out of range (nodes.size() = "
69 << snap.nodes.size() << ")";
70 return 0;
71 }
72 if (visited(idx))
73 {
74 ADD_FAILURE() << "cycle detected: node index " << idx << " reached more than once";
75 return 0;
76 }
77 visited(idx) = true;
78
79 const auto &node = snap.nodes(idx);
80 EXPECT_EQ(node.depth, expected_depth);
81
82 if (node.is_leaf)
83 {
84 EXPECT_FALSE(node.entry_boxes.is_empty());
85 if (node.entry_boxes.is_empty())
86 return 0;
87 Rectangle acc = node.entry_boxes(0);
88 for (size_t i = 1; i < node.entry_boxes.size(); ++i)
89 acc = union_of(acc, node.entry_boxes(i));
90 EXPECT_EQ(node.bbox, acc);
91 return node.entry_boxes.size();
92 }
93
94 EXPECT_FALSE(node.children.is_empty());
95 if (node.children.is_empty())
96 return 0;
97 EXPECT_LT(node.children(0), snap.nodes.size());
98 if (node.children(0) >= snap.nodes.size())
99 return 0;
100 Rectangle acc = snap.nodes(node.children(0)).bbox;
101 size_t total = check_snapshot_node_impl(snap, node.children(0), expected_depth + 1, visited);
102 for (size_t i = 1; i < node.children.size(); ++i)
103 {
104 EXPECT_LT(node.children(i), snap.nodes.size());
105 if (node.children(i) >= snap.nodes.size())
106 return total;
107 total += check_snapshot_node_impl(snap, node.children(i), expected_depth + 1, visited);
108 acc = union_of(acc, snap.nodes(node.children(i)).bbox);
109 }
110 EXPECT_EQ(node.bbox, acc);
111 return total;
112 }
113 }
114
142 template <typename Snapshot>
143 size_t check_snapshot_node(const Snapshot &snap, const size_t idx, const size_t expected_depth)
144 {
145 Array<bool> visited(snap.nodes.size(), false);
147 }
148}
149
150#endif // TESTS_R_TREE_DEBUG_SNAPSHOT_TEST_HELPERS_H
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:138
An axis-aligned rectangle.
Definition point.H:1789
const Geom_Number & get_xmin() const
Gets the minimum x-coordinate.
Definition point.H:1815
const Geom_Number & get_ymax() const
Gets the maximum y-coordinate.
Definition point.H:1830
const Geom_Number & get_ymin() const
Gets the minimum y-coordinate.
Definition point.H:1820
const Geom_Number & get_xmax() const
Gets the maximum x-coordinate.
Definition point.H:1825
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
size_t check_snapshot_node_impl(const Snapshot &snap, const size_t idx, const size_t expected_depth, Array< bool > &visited)
Rectangle union_of(const Rectangle &a, const Rectangle &b)
Computes the tight axis-aligned union of two rectangles.
size_t check_snapshot_node(const Snapshot &snap, const size_t idx, const size_t expected_depth)
Recursively validates the structural invariants of a DebugSnapshot produced by RTree::debug_snapshot(...
2D point and geometric utilities.
Dynamic array container with automatic resizing.