From ce85a583e8ac53acdcb7fc15e995de207be9f9eb Mon Sep 17 00:00:00 2001 From: leonmavr <0xleo.git@gmail.com> Date: Fri, 20 Sep 2024 17:18:25 +0200 Subject: [PATCH] insertion: ignore points that are off the boundary --- src/quad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/quad.c b/src/quad.c index 7adc474..13280f1 100644 --- a/src/quad.c +++ b/src/quad.c @@ -94,7 +94,6 @@ static void rect_divide(rect_t* src, rect_t* dest) { static int point_get_quadrant(rect_t* rect, point_t* point) { const int mid_x = (rect->x0 + rect->x1) / 2; const int mid_y = (rect->y0 + rect->y1) / 2; - if (point->x <= mid_x && point->y <= mid_y) return IND_NW; else if (point->x > mid_x && point->y <= mid_y) return IND_NE; else if (point->x > mid_x && point->y > mid_y) return IND_SE; @@ -134,6 +133,8 @@ static bool node_is_leaf(node_t* node) { } static void node_insert(node_t* node, point_t* point) { + if (!point_in_rect(point, &node->boundary)) + return; if (node->count < node_capacity && node_is_leaf(node)) { node->points[node->count++] = *point; } else {