X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.debug.graphical%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fgraphical%2Flayout%2FBarnesHut.java;h=ef54c25f7105b8efc108057f13271ff5afc24470;hb=refs%2Fchanges%2F38%2F238%2F2;hp=caf097cf5b741f37e1c71bece7b143277ce9e04c;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/BarnesHut.java b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/BarnesHut.java index caf097cf5..ef54c25f7 100644 --- a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/BarnesHut.java +++ b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/BarnesHut.java @@ -1,139 +1,139 @@ -package org.simantics.debug.graphical.layout; - -public class BarnesHut { - - static class Bounds { - final double minX; - final double minY; - final double maxX; - final double maxY; - - public Bounds(double minX, double minY, double maxX, double maxY) { - this.minX = minX; - this.minY = minY; - this.maxX = maxX; - this.maxY = maxY; - } - } - - private static Bounds computeOctreeBounds(double[] posX, double[] posY) { - double minX = posX[0]; - double minY = posY[0]; - double maxX = posX[0]; - double maxY = posY[0]; - - for(int i=1;i maxX) - maxX = x; - if(y < minY) - minY = y; - else if(y > maxY) - maxY = y; - } - - double diff = (maxX - minX) - (maxY - minY); - diff *= 0.5; - if(diff > 0.0) { - minY -= diff; - maxY += diff; - } - else { - minX += diff; - maxX -= diff; - } - return new Bounds(minX, minY, maxX, maxY); - } - - private static class VecRef { - double x; - double y; - } - - /*private static void force(VecRef f, double x1, double y1, double x2, double y2) { - double dx = x2 - x1; - double dy = y2 - y1; - double l2 = dx*dx + dy*dy; - double s = Q / l2; - f.x -= s * dx; - f.y -= s * dy; - } - - private static void forceNear(VecRef f, double x1, double y1, OctreeNode node, double[] posX, double[] posY) { - if(node instanceof OctreeLeaf) { - for(int id : ((OctreeLeaf)node).ids) { - force(f, x1, y1, posX[id], posY[id]); - } - } - else { - OctreeInnerNode inner = (OctreeInnerNode)node; - forceNear(f, x1, y1, inner.n00, posX, posY); - forceNear(f, x1, y1, inner.n10, posX, posY); - forceNear(f, x1, y1, inner.n01, posX, posY); - forceNear(f, x1, y1, inner.n11, posX, posY); - } - } - - private static void forceFar(VecRef f, double x1, double y1, OctreeNode node) { - double dx = node.massCenterX - x1; - double dy = node.massCenterY - y1; - double l2 = dx*dx + dy*dy; - double s = Q * node.mass / l2; - f.x -= s * dx; - f.y -= s * dy; - } - - private static void computeForce(OctreeNode octree, - ArrayList farNodes, - ArrayList nearNodes, - double[] posX, double[] posY, - double[] forceX, double[] forceY) { - VecRef f = new VecRef(); - if(octree instanceof OctreeLeaf) { - int[] ids = ((OctreeLeaf)octree).ids; - for(int i=0;i(), new ArrayList(), posX, posY, forceX, forceY); - }*/ - -} +package org.simantics.debug.graphical.layout; + +public class BarnesHut { + + static class Bounds { + final double minX; + final double minY; + final double maxX; + final double maxY; + + public Bounds(double minX, double minY, double maxX, double maxY) { + this.minX = minX; + this.minY = minY; + this.maxX = maxX; + this.maxY = maxY; + } + } + + private static Bounds computeOctreeBounds(double[] posX, double[] posY) { + double minX = posX[0]; + double minY = posY[0]; + double maxX = posX[0]; + double maxY = posY[0]; + + for(int i=1;i maxX) + maxX = x; + if(y < minY) + minY = y; + else if(y > maxY) + maxY = y; + } + + double diff = (maxX - minX) - (maxY - minY); + diff *= 0.5; + if(diff > 0.0) { + minY -= diff; + maxY += diff; + } + else { + minX += diff; + maxX -= diff; + } + return new Bounds(minX, minY, maxX, maxY); + } + + private static class VecRef { + double x; + double y; + } + + /*private static void force(VecRef f, double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + double l2 = dx*dx + dy*dy; + double s = Q / l2; + f.x -= s * dx; + f.y -= s * dy; + } + + private static void forceNear(VecRef f, double x1, double y1, OctreeNode node, double[] posX, double[] posY) { + if(node instanceof OctreeLeaf) { + for(int id : ((OctreeLeaf)node).ids) { + force(f, x1, y1, posX[id], posY[id]); + } + } + else { + OctreeInnerNode inner = (OctreeInnerNode)node; + forceNear(f, x1, y1, inner.n00, posX, posY); + forceNear(f, x1, y1, inner.n10, posX, posY); + forceNear(f, x1, y1, inner.n01, posX, posY); + forceNear(f, x1, y1, inner.n11, posX, posY); + } + } + + private static void forceFar(VecRef f, double x1, double y1, OctreeNode node) { + double dx = node.massCenterX - x1; + double dy = node.massCenterY - y1; + double l2 = dx*dx + dy*dy; + double s = Q * node.mass / l2; + f.x -= s * dx; + f.y -= s * dy; + } + + private static void computeForce(OctreeNode octree, + ArrayList farNodes, + ArrayList nearNodes, + double[] posX, double[] posY, + double[] forceX, double[] forceY) { + VecRef f = new VecRef(); + if(octree instanceof OctreeLeaf) { + int[] ids = ((OctreeLeaf)octree).ids; + for(int i=0;i(), new ArrayList(), posX, posY, forceX, forceY); + }*/ + +}