/// <summary>
        /// Returns a deep copy of this collection.
        /// </summary>
        /// <returns>The copied object.</returns>
        public object Clone()
        {
            CoordinateList copy = new CoordinateList();

            foreach (var c in this)
            {
                copy.Add(c.Copy());
            }
            return(copy);
        }
        /// <summary>
        /// If the coordinate array argument has repeated points,
        /// constructs a new array containing no repeated points.
        /// Otherwise, returns the argument.
        /// </summary>
        /// <param name="coord"></param>
        /// <returns></returns>
        public static Coordinate[] RemoveRepeatedPoints(Coordinate[] coord)
        {
            if (!HasRepeatedPoints(coord))
            {
                return(coord);
            }
            CoordinateList coordList = new CoordinateList(coord, false);

            return(coordList.ToCoordinateArray());
        }
        /**
         * Extracts the coordinates which intersect an {@link Envelope}.
         *
         * @param coordinates the coordinates to scan
         * @param env the envelope to intersect with
         * @return an array of the coordinates which intersect the envelope
         */
        public static Coordinate[] Intersection(Coordinate[] coordinates, Envelope env)
        {
            CoordinateList coordList = new CoordinateList();

            for (int i = 0; i < coordinates.Length; i++)
            {
                Coordinate c = coordinates[i];
                if (env.Intersects(c))
                {
                    coordList.Add(c, true);
                }
            }
            return(coordList.ToCoordinateArray());
        }
        /// <summary>
        /// Function to convert <c>this</c> octagonal envelope into a geometry
        /// </summary>
        /// <param name="geomFactory">The factory to create the geometry</param>
        /// <returns>A geometry</returns>
        public IGeometry ToGeometry(IGeometryFactory geomFactory)
        {
            if (geomFactory == null)
            {
                throw new ArgumentNullException(nameof(geomFactory));
            }

            if (IsNull)
            {
                return(geomFactory.CreatePoint());
            }

            var px00 = new Coordinate(_minX, _minA - _minX);
            var px01 = new Coordinate(_minX, _minX - _minB);

            var px10 = new Coordinate(_maxX, _maxX - _maxB);
            var px11 = new Coordinate(_maxX, _maxA - _maxX);

            var py00 = new Coordinate(_minA - _minY, _minY);
            var py01 = new Coordinate(_minY + _maxB, _minY);

            var py10 = new Coordinate(_maxY + _minB, _maxY);
            var py11 = new Coordinate(_maxA - _maxY, _maxY);

            var pm = geomFactory.PrecisionModel;

            pm.MakePrecise(px00);
            pm.MakePrecise(px01);
            pm.MakePrecise(px10);
            pm.MakePrecise(px11);
            pm.MakePrecise(py00);
            pm.MakePrecise(py01);
            pm.MakePrecise(py10);
            pm.MakePrecise(py11);

            var coordList = new CoordinateList();

            coordList.Add(px00, false);
            coordList.Add(px01, false);
            coordList.Add(py10, false);
            coordList.Add(py11, false);
            coordList.Add(px11, false);
            coordList.Add(px10, false);
            coordList.Add(py01, false);
            coordList.Add(py00, false);

            if (coordList.Count == 1)
            {
                return(geomFactory.CreatePoint(px00));
            }
            Coordinate[] pts;
            if (coordList.Count == 2)
            {
                pts = coordList.ToCoordinateArray();
                return(geomFactory.CreateLineString(pts));
            }
            // must be a polygon, so add closing point
            coordList.Add(px00, false);
            pts = coordList.ToCoordinateArray();
            return(geomFactory.CreatePolygon(geomFactory.CreateLinearRing(pts)));
        }