/// <summary> /// Returns true if this rectangle overlaps with the given box. /// </summary> /// <param name="box">Box.</param> public bool Overlaps(BoxF2D box) { // Yes, I know this code can be shorter but it would turn into a mess! if (box.Contains(this.BottomLeft) || box.Contains(this.BottomRight) || box.Contains(this.TopLeft) || box.Contains(this.TopRight)) { return(true); } if (this.Contains(box.Corners [0]) || this.Contains(box.Corners [2]) || this.Contains(box.Corners [3]) || this.Contains(box.Corners [0])) { return(true); } List <LineF2D> lines = new List <LineF2D> (); lines.Add(new LineF2D(this.BottomLeft, this.BottomRight, true)); lines.Add(new LineF2D(this.BottomRight, this.TopRight, true)); lines.Add(new LineF2D(this.TopRight, this.TopLeft, true)); lines.Add(new LineF2D(this.TopLeft, this.BottomLeft, true)); foreach (LineF2D line in (box as IEnumerable <LineF2D>)) { foreach (LineF2D otherLine in lines) { if (line.Intersects(otherLine)) { return(true); } } } return(false); }
/// <summary> /// Calculates the union of this box and the given box or the box that encompasses both original boxes. /// </summary> /// <param name="box">Box.</param> public BoxF2D Union(BoxF2D box) { // get the lowest minimums and the highest maximums. double minX = System.Math.Min(this.Min[0], box.Min[0]); double minY = System.Math.Min(this.Min[1], box.Min[1]); double maxX = System.Math.Max(this.Max[0], box.Max[0]); double maxY = System.Math.Max(this.Max[1], box.Max[1]); return(new BoxF2D(new PointF2D(minX, minY), new PointF2D(maxX, maxY))); }
public BoxF2D Union(BoxF2D box) { double x1 = System.Math.Min(this.Min[0], box.Min[0]); double num = System.Math.Min(this.Min[1], box.Min[1]); double x2 = System.Math.Max(this.Max[0], box.Max[0]); double y1 = System.Math.Max(this.Max[1], box.Max[1]); double y2 = num; return(new BoxF2D(new PointF2D(x1, y2), new PointF2D(x2, y1))); }
public bool Overlaps(BoxF2D box) { double num1 = System.Math.Max(this.Min[0], box.Min[0]); double num2 = System.Math.Max(this.Min[1], box.Min[1]); double num3 = System.Math.Min(this.Max[0], box.Max[0]); double num4 = System.Math.Min(this.Max[1], box.Max[1]); double num5 = num3; return(num1 <= num5 && num2 <= num4); }
public bool Contains(BoxF2D box) { foreach (PointF2D corner in box.Corners) { if (!this.Contains(corner)) { return(false); } } return(true); }
/// <summary> /// Returns true if the given box is completely inside this box. /// </summary> /// <param name="box"></param> /// <returns></returns> public bool IsInside(BoxF2D box) { foreach (PointF2D p in box.Corners) { if (!this.IsInside(p)) { return(false); } } return(true); }
/// <summary> /// Calculates the intersection between this box and the given box. /// </summary> /// <param name="box">Box.</param> public BoxF2D Intersection(BoxF2D box) { // get the highest minimums and the lowest maximums. double minX = System.Math.Max(this.Min[0], box.Min[0]); double minY = System.Math.Max(this.Min[1], box.Min[1]); double maxX = System.Math.Min(this.Max[0], box.Max[0]); double maxY = System.Math.Min(this.Max[1], box.Max[1]); if (minX <= maxX && minY <= maxY) { return(new BoxF2D(new PointF2D(minX, minY), new PointF2D(maxX, maxY))); } return(null); }
/// <summary> /// Returns true if the boxes overlap. /// </summary> /// <param name="box"></param> /// <returns></returns> public bool Overlaps(BoxF2D box) { double minX = System.Math.Max(this.Min[0], box.Min[0]); double minY = System.Math.Max(this.Min[1], box.Min[1]); double maxX = System.Math.Min(this.Max[0], box.Max[0]); double maxY = System.Math.Min(this.Max[1], box.Max[1]); if (minX <= maxX && minY <= maxY) { return(true); } return(false); }
public BoxF2D Intersection(BoxF2D box) { double x1 = System.Math.Max(this.Min[0], box.Min[0]); double y1 = System.Math.Max(this.Min[1], box.Min[1]); double x2 = System.Math.Min(this.Max[0], box.Max[0]); double y2 = System.Math.Min(this.Max[1], box.Max[1]); if (x1 <= x2 && y1 <= y2) { return(new BoxF2D(new PointF2D(x1, y1), new PointF2D(x2, y2))); } return((BoxF2D)null); }
public bool Overlaps(BoxF2D box) { if (box.Contains(this.BottomLeft) || box.Contains(this.BottomRight) || (box.Contains(this.TopLeft) || box.Contains(this.TopRight)) || (this.Contains(box.Corners[0]) || this.Contains(box.Corners[2]) || (this.Contains(box.Corners[3]) || this.Contains(box.Corners[0])))) { return(true); } List <LineF2D> lineF2DList = new List <LineF2D>(); lineF2DList.Add(new LineF2D(this.BottomLeft, this.BottomRight, true)); lineF2DList.Add(new LineF2D(this.BottomRight, this.TopRight, true)); lineF2DList.Add(new LineF2D(this.TopRight, this.TopLeft, true)); lineF2DList.Add(new LineF2D(this.TopLeft, this.BottomLeft, true)); foreach (LineF2D lineF2D in (IEnumerable <LineF2D>)box) { foreach (LineF2D line in lineF2DList) { if (lineF2D.Intersects(line)) { return(true); } } } return(false); }