private Bolt GenerateBolt(Bolt parent, BranchType type, Rectangle bounds) { lock (this._LockObject) { var newBolt = new Bolt(parent); int startX, startY; //generate start coords if (parent == null) { startY = 0; startX = this._Generator.Next(bounds.X, bounds.X + bounds.Width); newBolt.Color = Color.FromArgb(this._Generator.Next(255), this._Generator.Next(255), this._Generator.Next(255));; } else { //base all settings on parent startY = parent.EndPosition.Y; startX = parent.EndPosition.X; } var endY = this._Generator.Next(bounds.Y, bounds.Y + bounds.Height); var endX = this._Generator.Next(bounds.X, bounds.X + bounds.Width); if (endY > this._View.Size.Height - this._SnapToBottom) { endY = this._View.Size.Height; } newBolt.StartPosition = new Point(startX, startY); newBolt.EndPosition = new Point(endX, endY); //generate child bolts if necessary if (newBolt.EndPosition.Y >= this._View.Size.Height) { return(newBolt); } var side = this._Generator.Next(3); switch (side) { case 0: newBolt.LeftChild = this.GenerateBolt(newBolt, BranchType.Left, new Rectangle(bounds.X, endY, endX - bounds.X, this._View.Size.Height - endY)); break; case 1: newBolt.RightChild = this.GenerateBolt(newBolt, BranchType.Right, new Rectangle(endX, endY, bounds.X + bounds.Width - endX, this._View.Size.Height - endY)); break; case 2: newBolt.LeftChild = this.GenerateBolt(newBolt, BranchType.Left, new Rectangle(bounds.X, endY, endX - bounds.X, this._View.Size.Height - endY)); newBolt.RightChild = this.GenerateBolt(newBolt, BranchType.Right, new Rectangle(endX, endY, bounds.X + bounds.Width - endX, this._View.Size.Height - endY)); break; } return(newBolt); } }
public Bolt(Bolt parent) { this.Parent = parent; }