Example #1
0
        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);
        }
Example #2
0
 public CgmRectangle ToRectangle()
 {
     return(CgmRectangle.FromPoints(_topLine.A, _topLine.B, _leftLowerCorner, _rightLowerCorner));
 }