Exemple #1
0
        /// <summary>
        /// Creates an identical polygon.
        /// </summary>
        /// <returns>A polygon.</returns>
        /// <remarks>Functions as a deep clone.</remarks>
        public Polygon2 Clone()
        {
            Contract.Ensures(Contract.Result <Polygon2>() != null);
            var p = new Polygon2(Count);

            foreach (var r in this)
            {
                p.Add(r.Clone());
            }
            return(p);
        }
Exemple #2
0
        /// <summary>
        /// Determines if this polygon occupies the same area as the <paramref name="other"/> polygon.
        /// </summary>
        /// <param name="other">The polygon to compare.</param>
        /// <returns>True when the polygons are spatially equal.</returns>
        public bool SpatiallyEqual(Polygon2 other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (Equals(other))
            {
                return(true);
            }
            if (Count != other.Count)
            {
                return(false);
            }
            if (GetMbr() != other.GetMbr())
            {
                return(false);
            }

            var ringsToCheck = new LinkedList <Ring2>(other);

            foreach (var ringA in this)
            {
                if (ringsToCheck.Count == 0)
                {
                    return(false); // no rings left to check
                }
                var selected = ringsToCheck.FirstOrDefault(r => r.SpatiallyEqual(ringA));
                if (null == selected)
                {
                    return(false); // no match for this ring in A
                }
                ringsToCheck.Remove(selected);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the current object is equal to the <paramref name="other"/> parameter; otherwise, <c>false</c>.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(Polygon2 other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            if (Count != other.Count)
            {
                return(false);
            }

            for (var i = 0; i < Count; i++)
            {
                if (!this[i].Equals(other[i]))
                {
                    return(false);
                }
            }
            return(true);
        }