adding the shape based on the shape bounds (point) */
| 671 | |
| 672 | /* adding the shape based on the shape bounds (point) */ |
| 673 | static int treeNodeAddShape(msClusterLayerInfo* layerinfo, clusterTreeNode* node, clusterInfo* shape, int depth) |
| 674 | { |
| 675 | int i; |
| 676 | |
| 677 | /* -------------------------------------------------------------------- */ |
| 678 | /* If there are subnodes, then consider whether this object */ |
| 679 | /* will fit in them. */ |
| 680 | /* -------------------------------------------------------------------- */ |
| 681 | if( depth > 1 && node->subnode[0] != NULL ) |
| 682 | { |
| 683 | for(i = 0; i < 4; i++ ) |
| 684 | { |
| 685 | if( msRectContained(&shape->shape.bounds, &node->subnode[i]->rect)) |
| 686 | { |
| 687 | return treeNodeAddShape( layerinfo, node->subnode[i], shape, depth-1); |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /* -------------------------------------------------------------------- */ |
| 693 | /* Otherwise, consider creating four subnodes if could fit into */ |
| 694 | /* them, and adding to the appropriate subnode. */ |
| 695 | /* -------------------------------------------------------------------- */ |
| 696 | else if( depth > 1 && node->subnode[0] == NULL ) |
| 697 | { |
| 698 | rectObj half1, half2, quad1, quad2, quad3, quad4; |
| 699 | int subnode = -1; |
| 700 | |
| 701 | treeSplitBounds(&node->rect, &half1, &half2); |
| 702 | treeSplitBounds(&half1, &quad1, &quad2); |
| 703 | treeSplitBounds(&half2, &quad3, &quad4); |
| 704 | |
| 705 | if(msRectContained(&shape->shape.bounds, &quad1)) |
| 706 | subnode = 0; |
| 707 | else if(msRectContained(&shape->shape.bounds, &quad2)) |
| 708 | subnode = 1; |
| 709 | else if(msRectContained(&shape->shape.bounds, &quad3)) |
| 710 | subnode = 2; |
| 711 | else if(msRectContained(&shape->shape.bounds, &quad4)) |
| 712 | subnode = 3; |
| 713 | |
| 714 | if (subnode >= 0) |
| 715 | { |
| 716 | if ((node->subnode[0] = clusterTreeNodeCreate(layerinfo, quad1)) == NULL) |
| 717 | return MS_FAILURE; |
| 718 | node->subnode[0]->position = node->position * 4; |
| 719 | |
| 720 | if ((node->subnode[1] = clusterTreeNodeCreate(layerinfo, quad2)) == NULL) |
| 721 | return MS_FAILURE; |
| 722 | node->subnode[1]->position = node->position * 4 + 1; |
| 723 | |
| 724 | if ((node->subnode[2] = clusterTreeNodeCreate(layerinfo, quad3)) == NULL) |
| 725 | return MS_FAILURE; |
| 726 | node->subnode[2]->position = node->position * 4 + 2; |
| 727 | |
| 728 | if ((node->subnode[3] = clusterTreeNodeCreate(layerinfo, quad4)) == NULL) |
| 729 | return MS_FAILURE; |
| 730 | node->subnode[3]->position = node->position * 4 + 3; |
no test coverage detected