| 171 | }; |
| 172 | |
| 173 | std::size_t Tree::addPoint(const QuadPointRef* toAdd, const std::size_t curDepth) |
| 174 | { |
| 175 | if (data) |
| 176 | { |
| 177 | const Point& center(bbox.center); |
| 178 | |
| 179 | if (toAdd->point.sqDist(center) < data->point.sqDist(center)) |
| 180 | { |
| 181 | std::swap(data, toAdd); |
| 182 | } |
| 183 | |
| 184 | const std::size_t nextDepth(curDepth + 1); |
| 185 | |
| 186 | if (toAdd->point.x < center.x) |
| 187 | { |
| 188 | if (toAdd->point.y < center.y) |
| 189 | { |
| 190 | if (sw) |
| 191 | { |
| 192 | return sw->addPoint(toAdd, nextDepth); |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | sw.reset(new Tree( |
| 197 | BBox( |
| 198 | Point(bbox.minimum.x, bbox.minimum.y), |
| 199 | Point(center.x, center.y)), |
| 200 | toAdd)); |
| 201 | |
| 202 | return nextDepth; |
| 203 | } |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | if (nw) |
| 208 | { |
| 209 | return nw->addPoint(toAdd, nextDepth); |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | nw.reset(new Tree( |
| 214 | BBox( |
| 215 | Point(bbox.minimum.x, center.y), |
| 216 | Point(center.x, bbox.maximum.y)), |
| 217 | toAdd)); |
| 218 | |
| 219 | return nextDepth; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | if (toAdd->point.y < center.y) |
| 226 | { |
| 227 | if (se) |
| 228 | { |
| 229 | return se->addPoint(toAdd, nextDepth); |
| 230 | } |