Calculate the quadrant that the specified entity belongs to. Touching a line is considered overlapping a line. Touching is determined using :py:meth:`math.isclose` Quadrants are: - -1: None (it overlaps 2 or more quadrants)
(self, entity)
| 208 | |
| 209 | |
| 210 | def get_quadrant(self, entity): |
| 211 | """ |
| 212 | Calculate the quadrant that the specified entity belongs to. |
| 213 | |
| 214 | Touching a line is considered overlapping a line. Touching is |
| 215 | determined using :py:meth:`math.isclose` |
| 216 | |
| 217 | Quadrants are: |
| 218 | |
| 219 | - -1: None (it overlaps 2 or more quadrants) |
| 220 | - 0: Top-left |
| 221 | - 1: Top-right |
| 222 | - 2: Bottom-right |
| 223 | - 3: Bottom-left |
| 224 | |
| 225 | .. caution:: |
| 226 | |
| 227 | This function does not verify the entity is contained in this quadtree. |
| 228 | |
| 229 | This operation takes O(1) time. |
| 230 | |
| 231 | :param entity: the entity to place |
| 232 | :type entity: :class:`.QuadTreeEntity` |
| 233 | :returns: quadrant |
| 234 | :rtype: int |
| 235 | """ |
| 236 | |
| 237 | _aabb = entity.aabb |
| 238 | _halfwidth = self.location.width / 2 |
| 239 | _halfheight = self.location.height / 2 |
| 240 | _x = self.location.mincorner.x |
| 241 | _y = self.location.mincorner.y |
| 242 | |
| 243 | if math.isclose(_aabb.mincorner.x, _x + _halfwidth): |
| 244 | return -1 |
| 245 | if math.isclose(_aabb.mincorner.x + _aabb.width, _x + _halfwidth): |
| 246 | return -1 |
| 247 | if math.isclose(_aabb.mincorner.y, _y + _halfheight): |
| 248 | return -1 |
| 249 | if math.isclose(_aabb.mincorner.y + _aabb.height, _y + _halfheight): |
| 250 | return -1 |
| 251 | |
| 252 | _leftside_isleft = _aabb.mincorner.x < _x + _halfwidth |
| 253 | _rightside_isleft = _aabb.mincorner.x + _aabb.width < _x + _halfwidth |
| 254 | |
| 255 | if _leftside_isleft != _rightside_isleft: |
| 256 | return -1 |
| 257 | |
| 258 | _topside_istop = _aabb.mincorner.y < _y + _halfheight |
| 259 | _botside_istop = _aabb.mincorner.y + _aabb.height < _y + _halfheight |
| 260 | |
| 261 | if _topside_istop != _botside_istop: |
| 262 | return -1 |
| 263 | |
| 264 | _left = _leftside_isleft |
| 265 | _top = _topside_istop |
| 266 | |
| 267 | if _left: |
no outgoing calls