public static bool LineContainsPoint(double x1, double y1, double x2, double y2, double px, double py) { RectangleD r = new RectangleD(new PointD(x1, y1)); r.Add(x2, y2); r.Inflate(2.0, 2.0); if (!r.Contains(px, py)) { return(false); } double a, b, x, y; if (x1 == x2) { return(Math.Abs(px - x1) < 3.0); } if (y1 == y2) { return(Math.Abs(py - y1) < 3.0); } a = (y1 - y2) / (x1 - x2); b = y1 - a * x1; x = (py - b) / a; y = a * px + b; return(Math.Min(Math.Abs(x - px), Math.Abs(y - py)) < 4.0); }
public static bool RectangleInsideGdkRegion(RectangleD r, Gdk.Region region) { r.Inflate(1.0, 1.0); Gdk.Rectangle gdkRect = GdkRectangle(r); Gdk.OverlapType type = region.RectIn(gdkRect); return(type == Gdk.OverlapType.In || type == Gdk.OverlapType.Part); }