diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2018-11-28 00:13:11 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2018-11-28 00:13:11 -0800 |
commit | 2186240198bd82ecd08cac8937bed2b3c4e29623 (patch) | |
tree | ec3a048bf44fedbda7cf3c7532eeb2b6aa84af81 | |
parent | 28c0347ab1af0adec0249788f8351b0bde06297e (diff) |
libix3: disambiguate ix3_search_status_t
Previously one could only say stop/ignore/continue from the
search callback.
There was no way to say stop and ignore, or stop but don't ignore.
Now there are basically two classes of returns, stop and continue,
and each of those have ignore/don't ignore sub-statuses. The naming
is changed to STOP vs. MORE and HIT vs. MISS for brevity:
typedef enum ix3_search_status_t {
IX3_SEARCH_STOP_MISS,
IX3_SEARCH_STOP_HIT,
IX3_SEARCH_MORE_MISS,
IX3_SEARCH_MORE_HIT,
} ix3_search_status_t;
-rw-r--r-- | src/ix3.c | 43 | ||||
-rw-r--r-- | src/ix3.h | 7 | ||||
-rw-r--r-- | src/test.c | 2 |
3 files changed, 35 insertions, 17 deletions
@@ -676,13 +676,22 @@ unsigned ix3_search_by_point(ix3_t *ix3, v3f_t *point, ix3_search_cb cb, void *c ix3_object_t *o = ref->object; r = cb(cb_context, o, &o->position, &o->aabb, o->object); - if (r == IX3_SEARCH_STOP) { + switch (r) { + case IX3_SEARCH_STOP_HIT: + n_hits++; + + case IX3_SEARCH_STOP_MISS: + return n_hits; + + case IX3_SEARCH_MORE_HIT: n_hits++; - break; - } - if (r == IX3_SEARCH_IGNORE) + case IX3_SEARCH_MORE_MISS: continue; + + default: + assert(0); + } } n_hits++; @@ -772,22 +781,30 @@ unsigned ix3_search_by_aabb(ix3_t *ix3, v3f_t *search_position, v3f_t *search_or ix3_search_status_t r; r = cb(cb_context, o, &o->position, &o->aabb, o->object); - if (r == IX3_SEARCH_STOP) { + switch (r) { + case IX3_SEARCH_STOP_HIT: n_hits++; - break; - } - if (r == IX3_SEARCH_IGNORE) + case IX3_SEARCH_STOP_MISS: + /* XXX: this is necessary, the hits nodes must be kept movable */ + list_for_each_entry_safe(o, _o, &hits, hits) + list_del_init(&o->hits); + + return n_hits; + + case IX3_SEARCH_MORE_HIT: + n_hits++; + + case IX3_SEARCH_MORE_MISS: continue; + + default: + assert(0); + } } n_hits++; } - /* just in case the search was aborted, finish deleting these nodes */ - /* FIXME: this whole hit list thing is pretty janky */ - list_for_each_entry_safe(o, _o, &hits, hits) - list_del_init(&o->hits); - return n_hits; } @@ -23,9 +23,10 @@ typedef struct bb3f_t bb3f_t; typedef struct v3f_t v3f_t; typedef enum ix3_search_status_t { - IX3_SEARCH_STOP, - IX3_SEARCH_IGNORE, - IX3_SEARCH_CONTINUE + IX3_SEARCH_STOP_MISS, + IX3_SEARCH_STOP_HIT, + IX3_SEARCH_MORE_MISS, + IX3_SEARCH_MORE_HIT, } ix3_search_status_t; typedef ix3_search_status_t (*ix3_search_cb)(void *cb_context, ix3_object_t *ix3_object, v3f_t *ix3_object_position, bb3f_t *ix3_object_aabb, void *object); @@ -35,7 +35,7 @@ ix3_search_status_t cb(void *cb_context, ix3_object_t *ix3_object, v3f_t *ix3_ob ix3_object_aabb->min.x, ix3_object_aabb->min.y, ix3_object_aabb->min.z, ix3_object_aabb->max.x, ix3_object_aabb->max.y, ix3_object_aabb->max.z); - return IX3_SEARCH_CONTINUE; + return IX3_SEARCH_MORE_HIT; } typedef struct object_t { |