public void Property_Segment2DIntersectionShouldBehaveTheSameAsSegment3DIntersection ( Segment2D segment1, Segment2D segment2 ) { var intersection2D = segment1.IntersectWithSegment(segment2); var intersection3D = segment1.To3D().IntersectWithSegment(segment2.To3D()); if (intersection2D.Is <Null>()) { intersection3D.Is <Null>().Should().BeTrue(); } if (intersection2D.Is <Point2D>(out var point2D)) { intersection3D.Is <Point>().Should().BeTrue(); intersection3D.As <Point>().ToPoint2D().Should().Be(point2D); } if (intersection2D.Is <Segment2D>()) { var segment2D = intersection2D.As <Segment2D>(); intersection3D.Is <LineSegment>().Should().BeTrue(); intersection3D.As <LineSegment>().ProjectTo2D().Should().Be(segment2D); } }
public void Property_IfSegmentsAreParallelAndIntersect_ItShouldBeAnEndPoint ( Segment2D segment1, Segment2D segment2 ) { var intersection = segment1.IntersectWithSegment(segment2); if ( segment1.GetDirection().IsParallelTo(segment2.GetDirection()) && intersection.Is <Point2D>(out var point2D)) { var point = point2D.ToPoint3D(); var isEndOfOneOf = point.IsBaseOrEndPointOf(segment1.To3D()) || point.IsBaseOrEndPointOf(segment2.To3D()); isEndOfOneOf.Should().BeTrue(); } }
public void Property_NonNullResultIfAnyEndPointIsWithinDistanceToleranceOfOtherSegment ( Segment2D segment1, Segment2D segment2 ) { var intersection = segment1.IntersectWithSegment(segment2); var ends = Enumerable .Concat ( segment1.EndPoints.Where(e => e.ToPoint3D().DistanceTo(segment2.To3D()) == ZeroDistance), segment2.EndPoints.Where(e => e.ToPoint3D().DistanceTo(segment1.To3D()) == ZeroDistance) ) .ToList(); if (ends.Any()) { intersection.Should().NotBe(Null.Instance); } }