split - split the node into 4 subnodes
()
| 172 | |
| 173 | // split - split the node into 4 subnodes |
| 174 | func (qt *quadtreeNode) split() { |
| 175 | if qt.hasNodes { |
| 176 | return |
| 177 | } |
| 178 | qt.hasNodes = true |
| 179 | |
| 180 | nextLevel := qt.Level + 1 |
| 181 | subWidth := aabbWidth(qt.Bounds) / 2 |
| 182 | subHeight := aabbHeight(qt.Bounds) / 2 |
| 183 | x := qt.Bounds.Min.X |
| 184 | y := qt.Bounds.Min.Y |
| 185 | |
| 186 | //top right node (0) |
| 187 | qt.Nodes[0] = qt.Tree.newNode(aabbRect(x+subWidth, y, subWidth, subHeight), nextLevel) |
| 188 | |
| 189 | //top left node (1) |
| 190 | qt.Nodes[1] = qt.Tree.newNode(aabbRect(x, y, subWidth, subHeight), nextLevel) |
| 191 | |
| 192 | //bottom left node (2) |
| 193 | qt.Nodes[2] = qt.Tree.newNode(aabbRect(x, y+subHeight, subWidth, subHeight), nextLevel) |
| 194 | |
| 195 | //bottom right node (3) |
| 196 | qt.Nodes[3] = qt.Tree.newNode(aabbRect(x+subWidth, y+subHeight, subWidth, subHeight), nextLevel) |
| 197 | } |
| 198 | |
| 199 | func (qt *quadtreeNode) isEmpty() bool { |
| 200 | return len(qt.Objects) == 0 && !qt.hasNodes |
no test coverage detected