From 2ea4749161db6d8856407938911f1abfcf714b9d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 14 May 2018 14:03:15 -0700 Subject: *: initial commit libix2 implements a simple spatial index of objects described by 2D axis-aligned bounding boxes (AABB). It does so by internally utilizing a traditional quadtree data structure. At this time only simple AABB and point search queries are supported, with a simple per-match callback interface. It may make sense to in the future add support for indexing other 2D shapes than AABBs, like circles. It would also make senes to add more interesting search queries like radial ranges and such. The intended use is for broad-phase collision detection in 2D games. --- src/ix2.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/ix2.h (limited to 'src/ix2.h') diff --git a/src/ix2.h b/src/ix2.h new file mode 100644 index 0000000..345a310 --- /dev/null +++ b/src/ix2.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Vito Caputo - + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _IX2_H +#define _IX2_H + +typedef struct ix2_object_t ix2_object_t; +typedef struct ix2_t ix2_t; +typedef struct aabb_t aabb_t; +typedef struct v2f_t v2f_t; + +typedef enum ix2_search_status_t { + IX2_SEARCH_STOP, + IX2_SEARCH_IGNORE, + IX2_SEARCH_CONTINUE +} ix2_search_status_t; + +typedef ix2_search_status_t (*ix2_search_cb)(void *cb_context, ix2_object_t *ix2_object, aabb_t *ix2_object_aabb, void *object); + +ix2_t * ix2_new(aabb_t *aabb, unsigned max_per_node, unsigned max_depth); +void ix2_free(ix2_t *ix2); +ix2_object_t * ix2_insert_object(ix2_t *ix2, aabb_t *aabb, void *object); +void ix2_remove_object(ix2_t *ix2, ix2_object_t *object); +ix2_object_t * ix2_move_object(ix2_t *ix2, ix2_object_t *object, aabb_t *aabb); +unsigned ix2_search_by_point(ix2_t *ix2, v2f_t *point, ix2_search_cb cb, void *arg); +unsigned ix2_search_by_aabb(ix2_t *ix2, aabb_t *aabb, ix2_search_cb cb, void *arg); +unsigned ix2_search_by_ray(ix2_t *ix2, v2f_t *origin, v2f_t *direction, ix2_search_cb cb, void *arg); + +#endif -- cgit v1.2.3