Example #1
0
        /// <summary>
        /// Determines which side of a divider a horizontal line segment lies on.
        /// Used in point in polygon.
        /// </summary>
        /// <param name="id">The divider to process</param>
        /// <param name="s">Start of horizontal segment.</param>
        /// <param name="e">End of segment.</param>
        /// <param name="od">The divider the side refers to. This usually refers to
        /// the supplied divider, but may refer to another divider in a situation where the
        /// horizontal segment passes directly through one end of <paramref name="d"/>.</param>
        /// <returns>Side.Left if the line is to the left of the divider, Side.Right
        /// if line to the right, Side.On if the end of the line is coincident with
        /// the divider, Side.Unknown if an error arose.</returns>
        /// <remarks>
        /// Rather than passing in 2 PointGeometry objects, it would be better to pass
        /// in a HorizontalRay object, since 2 arbitrary positions are not guaranteed
        /// to be horizontal.
        /// </remarks>
        internal static Side GetSide(IDivider id, IPointGeometry s, IPointGeometry e, out IDivider od)
        {
            // If the end of the horizontal segment hits the start or
            // the end of the specified divider, we have a situation where the divider
            // may not be the divider which is adjacent to the segment. In
            // that case, use special code to determine the side code.
            // Otherwise just convert the supplied divider into a line, and get the
            // side code by looking for a vertex which has a different
            // northing from that of the horizontal segment.

            Debug.Assert(s.Easting.Microns <= e.Easting.Microns);
            double d = e.Easting.Meters - s.Easting.Meters;
            Debug.Assert(d>=0.0);
            HorizontalRay hseg = new HorizontalRay(s, d);

            if (e.IsCoincident(id.From) || e.IsCoincident(id.To)) // e both times!
                return hseg.GetSide(id, e.IsCoincident(id.From), out od);
            else
            {
                od = id;
                return od.LineGeometry.GetSide(hseg);
            }
        }