GetIntersectionWith() публичный Метод

Finds, provided it exists, the intersection point with the specified Line.

If the line and the segment do not intersect, the method returns . If the line and the segment share multiple points, the method throws an InvalidOperationException.

Thrown if this segment is a portion of /// line.
public GetIntersectionWith ( Line other ) : Point?
other Line to find intersection with.
Результат Point?
Пример #1
0
        public void IntersectionPointTest( float ax1, float ay1, float ax2, float ay2, float bx1, float by1, float bx2, float by2, float ix, float iy, IntersectionType type )
        {
            LineSegment segA = new LineSegment( new Point( ax1, ay1 ), new Point( ax2, ay2 ) );
            LineSegment segB = new LineSegment( new Point( bx1, by1 ), new Point( bx2, by2 ) );
            Point expectedIntersection = new Point( ix, iy );

            Assert.DoesNotThrow( ( ) =>
            {
                Point? segSeg = segA.GetIntersectionWith( segB );
                Point? segLine = segA.GetIntersectionWith( (Line) segB );
                Point? lineSeg = ( (Line) segA ).GetIntersectionWith( segB );

                if ( type == IntersectionType.AllFour )
                {
                    Assert.AreEqual( expectedIntersection, segSeg );
                }
                else
                {
                    Assert.AreEqual( null, segSeg );
                }

                if ( ( type == IntersectionType.AllFour ) || ( type == IntersectionType.SegmentA ) )
                {
                    Assert.AreEqual( expectedIntersection, segLine );
                }
                else
                {
                    Assert.AreEqual( null, segLine );
                }

                if ( ( type == IntersectionType.AllFour ) || ( type == IntersectionType.SegmentB ) )
                {
                    Assert.AreEqual( expectedIntersection, lineSeg );
                }
                else
                {
                    Assert.AreEqual( null, lineSeg );
                }
            } );

            Point? lineLine = ( (Line) segA ).GetIntersectionWith( (Line) segB );

            if ( type != IntersectionType.None )
            {
                Assert.AreEqual( expectedIntersection, lineLine );
            }
            else
            {
                Assert.AreEqual( null, lineLine );
            }
        }
Пример #2
0
        public void OverlappingSegmentIntersectionPointTest( float ax1, float ay1, float ax2, float ay2, float bx1, float by1, float bx2, float by2 )
        {
            LineSegment segA = new LineSegment( new Point( ax1, ay1 ), new Point( ax2, ay2 ) );
            LineSegment segB = new LineSegment( new Point( bx1, by1 ), new Point( bx2, by2 ) );

            // are we really collinear?
            Assert.Throws<InvalidOperationException>( ( ) => ( (Line) segA ).GetIntersectionWith( (Line) segB ) );

            Assert.Throws<InvalidOperationException>( ( ) => segA.GetIntersectionWith( (Line) segB ) );
            Assert.Throws<InvalidOperationException>( ( ) => ( (Line) segA ).GetIntersectionWith( segB ) );
            Assert.Throws<InvalidOperationException>( ( ) => segB.GetIntersectionWith( (Line) segA ) );
            Assert.Throws<InvalidOperationException>( ( ) => ( (Line) segB ).GetIntersectionWith( segA ) );
            Assert.Throws<InvalidOperationException>( ( ) => segB.GetIntersectionWith( segA ) );
            Assert.Throws<InvalidOperationException>( ( ) => segA.GetIntersectionWith( segB ) );
        }
Пример #3
0
        public void CommonIntersectionPointTest( float ax1, float ay1, float ax2, float ay2, float bx1, float by1, float bx2, float by2, float ix, float iy )
        {
            LineSegment segA = new LineSegment( new Point( ax1, ay1 ), new Point( ax2, ay2 ) );
            LineSegment segB = new LineSegment( new Point( bx1, by1 ), new Point( bx2, by2 ) );
            Point expectedIntersection = new Point( ix, iy );

            // are we really collinear?
            Assert.Throws<InvalidOperationException>( ( ) => ( (Line) segA ).GetIntersectionWith( (Line) segB ) );

            Assert.Throws<InvalidOperationException>( ( ) => segA.GetIntersectionWith( (Line) segB ) );
            Assert.Throws<InvalidOperationException>( ( ) => ( (Line) segA ).GetIntersectionWith( segB ) );
            Assert.Throws<InvalidOperationException>( ( ) => segB.GetIntersectionWith( (Line) segA ) );
            Assert.Throws<InvalidOperationException>( ( ) => ( (Line) segB ).GetIntersectionWith( segA ) );
            Assert.AreEqual( expectedIntersection, segB.GetIntersectionWith( segA ) );
            Assert.AreEqual( expectedIntersection, segA.GetIntersectionWith( segB ) );
        }
Пример #4
0
        public void ParallelIntersectionPointTest( float ax1, float ay1, float ax2, float ay2, float bx1, float by1, float bx2, float by2 )
        {
            LineSegment segA = new LineSegment( new Point( ax1, ay1 ), new Point( ax2, ay2 ) );
            LineSegment segB = new LineSegment( new Point( bx1, by1 ), new Point( bx2, by2 ) );

            // are we really parallel?
            Assert.AreEqual( null, ( (Line) segA ).GetIntersectionWith( (Line) segB ) );

            Assert.AreEqual( null, segA.GetIntersectionWith( (Line) segB ) );
            Assert.AreEqual( null, ( (Line) segA ).GetIntersectionWith( segB ) );
            Assert.AreEqual( null, segB.GetIntersectionWith( (Line) segA ) );
            Assert.AreEqual( null, ( (Line) segB ).GetIntersectionWith( segA ) );
            Assert.AreEqual( null, segB.GetIntersectionWith( segA ) );
            Assert.AreEqual( null, segA.GetIntersectionWith( segB ) );
        }
Пример #5
0
 /// <summary>
 /// Finds, provided it exists, the intersection point with the specified <see cref="LineSegment"/>.
 /// </summary>
 /// 
 /// <param name="other"><see cref="LineSegment"/> to find intersection with.</param>
 /// 
 /// <returns>Returns intersection point with the specified <see cref="LineSegment"/>, or <see langword="null"/>,
 /// if this line does not intersect with the segment.</returns>
 /// 
 /// <remarks><para>If the line and segment do not intersect, the method returns <see langword="null"/>.
 /// If the line and segment share multiple points, the method throws an <see cref="InvalidOperationException"/>.
 /// </para></remarks>
 /// 
 /// <exception cref="InvalidOperationException">Thrown if <paramref name="other"/> is a portion
 /// of this line.</exception>
 /// 
 public Point? GetIntersectionWith(LineSegment other)
 {
     return other.GetIntersectionWith(this);
 }
Пример #6
0
 /// <summary>
 /// Finds, provided it exists, the intersection point with the specified <see cref="LineSegment"/>.
 /// </summary>
 ///
 /// <param name="other"><see cref="LineSegment"/> to find intersection with.</param>
 ///
 /// <returns>Returns intersection point with the specified <see cref="LineSegment"/>, or <see langword="null"/>,
 /// if this line does not intersect with the segment.</returns>
 ///
 /// <remarks><para>If the line and segment do not intersect, the method returns <see langword="null"/>.
 /// If the line and segment share multiple points, the method throws an <see cref="InvalidOperationException"/>.
 /// </para></remarks>
 ///
 /// <exception cref="InvalidOperationException">Thrown if <paramref name="other"/> is a portion
 /// of this line.</exception>
 ///
 public Point?GetIntersectionWith(LineSegment other)
 {
     return(other.GetIntersectionWith(this));
 }