39#include <gtest/gtest.h>
132 for (
int i = 0; i < 10; ++i)
134 for (
int j = 0; j < 10; ++j)
143 for (
int i = 0; i < 10; ++i)
145 for (
int j = 0; j < 10; ++j)
156 for (
int i = 9; i >= 0; --i)
158 for (
int j = 9; j >= 0; --j)
171 std::mt19937
gen(12345);
172 std::uniform_real_distribution<>
dis(0, 1000);
174 std::vector<Point> points;
175 for (
int i = 0; i < 100; ++i)
184 for (
const auto & p : points)
195 for (
int i = 0; i < 20; ++i)
201 for (
int i = 0; i < 20; ++i)
278 for (
int i = 0; i <= 100; i += 10)
280 for (
int j = 0; j <= 100; j += 10)
357 for (
const auto & p : result)
394 std::mt19937
gen(54321);
395 std::uniform_real_distribution<>
dis(0, 10000);
398 std::vector<Point> points;
417 std::mt19937
gen(99999);
418 std::uniform_real_distribution<>
dis(0, 1000);
421 for (
int i = 0; i < 1000; ++i)
427 for (
int i = 0; i < 1000; ++i)
430 auto nearest = tree.
nearest(query);
439 std::mt19937
gen(11111);
440 std::uniform_real_distribution<>
dis(0, 1000);
443 for (
int i = 0; i < 1000; ++i)
449 for (
int i = 0; i < 100; ++i)
454 if (x1 > x2) std::swap(x1, x2);
455 if (
y1 > y2) std::swap(
y1, y2);
471 for (
int i = 100; i <= 200; i += 2)
473 for (
int j = 100; j <= 200; j += 2)
480 for (
int i = 700; i <= 900; i += 50)
482 for (
int j = 700; j <= 900; j += 50)
511 for (
int i = 0; i <= 100; i += 10)
519 for (
int i = 0; i <= 100; i += 10)
529 for (
int i = 0; i <= 100; i += 10)
541 for (
int i = 0; i <= 100; i += 10)
582 std::vector<Point> points = {
590 for (
const auto & p : points)
594 auto nearest = tree.
nearest(query);
599 for (
const auto & p : points)
610 std::mt19937
gen(77777);
611 std::uniform_real_distribution<>
dis(0, 100);
614 for (
int i = 0; i < 100; ++i)
626 for (
const auto & p : result)
634 if (
rect.contains(p))
637 for (
const auto &
r : result)
645 EXPECT_TRUE(found) <<
"Point in rectangle not found in result";
658 std::mt19937
gen(31415);
659 std::uniform_real_distribution<>
coord_dis(0, 10000);
660 std::uniform_int_distribution<>
op_dis(0, 2);
662 std::set<std::pair<double, double>> inserted;
664 for (
int i = 0; i < 1000; ++i)
674 inserted.insert(std::make_pair(
static_cast<double>(p.
get_x().
get_d()),
681 auto nearest = tree.
nearest(query);
690 if (x1 > x2) std::swap(x1, x2);
691 if (
y1 > y2) std::swap(
y1, y2);
700 for (
const auto & [x,
y] : inserted)
733 std::mt19937
gen(55555);
734 std::uniform_real_distribution<>
dis(0, 1000);
736 std::vector<Point> points;
737 for (
int i = 0; i < 200; ++i)
744 for (
const auto & p : points)
785 dst = std::move(src);
802 tree = std::move(*self);
845 for (
size_t i = 0; i <
pts.size(); ++i)
869 for (
int i = 0; i <= 100; i += 10)
870 for (
int j = 0; j <= 100; j += 10)
877 auto nearest = tree.nearest(
Point(43, 57));
887 std::mt19937
gen(12321);
888 std::uniform_real_distribution<>
dis(0, 10000);
891 for (
int i = 0; i < 5000; ++i)
897 for (
size_t i = 0; i <
pts.size(); ++i)
901 for (
int i = 0; i < 100; ++i)
904 auto near_bal = balanced.nearest(query);
909 for (
size_t j = 0; j <
pts.size(); ++j)
935 std::set<std::pair<double, double>>
expected;
936 for (
int i = 0; i <= 50; i += 10)
937 for (
int j = 0; j <= 50; j += 10)
940 expected.insert({
static_cast<double>(i),
static_cast<double>(j)});
943 std::set<std::pair<double, double>> visited;
956 for (
int i = 1; i <= 100; ++i)
974 ::testing::InitGoogleTest(&
argc,
argv);
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Dynamic singly linked list with functional programming support.
constexpr bool is_empty() const noexcept
size_t size() const noexcept
Count the number of elements of the list.
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
An axis-aligned rectangle.
2D k-d tree for efficient spatial point operations.
bool insert(const Point &p)
Insert a point into the tree.
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.
void for_each(Op &&op) const
Apply an operation to every point in the tree (inorder).
static K2Tree build(Array< Point > points, const Point &pmin, const Point &pmax)
Build a balanced k-d tree from an array of points.
bool contains(const Point &p) const noexcept
Check if the tree contains a point.
std::optional< Point > nearest(const Point &p) const noexcept
Find the nearest point to a query point.
constexpr bool is_empty() const noexcept
Check if the tree is empty.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
2D k-d tree implementation for spatial point indexing.
Dynamic array container with automatic resizing.