Last active
August 29, 2015 13:57
-
-
Save cjhanks/9767077 to your computer and use it in GitHub Desktop.
Evil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool | |
impl_query_pose_index(PoseIndexUncompressCtx* ctx, PoseIndexReq* req | |
, PoseIndexRes* res) | |
{ | |
if (!unpack_block(ctx)) | |
return false; | |
static void* dispatch[] = { &&above, &&below, &&exit }; | |
enum State { AboveThreshold = 0, BelowThreshold = 1, Done = 2 }; | |
enum State state = AboveThreshold; | |
double threshold_square = pow(req->radius, 2); | |
size_t i = 0; | |
PoseIndexComposite winner; | |
double winner_square; | |
double square; | |
next: | |
if (i == ctx->root->index_count) | |
state = Done; | |
else | |
square = square_value(req->x, ctx->comp[i].x | |
, req->y, ctx->comp[i].y); | |
goto *dispatch[state]; | |
above: | |
/* if within the range we are now below threshold */ | |
if (square <= threshold_square) { | |
winner = ctx->comp[i]; | |
winner_square = square; | |
state = BelowThreshold; | |
} | |
++i; | |
goto next; | |
below: | |
/* we have gone above limit */ | |
if (square > threshold_square) { | |
state = AboveThreshold; | |
res->timestamp_size++; | |
res->timestamp = (uint64_t*)realloc(res->timestamp | |
, res->timestamp_size * | |
sizeof(uint64_t)); | |
res->timestamp[res->timestamp_size - 1] = winner.timestamp; | |
/* check for new winner */ | |
} else if (square < winner_square) { | |
winner = ctx->comp[i]; | |
} | |
++i; | |
goto next; | |
exit: | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment