Пример #1
0
        [Pure] public LinesIntersection2?Intersects(LineSegment2 segment)
        {
            GetCorners(out Vector2 a, out Vector2 b, out Vector2 c, out Vector2 d);

            var abi = segment.Intersects(new LineSegment2(a, b));
            var bci = segment.Intersects(new LineSegment2(b, c));
            var cdi = segment.Intersects(new LineSegment2(c, d));
            var dai = segment.Intersects(new LineSegment2(d, a));

            var min = abi;

            if (bci.HasValue && (!min.HasValue || bci.Value.DistanceAlongA < min.Value.DistanceAlongA))
            {
                min = bci;
            }
            if (cdi.HasValue && (!min.HasValue || cdi.Value.DistanceAlongA < min.Value.DistanceAlongA))
            {
                min = cdi;
            }
            if (dai.HasValue && (!min.HasValue || dai.Value.DistanceAlongA < min.Value.DistanceAlongA))
            {
                min = dai;
            }

            return(min);
        }
        public void AssertThat_LineSegmentRayIntersection_FindsCorrectIntersection()
        {
            var i = new LineSegment2(new Vector2(0, 0), new Vector2(10, 0)).Intersects(new Ray2(new Vector2(5, 5), new Vector2(0, 1)));

            Assert.IsTrue(i.HasValue);
            Assert.AreEqual(new Vector2(5, 0), i.Value.Position);
            Assert.AreEqual(0.5f, i.Value.DistanceAlongA);
            Assert.AreEqual(-5, i.Value.DistanceAlongB);
        }
Пример #3
0
        public LinesIntersection2?Intersects(LineSegment2 segment, out Parallelism parallelism)
        {
            var intersection = LongLine.Intersects(segment.LongLine, out parallelism);

            if (!intersection.HasValue)
            {
                return(null);
            }

            if (intersection.Value.DistanceAlongA < 0 || intersection.Value.DistanceAlongA > 1)
            {
                return(null);
            }

            if (intersection.Value.DistanceAlongB < 0 || intersection.Value.DistanceAlongB > 1)
            {
                return(null);
            }

            return(intersection);
        }
Пример #4
0
 public LinesIntersection2? Intersects(LineSegment2 segment)
 {
     Parallelism _;
     return Intersects(segment, out _);
 }
Пример #5
0
        public LinesIntersection2? Intersects(LineSegment2 segment, out Parallelism parallelism)
        {
            var intersection = LongLine.Intersects(segment.LongLine, out parallelism);

            if (!intersection.HasValue)
                return null;

            if (intersection.Value.DistanceAlongA <= 0 || intersection.Value.DistanceAlongA >= 1)
                return null;

            if (intersection.Value.DistanceAlongB <= 0 || intersection.Value.DistanceAlongB >= 1)
                return null;

            return intersection;
        }
Пример #6
0
 /// <summary>
 /// Determines whether the specified LineSegment2 is equal to the current Ray.
 /// </summary>
 /// <param name="other">The LineSegment2 to compare with the current LineSegment2.</param>
 public bool Equals(LineSegment2 other)
 {
     return Start.Equals(other.Start) && End.Equals(other.End);
 }
Пример #7
0
 /// <summary>
 /// Determines whether the specified LineSegment2 is equal to the current Ray.
 /// </summary>
 /// <param name="other">The LineSegment2 to compare with the current LineSegment2.</param>
 public bool Equals(LineSegment2 other)
 {
     return(Start.Equals(other.Start) && End.Equals(other.End));
 }
Пример #8
0
 public LinesIntersection2?Intersects(LineSegment2 segment)
 {
     return(Intersects(segment, out Parallelism _));
 }