/// <summary>
            /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
            /// </summary>
            /// <param name="x">The first object to compare.</param>
            /// <param name="y">The second object to compare.</param>
            /// <returns>A signed integer that indicates the relative values of <paramref name="x" /> and <paramref name="y" />.</returns>
            public Int32 Compare(AngularEdge x, AngularEdge y)
            {
                Int32 coordinateCompare = _comparer.Compare(x.Source, y.Source);

                if (coordinateCompare == 0)
                {
                    return(x.Angle.CompareTo(y.Angle));
                }

                return(coordinateCompare);
            }
        /// <summary>
        /// Compares two <see cref="Event"/> instances and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <remarks>
        /// Events primarily compared by their vertex coordinate, secondarily by their type.
        /// </remarks>
        /// <param name="x">The first <see cref="Event"/> to compare.</param>
        /// <param name="y">The second <see cref="Event"/> to compare.</param>
        /// <returns>A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>.</returns>
        public Int32 Compare(Event x, Event y)
        {
            Int32 result = _coordinateComparer.Compare(x.Vertex, y.Vertex);

            if (result != 0)
            {
                return(result);
            }

            if (x is EndPointEvent && y is EndPointEvent)
            {
                EndPointEvent ex = (EndPointEvent)x;
                EndPointEvent ey = (EndPointEvent)y;

                result = ex.Type.CompareTo(ey.Type);
                if (result == 0)
                {
                    result = ex.Edge.CompareTo(ey.Edge);
                }
            }
            else if (x is IntersectionEvent && y is IntersectionEvent)
            {
                IntersectionEvent ix = (IntersectionEvent)x;
                IntersectionEvent iy = (IntersectionEvent)y;

                if (result == 0)
                {
                    result = _coordinateComparer.Compare(ix.Below.LeftCoordinate, iy.Below.LeftCoordinate);
                }
                if (result == 0)
                {
                    result = _coordinateComparer.Compare(ix.Above.LeftCoordinate, iy.Above.LeftCoordinate);
                }
                if (result == 0)
                {
                    result = _coordinateComparer.Compare(ix.Below.RightCoordinate, iy.Below.RightCoordinate);
                }
                if (result == 0)
                {
                    result = _coordinateComparer.Compare(ix.Above.RightCoordinate, iy.Above.RightCoordinate);
                }
                if (result == 0)
                {
                    result = ix.Below.Edge.CompareTo(iy.Below.Edge);
                }
                if (result == 0)
                {
                    result = ix.Above.Edge.CompareTo(iy.Above.Edge);
                }
                if (result == 0)
                {
                    result = ix.IsClose.CompareTo(iy.IsClose);
                }
            }
            else if (x is EndPointEvent && y is IntersectionEvent)
            {
                result = ((EndPointEvent)x).Type == EventType.Left ? -1 : 1;
            }
            else if (y is EndPointEvent && x is IntersectionEvent)
            {
                result = ((EndPointEvent)y).Type == EventType.Left ? 1 : -1;
            }
            return(result);
        }
Example #3
0
 /// <summary>
 /// Determines whether the <see cref="EventHeap"/> contains any event element with the given coordinate.
 /// </summary>
 /// <param name="position">The coordinate position to locate in the <see cref="EventHeap"/>.</param>
 /// <returns><c>true</c> if the <see cref="EventHeap"/> contains an event element with the specified position; otherwise <c>false</c>.</returns>
 public Boolean Contains(Coordinate position)
 {
     return(this.Any(item => _coordinateComparer.Compare(item.Key.Vertex, position) == 0));
 }