private void UpdateViewBounds() { try { UpdateGraphBounds(); if (fViewBounds == null) { fViewBounds = fGraphBounds; return; } ArborPoint vLT = fGraphBounds.LeftTop.Sub(fViewBounds.LeftTop).Mul(Mag); ArborPoint vRB = fGraphBounds.RightBottom.Sub(fViewBounds.RightBottom).Mul(Mag); double aX = vLT.Magnitude() * fViewWidth; double aY = vRB.Magnitude() * fViewHeight; if (aX > 1.0f || aY > 1.0f) { ArborPoint nbLT = fViewBounds.LeftTop.Add(vLT); ArborPoint nbRB = fViewBounds.RightBottom.Add(vRB); fViewBounds = new PSBounds(nbLT, nbRB); } } catch (Exception ex) { Debug.WriteLine("ArborSystem.UpdateViewBounds(): " + ex.Message); } }
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); }