public override void OnMouseMove(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left || !this.IsSelected || isDrawn) { return; } var ptSecond = Element.ToImageCoordinate(e.Location).ToPt().Round(); roi = new RectangleF { X = System.Math.Min(ptFirst.X, ptSecond.X), Y = System.Math.Min(ptFirst.Y, ptSecond.Y), Width = System.Math.Abs(ptFirst.X - ptSecond.X), Height = System.Math.Abs(ptFirst.Y - ptSecond.Y) }; roi.Width = Math.Max(MIN_RECT_SIZE, roi.Width); roi.Height = Math.Max(MIN_RECT_SIZE, roi.Height); roi.Height = 1.2f * roi.Width; //fix width-height ratio var imageSize = Element.Image.Size.ToSize(); this.Annotation.Polygon = roi.Vertices().Select(x => x.Clamp(imageSize)).ToArray(); }
/// <summary> /// Truncate Shared Method /// </summary> /// /// <remarks> /// Produces a Rectangle structure from a RectangleF by /// truncating the X, Y, Width, and Height properties. /// </remarks> // LAMESPEC: Should this be floor, or a pure cast to int? public static Rectangle Truncate(RectangleF value) { int x, y, w, h; checked { x = (int)value.X; y = (int)value.Y; w = (int)value.Width; h = (int)value.Height; } return new Rectangle(x, y, w, h); }
private void drawPoints(Image<Bgr, byte> im, List<PointF> points) { foreach (var pt in points) { /*im[(int)pt.Y, (int)pt.X] = new Bgr(Color.Red); continue;*/ var rect = new RectangleF(pt.X, pt.Y, 1, 1); rect.Inflate(winSize / 2, winSize / 2); im.Draw(rect, System.Drawing.Color.Red.ToBgr(), 3); } }
/// <summary> /// Round Shared Method /// </summary> /// /// <remarks> /// Produces a Rectangle structure from a RectangleF by /// rounding the X, Y, Width, and Height properties. /// </remarks> public static Rectangle Round(RectangleF value) { int x, y, w, h; checked { x = (int)Math.Round(value.X); y = (int)Math.Round(value.Y); w = (int)Math.Round(value.Width); h = (int)Math.Round(value.Height); } return new Rectangle(x, y, w, h); }
/// <summary> /// IntersectsWith Method /// </summary> /// /// <remarks> /// Checks if a RectangleF intersects with this one. /// </remarks> public bool IntersectsWith(RectangleF rect) { return !((Left >= rect.Right) || (Right <= rect.Left) || (Top >= rect.Bottom) || (Bottom <= rect.Top)); }
private bool IntersectsWithInclusive(RectangleF r) { return !((Left > r.Right) || (Right < r.Left) || (Top > r.Bottom) || (Bottom < r.Top)); }
/// <summary> /// Intersect Method /// </summary> /// /// <remarks> /// Replaces the RectangleF with the intersection of itself /// and another RectangleF. /// </remarks> public void Intersect(RectangleF rect) { this = RectangleF.Intersect(this, rect); }
/// <summary> /// Contains Method /// </summary> /// /// <remarks> /// Checks if a RectangleF lies entirely within this /// RectangleF. /// </remarks> public bool Contains(RectangleF rect) { return (rect == Intersect(this, rect)); }
/// <summary> /// Union Shared Method /// </summary> /// /// <remarks> /// Produces a new RectangleF from the union of 2 existing /// RectangleFs. /// </remarks> public static RectangleF Union(RectangleF a, RectangleF b) { return FromLTRB(Math.Min(a.Left, b.Left), Math.Min(a.Top, b.Top), Math.Max(a.Right, b.Right), Math.Max(a.Bottom, b.Bottom)); }
/// <summary> /// Intersect Shared Method /// </summary> /// /// <remarks> /// Produces a new RectangleF by intersecting 2 existing /// RectangleFs. Returns null if there is no intersection. /// </remarks> public static RectangleF Intersect(RectangleF a, RectangleF b) { // MS.NET returns a non-empty rectangle if the two rectangles // touch each other if (!a.IntersectsWithInclusive(b)) return Empty; return FromLTRB( Math.Max(a.Left, b.Left), Math.Max(a.Top, b.Top), Math.Min(a.Right, b.Right), Math.Min(a.Bottom, b.Bottom)); }
/// <summary> /// Inflate Shared Method /// </summary> /// /// <remarks> /// Produces a new RectangleF by inflating an existing /// RectangleF by the specified coordinate values. /// </remarks> public static RectangleF Inflate(RectangleF rect, float x, float y) { RectangleF ir = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height); ir.Inflate(x, y); return ir; }