39#include <gtest/gtest.h>
131 for (
int i = 0; i < 10; ++i)
133 for (
int j = 0; j < 10; ++j)
142 for (
int i = 0; i < 10; ++i)
144 for (
int j = 0; j < 10; ++j)
155 for (
int i = 9; i >= 0; --i)
157 for (
int j = 9; j >= 0; --j)
170 std::mt19937
gen(12345);
171 std::uniform_real_distribution<>
dis(0, 1000);
173 std::vector<Point> points;
174 for (
int i = 0; i < 100; ++i)
183 for (
const auto & p : points)
194 for (
int i = 0; i < 20; ++i)
200 for (
int i = 0; i < 20; ++i)
276 for (
int i = 0; i <= 100; i += 10)
278 for (
int j = 0; j <= 100; j += 10)
302 tree.
range(rect, &result);
317 tree.
range(rect, &result);
331 tree.
range(rect, &result);
348 tree.
range(rect, &result);
354 for (
const auto & p : result)
376 tree.
range(rect, &result);
391 std::mt19937
gen(54321);
392 std::uniform_real_distribution<>
dis(0, 10000);
395 std::vector<Point> points;
414 std::mt19937
gen(99999);
415 std::uniform_real_distribution<>
dis(0, 1000);
418 for (
int i = 0; i < 1000; ++i)
424 for (
int i = 0; i < 1000; ++i)
437 std::mt19937
gen(11111);
438 std::uniform_real_distribution<>
dis(0, 1000);
441 for (
int i = 0; i < 1000; ++i)
447 for (
int i = 0; i < 100; ++i)
452 if (x1 > x2) std::swap(x1, x2);
453 if (
y1 > y2) std::swap(
y1, y2);
457 tree.
range(rect, &result);
469 for (
int i = 100; i <= 200; i += 2)
471 for (
int j = 100; j <= 200; j += 2)
478 for (
int i = 700; i <= 900; i += 50)
480 for (
int j = 700; j <= 900; j += 50)
509 for (
int i = 0; i <= 100; i += 10)
517 for (
int i = 0; i <= 100; i += 10)
527 for (
int i = 0; i <= 100; i += 10)
539 for (
int i = 0; i <= 100; i += 10)
580 std::vector<Point> points = {
588 for (
const auto & p : points)
596 for (
const auto & p : points)
607 std::mt19937
gen(77777);
608 std::uniform_real_distribution<>
dis(0, 100);
611 for (
int i = 0; i < 100; ++i)
620 tree.
range(rect, &result);
623 for (
const auto & p : result)
634 for (
const auto & r : result)
655 std::mt19937
gen(31415);
656 std::uniform_real_distribution<>
coord_dis(0, 10000);
657 std::uniform_int_distribution<>
op_dis(0, 2);
659 std::set<std::pair<double, double>>
inserted;
661 for (
int i = 0; i < 1000; ++i)
669 if (result !=
nullptr)
687 if (x1 > x2) std::swap(x1, x2);
688 if (
y1 > y2) std::swap(
y1, y2);
692 tree.
range(rect, &result);
709 ::testing::InitGoogleTest(&
argc,
argv);
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
2D k-d tree for efficient spatial point operations.
constexpr size_t size() const noexcept
Get the number of points in the tree.
static void range(Node *root, const Rectangle &rect, DynList< Point > *q)
Recursively find points within a rectangle.
Point nearest(const Point &p) noexcept
Find the nearest point to a query point.
bool contains(const Point &p) const noexcept
Check if the tree contains a point.
constexpr bool is_empty() const noexcept
Check if the tree is empty.
Point * insert(const Point &p)
Insert a point into the tree.
Rectangular point in the plane.
const Geom_Number & get_y() const
Returns y value.
Geom_Number distance_with(const Point &p) const
Returns the Euclidean distance between this and p.
const Geom_Number & get_x() const
Returns x value.
bool contains(const Point &p) const
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
DynList< T > maps(const C &c, Op op)
Classic map operation.
2D k-d tree implementation for spatial point indexing.