| 161 | * Split the node into 4 subnodes |
| 162 | */ |
| 163 | split() { |
| 164 | const nextLevel = this.level + 1; |
| 165 | const subWidth = this.bounds.width / 2; |
| 166 | const subHeight = this.bounds.height / 2; |
| 167 | const left = this.bounds.left; |
| 168 | const top = this.bounds.top; |
| 169 | |
| 170 | //top right node |
| 171 | this.nodes[0] = QT_ARRAY_POP( |
| 172 | this.world, |
| 173 | { |
| 174 | left: left + subWidth, |
| 175 | top: top, |
| 176 | width: subWidth, |
| 177 | height: subHeight, |
| 178 | }, |
| 179 | this.max_objects, |
| 180 | this.max_levels, |
| 181 | nextLevel, |
| 182 | ); |
| 183 | |
| 184 | //top left node |
| 185 | this.nodes[1] = QT_ARRAY_POP( |
| 186 | this.world, |
| 187 | { |
| 188 | left: left, |
| 189 | top: top, |
| 190 | width: subWidth, |
| 191 | height: subHeight, |
| 192 | }, |
| 193 | this.max_objects, |
| 194 | this.max_levels, |
| 195 | nextLevel, |
| 196 | ); |
| 197 | |
| 198 | //bottom left node |
| 199 | this.nodes[2] = QT_ARRAY_POP( |
| 200 | this.world, |
| 201 | { |
| 202 | left: left, |
| 203 | top: top + subHeight, |
| 204 | width: subWidth, |
| 205 | height: subHeight, |
| 206 | }, |
| 207 | this.max_objects, |
| 208 | this.max_levels, |
| 209 | nextLevel, |
| 210 | ); |
| 211 | |
| 212 | //bottom right node |
| 213 | this.nodes[3] = QT_ARRAY_POP( |
| 214 | this.world, |
| 215 | { |
| 216 | left: left + subWidth, |
| 217 | top: top + subHeight, |
| 218 | width: subWidth, |
| 219 | height: subHeight, |
| 220 | }, |