MCPcopy Index your code
hub / github.com/MapServer/MapServer / findRelatedShapes

Function findRelatedShapes

mapcluster.c:397–452  ·  view source on GitHub ↗

traverse the quadtree to find the neighbouring shapes and update some data on the related shapes (when adding a new feature)*/

Source from the content-addressed store, hash-verified

395/* traverse the quadtree to find the neighbouring shapes and update some data
396on the related shapes (when adding a new feature)*/
397static void findRelatedShapes(msClusterLayerInfo* layerinfo,
398 clusterTreeNode *node, clusterInfo* current)
399{
400 int i;
401 clusterInfo* s;
402
403 /* -------------------------------------------------------------------- */
404 /* Does this node overlap the area of interest at all? If not, */
405 /* return without adding to the list at all. */
406 /* -------------------------------------------------------------------- */
407 if(!msRectOverlap(&node->rect, &current->bounds))
408 return;
409
410 /* Modify the feature count of the related shapes */
411 s = node->shapes;
412 while (s)
413 {
414 if (layerinfo->fnCompare(current, s))
415 {
416 ++current->numsiblings;
417 /* calculating the average positions */
418 current->avgx = (current->avgx * current->numsiblings + s->x) / (current->numsiblings + 1);
419 current->avgy = (current->avgy * current->numsiblings + s->y) / (current->numsiblings + 1);
420 /* calculating the variance */
421 current->varx = current->varx * current->numsiblings / (current->numsiblings + 1) +
422 (s->x - current->avgx) * (s->x - current->avgx) / (current->numsiblings + 1);
423 current->vary = current->vary * current->numsiblings / (current->numsiblings + 1) +
424 (s->y - current->avgy) * (s->y - current->avgy) / (current->numsiblings + 1);
425
426 if (layerinfo->fnCompare(s, current))
427 {
428 /* this feature falls into the region of the other as well */
429 ++s->numsiblings;
430 /* calculating the average positions */
431 s->avgx = (s->avgx * s->numsiblings + current->x) / (s->numsiblings + 1);
432 s->avgy = (s->avgy * s->numsiblings + current->y) / (s->numsiblings + 1);
433 /* calculating the variance */
434 s->varx = s->varx * s->numsiblings / (s->numsiblings + 1) +
435 (current->x - s->avgx) * (current->x - s->avgx) / (s->numsiblings + 1);
436 s->vary = s->vary * s->numsiblings / (s->numsiblings + 1) +
437 (current->y - s->avgy) * (current->y - s->avgy) / (s->numsiblings + 1);
438 }
439 }
440 s = s->next;
441 }
442
443 if (node->subnode[0] == NULL)
444 return;
445
446 /* Recurse to subnodes if they exist */
447 for (i = 0; i < 4; i++)
448 {
449 if (node->subnode[i])
450 findRelatedShapes(layerinfo, node->subnode[i], current);
451 }
452}
453
454/* traverse the quadtree to find the neighbouring shapes and update some data

Callers 1

RebuildClustersFunction · 0.85

Calls 1

msRectOverlapFunction · 0.85

Tested by

no test coverage detected