Exemplo n.º 1
0
        internal bool Intersects(Point2 p, bool guaranteeEdge)
        {
            var lastIndex = _pointList.Count - 1;

            if (2 <= lastIndex)
            {
                var intersectionCount = IntersectionPositiveXRayCount(p);
                if (intersectionCount > 0)
                {
                    return(((_hole.HasValue && _hole.Value) ? 0 : 1) == (intersectionCount % 2));
                }
                if ((_hole.HasValue && _hole.Value))
                {
                    return(true);
                }
                if (guaranteeEdge)
                {
                    for (int i = lastIndex, nextIndex = 0; nextIndex <= lastIndex; i = nextIndex++)
                    {
                        if (Segment2.Intersects(_pointList[i], _pointList[nextIndex], p))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
            return(
                0 == lastIndex
                ? _pointList[0].Equals(p)
                : 1 == lastIndex && Segment2.Intersects(_pointList[0], _pointList[1], p)
                );
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public bool Intersects(Segment2 other)
        {
            if (Count == 0 || ReferenceEquals(null, other))
            {
                return(false);
            }
            if (Count == 1)
            {
                return(other.Intersects(this[0]));
            }

            throw new NotImplementedException();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines if a point intersects this line string.
        /// </summary>
        /// <param name="p">A point to test intersection with.</param>
        /// <returns>True when a point intersects this line string.</returns>
        public bool Intersects(Point2 p)
        {
            var lastIndex = Count - 1;

            if (lastIndex >= 1)
            {
                for (int i = 0, nextIndex = 1; i < lastIndex; i = nextIndex++)
                {
                    if (Segment2.Intersects(this[i], this[nextIndex], p))
                    {
                        return(true);
                    }
                }
            }
            return(lastIndex == 0 && this[0].Equals(p));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Advanced intersection testing.
        /// </summary>
        /// <param name="p"></param>
        /// <returns>0 for boundary, 1 for within, -1 for outside</returns>
        internal int AdvancedIntersectionTest(Point2 p)
        {
            var mbr = GetMbr();

            Contract.Assume(Count <= 0 || mbr != null);
            if (Count >= 2 && mbr.Intersects(p))
            {
                var b = this[Count - 1];
                for (var nextIndex = 0; nextIndex < Count; nextIndex++)
                {
                    var a = b;
                    b = this[nextIndex];
                    if (Segment2.Intersects(a, b, p))
                    {
                        return(0);
                    }
                }
            }
            return(Intersects(p, false) ? 1 : -1);
        }