/// <summary> /// Split a region into top, middle, and bottom sections. /// Split along points 1 & 2. /// If resulting rect has zero height it is omitted from the results. /// </summary> private static List <ImageComponent> SplitAlongY( int x, int y, int width, int height, int ySplit1, int ySplit2, TileBias xBias) { Contract.Requires(height != 0); Contract.Requires(ySplit1 >= y); Contract.Requires(ySplit2 >= y && ySplit2 > ySplit1); var split = new List <ImageComponent>(3); if (width == 0) { return(split); } // top if (ySplit1 - y > 0) { var top = new Rectangle(x, y, width, ySplit1 - y); split.Add(new ImageComponent(top, xBias, TileBias.Negative)); } // middle if (ySplit2 - ySplit1 > 0) { var middle = new Rectangle(x, ySplit1, width, ySplit2 - ySplit1); split.Add(new ImageComponent(middle, xBias, TileBias.Neutral)); } // bottom if (y + height - ySplit2 > 0) { var bottom = new Rectangle(x, ySplit2, width, y + height - ySplit2); split.Add(new ImageComponent(bottom, xBias, TileBias.Positive)); } return(split); }
public ImageComponent(Rectangle fragment, TileBias xBias, TileBias yBias) { this.Fragment = fragment; this.XBias = xBias; this.YBias = yBias; }