public ArborNode GetNearestNode(int viewX, int viewY) { ArborPoint pt = GetModelCoords(viewX, viewY); ArborNode result = null; double minDist = +1.0f; for (int i = 0, nodesCount = fNodes.Count; i < nodesCount; i++) { ArborNode node = fNodes[i]; ArborPoint nodePt = node.Pt; if (nodePt.IsExploded()) { continue; } double dist = nodePt.Sub(pt).Magnitude(); if (dist < minDist) { result = node; minDist = dist; } } return(result); }
public void Test_IsExploded() { var pt = new ArborPoint(double.NaN, 4); Assert.IsTrue(pt.IsExploded()); pt = new ArborPoint(3, 4); Assert.IsFalse(pt.IsExploded()); }
private void UpdateGraphBounds() { ArborPoint lt = new ArborPoint(-1.0f, -1.0f); ArborPoint rb = new ArborPoint(+1.0f, +1.0f); for (int i = 0, nodesCount = fNodes.Count; i < nodesCount; i++) { ArborPoint pt = fNodes[i].Pt; if (pt.IsExploded()) { continue; } if (pt.X < lt.X) { lt.X = pt.X; } if (pt.Y < lt.Y) { lt.Y = pt.Y; } if (pt.X > rb.X) { rb.X = pt.X; } if (pt.Y > rb.Y) { rb.Y = pt.Y; } } lt.X -= 1.2f; lt.Y -= 1.2f; rb.X += 1.2f; rb.Y += 1.2f; ArborPoint sz = rb.Sub(lt); ArborPoint cent = lt.Add(sz.Div(2.0f)); ArborPoint d = new ArborPoint(Math.Max(sz.X, 4.0f), Math.Max(sz.Y, 4.0f)).Div(2.0f); fGraphBounds = new PSBounds(cent.Sub(d), cent.Add(d)); fBHTree = new BarnesHutTree(fGraphBounds.LeftTop, fGraphBounds.RightBottom, Theta); }