/// <summary> /// Returns the distance from this to the other rect. 0 if there is an overlap. /// </summary> /// <param name="Other">Other rectangle.</param> public double Distance(C2DRect Other) { if (this.Overlaps(Other)) { return(0); } if (Other.GetLeft() > this.BottomRight.x) { // Other is to the right if (Other.GetBottom() > this.TopLeft.y) { // Other is to the top right C2DPoint ptTopRight = new C2DPoint(BottomRight.x, TopLeft.y); return(ptTopRight.Distance(new C2DPoint(Other.GetLeft(), Other.GetBottom()))); } else if (Other.GetTop() < this.BottomRight.y) { // Other to the bottom right return(BottomRight.Distance(Other.TopLeft)); } else { // to the right return(Other.GetLeft() - this.BottomRight.x); } } else if (Other.GetRight() < this.TopLeft.x) { // Other to the left if (Other.GetBottom() > this.TopLeft.y) { // Other is to the top left return(TopLeft.Distance(Other.BottomRight)); } else if (Other.GetTop() < this.BottomRight.y) { // Other to the bottom left C2DPoint ptBottomLeft = new C2DPoint(TopLeft.x, BottomRight.y); return(ptBottomLeft.Distance(new C2DPoint(Other.GetRight(), Other.GetTop()))); } else { //Just to the left return(this.TopLeft.x - Other.GetRight()); } } else { // There is horizontal overlap; if (Other.GetBottom() > TopLeft.y) { return(Other.GetBottom() - TopLeft.y); } else { return(BottomRight.y - Other.GetTop()); } } }
/// <summary> /// True if the entire other rectangle is within. /// </summary> /// <param name="Other">Other rectangle.</param> public bool Contains(C2DRect Other) { return(Other.GetLeft() > TopLeft.x && Other.GetRight() < BottomRight.x && Other.GetBottom() > BottomRight.y && Other.GetTop() < TopLeft.y); }
/// <summary> /// True if there is an overlap. /// </summary> /// <param name="Other">Other rectangle.</param> public bool Overlaps(C2DRect Other) { bool bOvX = !(Other.GetLeft() >= BottomRight.x || Other.GetRight() <= TopLeft.x); bool bOvY = !(Other.GetBottom() >= TopLeft.y || Other.GetTop() <= BottomRight.y); return(bOvX && bOvY); }
/// <summary> /// True if this is above the other. /// </summary> /// <param name="Other"></param> /// <returns></returns> public bool OverlapsAbove(C2DRect Other) { if (Other.GetLeft() >= BottomRight.x || Other.GetRight() <= TopLeft.x) { return(false); } else { return(TopLeft.y > Other.GetBottom()); } }
/// <summary> /// Returns the projection of this onto the vector provided, given as the interval on /// (or off) the vector. Interval given as distance from the start of the vector. /// The vector is equivalent to a line from (0, 0). /// </summary> /// <param name="Vector">The projection vector.</param> /// <param name="Interval">The interval to recieve the result.</param> public override void Project(C2DVector Vector, CInterval Interval) { C2DArc ThisCopy = new C2DArc(this); C2DVector VecCopy = new C2DVector(Vector); double dAng = VecCopy.AngleFromNorth(); VecCopy.TurnLeft(dAng); ThisCopy.RotateToRight(-dAng, new C2DPoint(0, 0)); C2DRect rect = new C2DRect(); ThisCopy.GetBoundingRect(rect); Interval.dMax = rect.GetTop() - VecCopy.j; Interval.dMin = Interval.dMax; Interval.ExpandToInclude(rect.GetBottom() - VecCopy.j); }
/// <summary> /// Returns the projection of this onto the line provided, given as the interval on /// (or off) the line. Interval given as distance from the start of the line. /// </summary> /// <param name="TestLine">The projection line.</param> /// <param name="Interval">The interval to recieve the result.</param> public override void Project(C2DLine TestLine, CInterval Interval) { C2DArc ThisCopy = new C2DArc(this); C2DLine LineCopy = new C2DLine(TestLine); double dAng = LineCopy.vector.AngleFromNorth(); LineCopy.vector.TurnLeft(dAng); ThisCopy.RotateToRight(-dAng, LineCopy.point); C2DRect rect = new C2DRect(); ThisCopy.GetBoundingRect(rect); Interval.dMax = rect.GetTop() - LineCopy.point.y; Interval.dMin = Interval.dMax; Interval.ExpandToInclude(rect.GetBottom() - LineCopy.point.y); }
/// <summary> /// True if this is above the other. /// </summary> /// <param name="Other"></param> /// <returns></returns> public bool OverlapsAbove( C2DRect Other) { if (Other.GetLeft() >= BottomRight.x || Other.GetRight() <= TopLeft.x) { return false; } else { return TopLeft.y > Other.GetBottom(); } }
/// <summary> /// Returns the distance from this to the other rect. 0 if there is an overlap. /// </summary> /// <param name="Other">Other rectangle.</param> public double Distance(C2DRect Other) { if (this.Overlaps(Other)) return 0; if (Other.GetLeft() > this.BottomRight.x) { // Other is to the right if (Other.GetBottom() > this.TopLeft.y) { // Other is to the top right C2DPoint ptTopRight = new C2DPoint(BottomRight.x, TopLeft.y); return ptTopRight.Distance(new C2DPoint(Other.GetLeft(), Other.GetBottom())); } else if (Other.GetTop() < this.BottomRight.y) { // Other to the bottom right return BottomRight.Distance( Other.TopLeft ); } else { // to the right return Other.GetLeft() - this.BottomRight.x; } } else if ( Other.GetRight() < this.TopLeft.x) { // Other to the left if (Other.GetBottom() > this.TopLeft.y) { // Other is to the top left return TopLeft.Distance(Other.BottomRight); } else if (Other.GetTop() < this.BottomRight.y) { // Other to the bottom left C2DPoint ptBottomLeft = new C2DPoint(TopLeft.x, BottomRight.y); return ptBottomLeft.Distance ( new C2DPoint( Other.GetRight(), Other.GetTop())); } else { //Just to the left return (this.TopLeft.x - Other.GetRight()); } } else { // There is horizontal overlap; if (Other.GetBottom() > TopLeft.y) return Other.GetBottom() - TopLeft.y; else return BottomRight.y - Other.GetTop(); } }
/// <summary> /// True if there is an overlap. /// </summary> /// <param name="Other">Other rectangle.</param> public bool Overlaps(C2DRect Other) { bool bOvX = !(Other.GetLeft() >= BottomRight.x || Other.GetRight() <= TopLeft.x); bool bOvY = !(Other.GetBottom() >= TopLeft.y || Other.GetTop() <= BottomRight.y); return bOvX && bOvY; }
/// <summary> /// True if the entire other rectangle is within. /// </summary> /// <param name="Other">Other rectangle.</param> public bool Contains(C2DRect Other) { return (Other.GetLeft() > TopLeft.x && Other.GetRight() < BottomRight.x && Other.GetBottom() > BottomRight.y && Other.GetTop() < TopLeft.y); }
/// <summary> /// Returns the projection of this onto the vector provided, given as the interval on /// (or off) the vector. Interval given as distance from the start of the vector. /// The vector is equivalent to a line from (0, 0). /// </summary> /// <param name="Vector">The projection vector.</param> /// <param name="Interval">The interval to recieve the result.</param> public override void Project(C2DVector Vector, CInterval Interval) { C2DArc ThisCopy = new C2DArc(this); C2DVector VecCopy = new C2DVector(Vector); double dAng = VecCopy.AngleFromNorth(); VecCopy.TurnLeft(dAng); ThisCopy.RotateToRight( -dAng, new C2DPoint(0, 0)); C2DRect rect = new C2DRect(); ThisCopy.GetBoundingRect( rect); Interval.dMax = rect.GetTop() - VecCopy.j; Interval.dMin = Interval.dMax; Interval.ExpandToInclude( rect.GetBottom() - VecCopy.j ); }
/// <summary> /// Returns the projection of this onto the line provided, given as the interval on /// (or off) the line. Interval given as distance from the start of the line. /// </summary> /// <param name="TestLine">The projection line.</param> /// <param name="Interval">The interval to recieve the result.</param> public override void Project(C2DLine TestLine, CInterval Interval) { C2DArc ThisCopy = new C2DArc(this); C2DLine LineCopy = new C2DLine(TestLine); double dAng = LineCopy.vector.AngleFromNorth(); LineCopy.vector.TurnLeft(dAng); ThisCopy.RotateToRight( -dAng, LineCopy.point); C2DRect rect = new C2DRect(); ThisCopy.GetBoundingRect( rect); Interval.dMax = rect.GetTop() - LineCopy.point.y; Interval.dMin = Interval.dMax; Interval.ExpandToInclude(rect.GetBottom() - LineCopy.point.y); }