public static CgmRectangle GetRectangle(Polyline polyline) { if (IsRectangle(polyline)) { var points = polyline.Points; // rectangle is descriped counter clock-wise starting right if (CgmPoint.IsSame(points[0].Y, points[1].Y) && CgmPoint.IsSame(points[1].X, points[2].X) && CgmPoint.IsSame(points[2].Y, points[3].Y)) { if (points[1].Y < points[2].Y) { return(CgmRectangle.FromPoints(points[1], points[0], points[2], points[3])); } else if (points[0].X < points[1].X) // starting left { return(CgmRectangle.FromPoints(points[3], points[2], points[0], points[1])); } else { return(CgmRectangle.FromPoints(points[2], points[3], points[1], points[0])); } } // rectangle is described clock wise if (CgmPoint.IsSame(points[0].X, points[1].X) && CgmPoint.IsSame(points[1].Y, points[2].Y) && CgmPoint.IsSame(points[2].X, points[3].X)) { return(CgmRectangle.FromPoints(points[4], points[0], points[3], points[1])); } } return(CgmRectangle.Empty); }
public CgmRectangle ToRectangle() { return(CgmRectangle.FromPoints(_topLine.A, _topLine.B, _leftLowerCorner, _rightLowerCorner)); }
/// <summary> /// Determines whether point A is near point b /// </summary> /// <param name="pointA">The start point.</param> /// <param name="pointWithinRange">The point with have to be within the range of the start point.</param> /// <param name="rangeDistance">The range distance.</param> public static bool IsNearBy(CgmPoint pointA, CgmPoint pointWithinRange, float rangeDistance) { var rect = new CgmRectangle((float)pointA.X - rangeDistance, (float)pointA.Y - rangeDistance, rangeDistance * 2, rangeDistance * 2); return(rect.Contains(pointWithinRange)); }