static Bitmap CoverPolygon(Bitmap original, Bitmap bmp, Point[] polygon, FilterInfo info) { int width = original.Size.Width; int height = original.Size.Height; PointF center = new Point(); Point lowerBounds = new Point(); Point upperBounds = new Point(); for (int i = 0; i < polygon.Length; ++i) { center.X += polygon[i].X; center.Y += polygon[i].Y; lowerBounds.X = Math.Min(lowerBounds.X, polygon[i].X); lowerBounds.Y = Math.Min(lowerBounds.Y, polygon[i].Y); upperBounds.X = Math.Max(upperBounds.X, polygon[i].X); upperBounds.Y = Math.Max(upperBounds.Y, polygon[i].Y); } center.X /= polygon.Length; center.Y /= polygon.Length; int[] minX = new int[height]; int[] maxX = new int[height]; for (int y = lowerBounds.Y; y <= upperBounds.Y; ++y) { Line2D row = new Line2D(0, 1, -y); minX[y] = width; maxX[y] = 0; for (int i = 0; i < polygon.Length; ++i) { Segment2D seg = new Segment2D(polygon[i], polygon[(i + 1) % polygon.Length]); Tuple <bool, PointF> res = seg.Intersect(row); if (res.Item1 == true) { //if (res.Item2.X <= center.X) minX[y] = (int)Math.Min(minX[y], res.Item2.X); //if (res.Item2.X >= center.X) maxX[y] = (int)Math.Max(maxX[y], res.Item2.X); } } } // THIS HAS TO GO SOMEWHERE ELSE //Graphics g = Graphics.FromImage(bmp); //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (info.type == FilterInfo.FilterType.solidColor) { //SolidBrush brush = new SolidBrush(info.color); //g.FillPolygon(brush, polygon); Fill(bmp, info.color, lowerBounds.Y, upperBounds.Y, minX, maxX); } else if (info.type == FilterInfo.FilterType.mean) { Color color = GetMean(original, lowerBounds.Y, upperBounds.Y, minX, maxX); //SolidBrush brush = new SolidBrush(color); //g.FillPolygon(brush, polygon); Fill(bmp, color, lowerBounds.Y, upperBounds.Y, minX, maxX); } return(bmp); }
public bool IsParalel(Line2D arg) { return(Math.Abs((-a / b) - (-arg.a / arg.b)) < EPS); }