Merge branch 'quadtreefixes' into 'master'
quadtree fixes See merge request Timfa/frameworkv3!6
@@ -29,10 +29,11 @@ class QuadTree
29
29
*/
30
30
add (object)
31
31
{
32
const dirOfOob = this.outOfBounds(object);
33
if (dirOfOob)
32
let dirOfOob = this.outOfBounds(object);
33
while (dirOfOob)
34
34
{
35
35
this.embiggen(dirOfOob);
36
dirOfOob = this.outOfBounds(object);
36
37
}
37
38
38
39
if (!this.root.hasChildren)
@@ -249,7 +250,7 @@ class QuadTree
249
250
250
251
countObjectsInChild (parentNode)
251
252
{
252
if (!parentnode.hasChildren)
253
if (!parentNode.hasChildren)
253
254
{
254
255
return 0;
255
256
}
@@ -287,7 +288,7 @@ class QuadTree
287
288
return "L";
288
289
}
289
290
290
if (pos.x > this.root.x2 + this.root.x1)
291
if (pos.x > this.root.x2)
291
292
{
292
293
return "R";
293
294
}
@@ -297,7 +298,7 @@ class QuadTree
297
298
return "U";
298
299
}
299
300
300
if (pos.y > this.root.y2 + this.root.y1)
301
if (pos.y > this.root.y2)
301
302
{
302
303
return "D";
303
304
}
@@ -310,7 +311,7 @@ class Node
310
311
{
311
312
get canBeMerged ()
312
313
{
313
return !this.hasChildren && this.parent && this.parent.recursiveCount < this.quadTree.bucketSize;
314
return !this.hasChildren && this.parent && this.parent.recursiveCount <= this.quadTree.bucketSize;
314
315
}
315
316
316
317
get shouldSplit ()
@@ -534,32 +535,35 @@ class Node
534
535
535
536
if (nodePosition == "topleft")
536
537
{
537
parentNode = new Node(this.x1, this.y1, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);
538
parentNode = new Node(this.x1, this.y1, this.x1 + (this.lengthX * 2), this.y1 + (this.lengthY * 2), this.depth - 1, null, "", this.quadTree);
538
539
539
parentNode.topleft == this;
540
parentNode.topleft = this;
540
541
}
541
542
542
543
if (nodePosition == "topright")
543
544
{
544
parentNode = new Node(this.x1 - this.lengthX, this.y1, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);
545
parentNode = new Node(this.x1 - this.lengthX, this.y1, this.x1 + this.lengthX, this.y1 + (this.lengthY * 2), this.depth - 1, null, "", this.quadTree);
545
546
546
parentNode.topright == this;
547
parentNode.topright = this;
547
548
}
548
549
549
550
if (nodePosition == "bottomleft")
550
551
{
551
parentNode = new Node(this.x1, this.y1 - this.lengthY, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);
552
parentNode = new Node(this.x1, this.y1 - this.lengthY, this.x1 + (this.lengthX * 2), this.y1 + this.lengthY, this.depth - 1, null, "", this.quadTree);
552
553
553
parentNode.bottomleft == this;
554
parentNode.bottomleft = this;
554
555
}
555
556
556
557
if (nodePosition == "bottomright")
557
558
{
558
parentNode = new Node(this.x1 - this.lengthX, this.y1 - this.lengthY, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);
559
parentNode = new Node(this.x1 - this.lengthX, this.y1 - this.lengthY, this.x1 + this.lengthX, this.y1 + this.lengthY, this.depth - 1, null, "", this.quadTree);
559
560
560
parentNode.bottomright == this;
561
parentNode.bottomright = this;
561
562
}
562
563
564
this.parent = parentNode;
565
parentNode.recursiveCount = this.recursiveCount;
566
563
567
if (!parentNode.topleft)
564
568
{
565
569
parentNode.topleft = new Node(parentNode.x1, parentNode.y1, parentNode.x1 + parentNode.halfLengthX, parentNode.y1 + parentNode.halfLengthY, this.depth, parentNode, parentNode.name + 0, this.quadTree);
@@ -580,7 +584,7 @@ class Node
580
584
parentNode.bottomright = new Node(parentNode.x1 + parentNode.halfLengthX, parentNode.y1 + parentNode.halfLengthY, parentNode.x2, parentNode.y2, this.depth, parentNode, parentNode.name + 3, this.quadTree);
581
585
}
582
586
583
this.startReconfigureNames();
587
parentNode.reconfigureNames("");
584
588
return parentNode;
585
589
}
586
590
@@ -679,7 +683,7 @@ class Node
679
683
break;
680
684
}
681
685
682
return quadTree.traverseTo(name.join(""));
686
return this.quadTree.traverseTo(name.join(""));
683
687
}
684
688
685
689
show (ctx)
@@ -29,10 +29,11 @@ class QuadTree29
*/29
*/30
add (object)30
add (object)31
{31
{32
const dirOfOob = this.outOfBounds(object);32
let dirOfOob = this.outOfBounds(object);33
if (dirOfOob)33
while (dirOfOob)34
{34
{35
this.embiggen(dirOfOob);35
this.embiggen(dirOfOob);36
dirOfOob = this.outOfBounds(object);36
}37
}37
38
38
if (!this.root.hasChildren)39
if (!this.root.hasChildren)@@ -249,7 +250,7 @@ class QuadTree249
250
250
countObjectsInChild (parentNode)251
countObjectsInChild (parentNode)251
{252
{252
if (!parentnode.hasChildren)253
if (!parentNode.hasChildren)253
{254
{254
return 0;255
return 0;255
}256
}@@ -287,7 +288,7 @@ class QuadTree287
return "L";288
return "L";288
}289
}289
290
290
if (pos.x > this.root.x2 + this.root.x1)291
if (pos.x > this.root.x2)291
{292
{292
return "R";293
return "R";293
}294
}@@ -297,7 +298,7 @@ class QuadTree297
return "U";298
return "U";298
}299
}299
300
300
if (pos.y > this.root.y2 + this.root.y1)301
if (pos.y > this.root.y2)301
{302
{302
return "D";303
return "D";303
}304
}@@ -310,7 +311,7 @@ class Node310
{311
{311
get canBeMerged ()312
get canBeMerged ()312
{313
{313
return !this.hasChildren && this.parent && this.parent.recursiveCount < this.quadTree.bucketSize;314
return !this.hasChildren && this.parent && this.parent.recursiveCount <= this.quadTree.bucketSize;314
}315
}315
316
316
get shouldSplit ()317
get shouldSplit ()@@ -534,32 +535,35 @@ class Node534
535
535
if (nodePosition == "topleft")536
if (nodePosition == "topleft")536
{537
{537
parentNode = new Node(this.x1, this.y1, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);538
parentNode = new Node(this.x1, this.y1, this.x1 + (this.lengthX * 2), this.y1 + (this.lengthY * 2), this.depth - 1, null, "", this.quadTree);538
539
539
parentNode.topleft == this;540
parentNode.topleft = this;540
}541
}541
542
542
if (nodePosition == "topright")543
if (nodePosition == "topright")543
{544
{544
parentNode = new Node(this.x1 - this.lengthX, this.y1, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);545
parentNode = new Node(this.x1 - this.lengthX, this.y1, this.x1 + this.lengthX, this.y1 + (this.lengthY * 2), this.depth - 1, null, "", this.quadTree);545
546
546
parentNode.topright == this;547
parentNode.topright = this;547
}548
}548
549
549
if (nodePosition == "bottomleft")550
if (nodePosition == "bottomleft")550
{551
{551
parentNode = new Node(this.x1, this.y1 - this.lengthY, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);552
parentNode = new Node(this.x1, this.y1 - this.lengthY, this.x1 + (this.lengthX * 2), this.y1 + this.lengthY, this.depth - 1, null, "", this.quadTree);552
553
553
parentNode.bottomleft == this;554
parentNode.bottomleft = this;554
}555
}555
556
556
if (nodePosition == "bottomright")557
if (nodePosition == "bottomright")557
{558
{558
parentNode = new Node(this.x1 - this.lengthX, this.y1 - this.lengthY, this.lengthX * 2, this.lengthY * 2, this.depth - 1, null, "", this.quadTree);559
parentNode = new Node(this.x1 - this.lengthX, this.y1 - this.lengthY, this.x1 + this.lengthX, this.y1 + this.lengthY, this.depth - 1, null, "", this.quadTree);559
560
560
parentNode.bottomright == this;561
parentNode.bottomright = this;561
}562
}562
563
564
this.parent = parentNode;565
parentNode.recursiveCount = this.recursiveCount;566
563
if (!parentNode.topleft)567
if (!parentNode.topleft)564
{568
{565
parentNode.topleft = new Node(parentNode.x1, parentNode.y1, parentNode.x1 + parentNode.halfLengthX, parentNode.y1 + parentNode.halfLengthY, this.depth, parentNode, parentNode.name + 0, this.quadTree);569
parentNode.topleft = new Node(parentNode.x1, parentNode.y1, parentNode.x1 + parentNode.halfLengthX, parentNode.y1 + parentNode.halfLengthY, this.depth, parentNode, parentNode.name + 0, this.quadTree);@@ -580,7 +584,7 @@ class Node580
parentNode.bottomright = new Node(parentNode.x1 + parentNode.halfLengthX, parentNode.y1 + parentNode.halfLengthY, parentNode.x2, parentNode.y2, this.depth, parentNode, parentNode.name + 3, this.quadTree);584
parentNode.bottomright = new Node(parentNode.x1 + parentNode.halfLengthX, parentNode.y1 + parentNode.halfLengthY, parentNode.x2, parentNode.y2, this.depth, parentNode, parentNode.name + 3, this.quadTree);581
}585
}582
586
583
this.startReconfigureNames();587
parentNode.reconfigureNames("");584
return parentNode;588
return parentNode;585
}589
}586
590
@@ -679,7 +683,7 @@ class Node679
break;683
break;680
}684
}681
685
682
return quadTree.traverseTo(name.join(""));686
return this.quadTree.traverseTo(name.join(""));683
}687
}684
688
685
show (ctx)689
show (ctx)