Ejemplo n.º 1
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(nameof(intersectionEvent));
            }

            this.eventHeap.Insert(intersectionEvent);
        }
Ejemplo n.º 2
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(nameof(intersectionEvent));
            }

            return(this.eventHeap.Contains(intersectionEvent));
        }
Ejemplo n.º 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 the segments; otherwise <c>false</c>.</returns>
        /// <exception cref="System.ArgumentNullException">The event is null.</exception>
        /// <exception cref="InvalidOperationException">The segments do not intersect each other.</exception>
        public Boolean Add(IntersectionEvent e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            return(this.Intersect(e.Below, e.Above));
        }
Ejemplo n.º 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)
        {
            if (x == null || y == null)
            {
                return(0);
            }

            Int32 result = this.coordinateComparer.Compare(x.Vertex, y.Vertex);

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

            EndPointEvent     ex = x as EndPointEvent;
            EndPointEvent     ey = y as EndPointEvent;
            IntersectionEvent ix = x as IntersectionEvent;
            IntersectionEvent iy = y as IntersectionEvent;

            if (ex != null && ey != null)
            {
                result = ex.Type.CompareTo(ey.Type);
                if (result == 0)
                {
                    result = ex.Edge.CompareTo(ey.Edge);
                }
            }
            else if (ix != null && iy != null)
            {
                if (result == 0)
                {
                    result = this.coordinateComparer.Compare(ix.Below.LeftCoordinate, iy.Below.LeftCoordinate);
                }
                if (result == 0)
                {
                    result = this.coordinateComparer.Compare(ix.Above.LeftCoordinate, iy.Above.LeftCoordinate);
                }
                if (result == 0)
                {
                    result = this.coordinateComparer.Compare(ix.Below.RightCoordinate, iy.Below.RightCoordinate);
                }
                if (result == 0)
                {
                    result = this.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.IsClosing.CompareTo(iy.IsClosing);
                }
            }
            else if (ex != null && iy != null)
            {
                result = ex.Type == EventType.Left ? -1 : 1;
            }
            else if (ix != null && ey != null)
            {
                result = ey.Type == EventType.Left ? 1 : -1;
            }

            return(result);
        }