/*! Checks whether a single layout object shape will fit into one of the childrens quadTree. It calls add() and returns success if the new layout object fits entirely into one of the possible subtrees or if it blows up its overlaping area not more than 10%. Returns false if the shape does not fit anywhere - means it should be placed higher into the quadTree structure.\n The method might be called recursively via the add() method. */ bool laydata::quadTree::fitintree(tdtdata* shape) { DBbox shovl = shape->overlap(); float clipedarea[4]; // check the clipping to see in witch region to place the shape for (byte i = 0; i < 4 ; i++) { DBbox subbox = _overlap.getcorner(i); clipedarea[i] = subbox.cliparea(shovl,true); if (-1 == clipedarea[i]) {//entirely inside the area if (!_quads[i]) _quads[i] = DEBUG_NEW quadTree(); _quads[i]->add(shape); return true; } } // if we got to this point - means that the shape does not fit // entirely inside neither of the four sub-areas. // It is a decision time then byte candidate = biggest(clipedarea); // now calculate the eventual new overlaping box DBbox newovl = _overlap.getcorner(candidate); newovl.overlap(shovl); // if the max area of the candidate does not blow more than 10% - // then seems to be OK to get it if (newovl.area() < 1.1 * (_overlap.area() / 4)) { if (!_quads[candidate]) _quads[candidate] = DEBUG_NEW quadTree(); _quads[candidate]->add(shape); return true; } return false; // shape can not be fit into any subtree }
/*! Checks whether a single layout object shape will fit into one of the childrens quadTree. Returns the index of the child quadTree which fits the shape or -1 otherwise. */ int laydata::quadTree::fitsubtree(DBbox shovl, DBbox* maxsubbox ) { float clipedarea[4]; // check the clipping to see in witch region to place the shape for (byte i = 0; i < 4 ; i++) { clipedarea[i] = maxsubbox[i].cliparea(shovl,true); if (-1 == clipedarea[i]) {//entirely inside the area return i; } } // if we got to this point - means that the shape does not fit // entirely inside neither of the four sub-areas. // It is a decision time then byte candidate = biggest(clipedarea); // now calculate the eventual new overlaping box DBbox newovl = maxsubbox[candidate]; newovl.overlap(shovl); // if the max area of the candidate does not blow more than 10% - // then seems to be OK to get it if (newovl.area() < 1.1 * (_overlap.area() / 4)) { return candidate; } return -1; // shape can not be fit into any subtree }