Пример #1
0
        /// <summary>
        /// Returns whether this line intersects the other.
        /// Edge cases such as if the endpoint of one line lies on the other line
        /// have no definite behaviour.
        /// </summary>
        public bool Intersects(Line other)
        {
            var n = LeftNormal;
            var h = n.Dot(other.Origin - Origin);

            if (h * n.Dot(other.Destination - Origin) > 0)
            {
                return(false);
            }
            else if (h * n.Dot(other.Destination - Origin) == 0)
            {
                if ((Offset.Dot(other.Origin - Origin) < 0 && Offset.Dot(other.Destination - Origin) < 0) ||
                    (Offset.Dot(other.Origin - Destination) > 0 && Offset.Dot(other.Destination - Destination) > 0))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            var angle = other.Offset.Angle(this.Offset);

            if (angle.Degrees == 0 || angle.Degrees == 180)
            {
                if (h != 0)
                {
                    return(false);
                }
                return(_isPointAdjacent(other.Origin) || _isPointAdjacent(other.Destination));
            }

            var sign = n.Dot(other.Offset) > 0 ? 1 : -1;
            var p    = other.Origin - sign * new Vector(h / GMath.Sin(angle), angle);

            return(_isPointAdjacent(p));
        }