Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
4e81f4b3cd |
@ -51,6 +51,12 @@ public class Octree {
|
|||||||
if (root == null) return;
|
if (root == null) return;
|
||||||
root.draw(cd);
|
root.draw(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfBalancedRegions() {
|
||||||
|
if (root == null || !(root instanceof OctreeNode r)) return 0;
|
||||||
|
|
||||||
|
return r.getNumberOfBalancedRegions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class OctreeItem {
|
abstract class OctreeItem {
|
||||||
@ -149,6 +155,26 @@ class OctreeNode extends OctreeItem {
|
|||||||
((octNum & 4) != 0) ? -1 : 1)
|
((octNum & 4) != 0) ? -1 : 1)
|
||||||
.times(this.size / 4));
|
.times(this.size / 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isBalanced() {
|
||||||
|
for (OctreeItem i : children) {
|
||||||
|
if (!(i instanceof OctreeLeaf))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getNumberOfBalancedRegions() {
|
||||||
|
if (isBalanced()) return 1;
|
||||||
|
|
||||||
|
int c = 0;
|
||||||
|
for (OctreeItem i : children) {
|
||||||
|
if (i instanceof OctreeNode n) {
|
||||||
|
c += n.getNumberOfBalancedRegions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OctreeLeaf extends OctreeItem {
|
class OctreeLeaf extends OctreeItem {
|
||||||
|
@ -55,6 +55,7 @@ public class Simulation {
|
|||||||
for (Body body : bodies) {
|
for (Body body : bodies) {
|
||||||
octree.add(body);
|
octree.add(body);
|
||||||
}
|
}
|
||||||
|
System.out.println(octree.getNumberOfBalancedRegions());
|
||||||
octree.applyForces(bodies, 100);
|
octree.applyForces(bodies, 100);
|
||||||
|
|
||||||
if ((seconds % 60) == 0) {
|
if ((seconds % 60) == 0) {
|
||||||
|
Reference in New Issue
Block a user