/// <summary>
        /// Checks if the given 4 vertices form a rectangle
        /// </summary>
        /// <param name="vertices"></param>
        /// <returns></returns>
        public static bool IsRectangle(Vector2[] vertices, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException("vertices");
            }
            if (vertices.Count() != 4)
            {
                throw new ArgumentException("You must submit 4 vertices!");
            }

            var topLine    = new LineSegment2(vertices[0], vertices[1]).ToVector();
            var rightLine  = new LineSegment2(vertices[1], vertices[2]).ToVector();
            var bottomLine = new LineSegment2(vertices[2], vertices[3]).ToVector();
            var leftLine   = new LineSegment2(vertices[3], vertices[0]).ToVector();

            // Check that two lines have equal length

            if (Math.Abs(topLine.Length - bottomLine.Length) < tolerance &&
                Math.Abs(rightLine.Length - leftLine.Length) < tolerance)
            {
                // Now ensure that the lines are orthogonal on each other
                bool isRect = topLine.IsPerpendicularTo(rightLine, tolerance);
                isRect &= rightLine.IsPerpendicularTo(bottomLine, tolerance);
                isRect &= bottomLine.IsPerpendicularTo(leftLine, tolerance);

                return(isRect);
            }

            return(false);
        }
        /// <summary>
        /// Checks if the given 4 vertices form a rectangle
        /// </summary>
        /// <param name="vertices"></param>
        /// <returns></returns>
        public static bool IsRectangle(Vector2[] vertices, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            if (vertices == null) throw new ArgumentNullException("vertices");
            if (vertices.Count() != 4) throw new ArgumentException("You must submit 4 vertices!");

            var topLine = new LineSegment2(vertices[0], vertices[1]).ToVector();
            var rightLine = new LineSegment2(vertices[1], vertices[2]).ToVector();
            var bottomLine = new LineSegment2(vertices[2], vertices[3]).ToVector();
            var leftLine = new LineSegment2(vertices[3], vertices[0]).ToVector();

            // Check that two lines have equal length

            if (Math.Abs(topLine.Length - bottomLine.Length) < tolerance
                && Math.Abs(rightLine.Length - leftLine.Length) < tolerance)
            {
                // Now ensure that the lines are orthogonal on each other
                bool isRect = topLine.IsPerpendicularTo(rightLine, tolerance);
                isRect &= rightLine.IsPerpendicularTo(bottomLine, tolerance);
                isRect &= bottomLine.IsPerpendicularTo(leftLine, tolerance);

                return isRect;
            }

            return false;
        }