コード例 #1
0
        /// <summary>
        /// Determines whether the queue contains an intersection event.
        /// </summary>
        /// <param name="intersectionEvent">The intersection event.</param>
        /// <returns><c>true</c> if the queue contains the <paramref name="intersectionEvent"/>; otherwise <c>false</c>.</returns>
        /// <exception cref="System.ArgumentNullException">The intersection event is null.</exception>
        public Boolean Contains(IntersectionEvent intersectionEvent)
        {
            if (intersectionEvent == null)
            {
                throw new ArgumentNullException("intersectionEvent", "The intersection event is null.");
            }

            return(_eventHeap.Contains(intersectionEvent));
        }
コード例 #2
0
        /// <summary>
        /// Adds an intersection event to the queue.
        /// </summary>
        /// <param name="intersectionEvent">The intersection event.</param>
        /// <exception cref="System.ArgumentNullException">The intersection event is null.</exception>
        public void Add(IntersectionEvent intersectionEvent)
        {
            if (intersectionEvent == null)
            {
                throw new ArgumentNullException("intersectionEvent", "The intersection event is null.");
            }

            _eventHeap.Insert(intersectionEvent);
        }
コード例 #3
0
 /// <summary>
 /// Adds a new intersection event to the sweep line.
 /// Performs the order modifying effect of a possible intersection point between two directly adjacent segments.
 /// </summary>
 /// <remarks>
 /// An intersection event may become invalid if the order of the segments were altered or the intersection point has been already passed by the sweep line since the enqueuing of the event.
 /// This method is safe to be applied for invalid intersections.
 /// </remarks>
 /// <param name="e">The event.</param>
 /// <returns><c>true</c> if a new, valid intersection point was found and passed between <paramref name="x" /> and <paramref name="y" />; otherwise <c>false</c>.</returns>
 /// <exception cref="InvalidOperationException">Segment <paramref name="x" /> and <paramref name="y" /> do not intersect each other.</exception>
 public Boolean Add(IntersectionEvent e)
 {
     return(Intersect(e.Below, e.Above));
 }
コード例 #4
0
        /// <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);
        }