Algorithm-QuadTree-XS
view release on metacpan or search on metacpan
free(root);
void
_AQT_addObject(self, object, x, y, x2_or_radius, ...)
SV *self
SV *object
double x
double y
double x2_or_radius
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
Shape param;
param.x = x;
param.y = y;
if (items > 5) {
param.type = shape_rectangle;
param.x2 = x2_or_radius;
param.y2 = SvNV(ST(5));
}
else {
param.type = shape_circle;
param.radius_sq = x2_or_radius * x2_or_radius;
}
if (fill_nodes(root, root->node, object, ¶m)) {
push_array_SV(root->objects, object);
}
SV*
_AQT_findObjects(self, x, y, x2_or_radius, ...)
SV *self
double x
double y
double x2_or_radius
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
HV *ret_hash = newHV();
Shape param;
param.x = x;
param.y = y;
if (items > 4) {
param.type = shape_rectangle;
param.x2 = x2_or_radius;
param.y2 = SvNV(ST(4));
}
else {
param.type = shape_circle;
param.radius_sq = x2_or_radius * x2_or_radius;
}
find_nodes(root->node, ret_hash, ¶m);
AV *ret = get_hash_values(ret_hash);
SvREFCNT_dec((SV*) ret_hash);
RETVAL = newRV_noinc((SV*) ret);
OUTPUT:
RETVAL
void
_AQT_delete(self, object)
SV *self
SV *object
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
if (hv_exists_ent(root->backref, object, 0)) {
DynArr* list = (DynArr*) SvIV(HeVAL(hv_fetch_ent(root->backref, object, 0, 0)));
int i, j;
for (i = 0; i < list->count; ++i) {
QuadTreeNode *node = (QuadTreeNode*) list->ptr[i];
DynArr* new_list = create_array();
for(j = 0; j < node->values->count; ++j) {
SV *fetched = (SV*) node->values->ptr[j];
if (!sv_eq(fetched, object)) {
push_array(new_list, fetched);
}
}
destroy_array(node->values);
node->values = new_list;
if (new_list->count == 0) clear_has_objects(node);
}
destroy_array(list);
hv_delete_ent(root->backref, object, 0, 0);
DynArr* new_list = create_array();
for(j = 0; j < root->objects->count; ++j) {
SV *fetched = (SV*) root->objects->ptr[j];
if (!sv_eq(fetched, object)) {
push_array(new_list, fetched);
}
else {
SvREFCNT_dec(fetched);
}
}
destroy_array(root->objects);
root->objects = new_list;
}
void
_AQT_clear(self)
SV* self
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
clear_tree(root);
MODULE = Algorithm::QuadTree::XS PACKAGE = Algorithm::QuadTree::XS::NoBackRefs PREFIX = nbr
PROTOTYPES: DISABLE
void
nbr_AQT_init(obj)
free(root);
void
nbr_AQT_addObject(self, object, x, y, x2_or_radius, ...)
SV *self
SV *object
double x
double y
double x2_or_radius
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
Shape param;
param.x = x;
param.y = y;
if (items > 5) {
param.type = shape_rectangle;
param.x2 = x2_or_radius;
param.y2 = SvNV(ST(5));
}
else {
param.type = shape_circle;
param.radius_sq = x2_or_radius * x2_or_radius;
}
if (fill_nodes_nobackref(root->node, object, ¶m)) {
push_array_SV(root->objects, object);
}
SV*
nbr_AQT_findObjects(self, x, y, x2_or_radius, ...)
SV *self
double x
double y
double x2_or_radius
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
HV *ret_hash = newHV();
Shape param;
param.x = x;
param.y = y;
if (items > 4) {
param.type = shape_rectangle;
param.x2 = x2_or_radius;
param.y2 = SvNV(ST(4));
}
else {
param.type = shape_circle;
param.radius_sq = x2_or_radius * x2_or_radius;
}
find_nodes(root->node, ret_hash, ¶m);
AV *ret = get_hash_values(ret_hash);
SvREFCNT_dec((SV*) ret_hash);
RETVAL = newRV_noinc((SV*) ret);
OUTPUT:
RETVAL
void
nbr_AQT_clear(self)
SV* self
CODE:
QuadTreeRootNode *root = get_root_from_perl(self);
clear_tree(root);
( run in 0.469 second using v1.01-cache-2.11-cpan-13bb782fe5a )