/// <summary> /// Determines the boundaries of the grids non-null content. /// </summary> /// <returns></returns> public Rectangle GetContentBoundaries() { Rectangle bounds = new Rectangle(this.width, this.height, 0, 0); int count = this.sequence.Count; T[] data = this.sequence.Data; for (int i = 0; i < count; i++) { if (GenericOperator.Equal(data[i], default(T))) { continue; } int cX = i % this.width; int cY = i / this.width; bounds.X = Math.Min(bounds.X, cX); bounds.Y = Math.Min(bounds.Y, cY); bounds.Width = Math.Max(bounds.Width, cX); bounds.Height = Math.Max(bounds.Height, cY); } bounds.Width = 1 + Math.Max(0, bounds.Width - bounds.X); bounds.Height = 1 + Math.Max(0, bounds.Height - bounds.Y); return(bounds); }
/// <summary> /// Determines the boundaries of the grids non-null content. /// </summary> /// <returns></returns> public void GetContentBoundaries(out Point2 topLeft, out Point2 size) { topLeft = new Point2(this.width, this.height); size = new Point2(0, 0); int count = this.sequence.Count; T[] data = this.sequence.Data; for (int i = 0; i < count; i++) { if (GenericOperator.Equal(data[i], default(T))) { continue; } int cX = i % this.width; int cY = i / this.width; topLeft.X = Math.Min(topLeft.X, cX); topLeft.Y = Math.Min(topLeft.Y, cY); size.X = Math.Max(size.X, cX); size.Y = Math.Max(size.Y, cY); } size.X = 1 + Math.Max(0, size.X - topLeft.X); size.Y = 1 + Math.Max(0, size.Y - topLeft.Y); }