public SegmentSegmentPosition IntesectionWith(LineSegment1D other) { // TODO: add tolerance if (other.Start > this.End) { return(SegmentSegmentPosition.Disjoint); } if (other.End < this.Start) { return(SegmentSegmentPosition.Disjoint); } if (other.Start > this.Start && other.Start < this.End) { return(SegmentSegmentPosition.Overlapping); // Is the second check necessary? } if (other.End > this.Start && other.End < this.End) { return(SegmentSegmentPosition.Overlapping); } if (other.Start == this.End) { return(SegmentSegmentPosition.CommonVertexOnly); // TODO: return the vertex itself } else { return(SegmentSegmentPosition.CommonVertexOnly); // TODO: return the vertex itself } }
[InlineData(1, 4, 2, 3, 1, "NEVER")] // overlapping public void LineSegementCollision1D(int start1, int stop1, int start2, int stop2, int motion2, string expected) { var ls1 = new LineSegment1D(FixedPoint.FromInt(start1), FixedPoint.FromInt(stop1)); var ls2 = new LineSegment1D(FixedPoint.FromInt(start2), FixedPoint.FromInt(stop2)); var m = FixedPoint.FromInt(motion2); var time = CollisionDetector.DetermineCollisionTime(ls1, ls2, m); var res = time == null ? "NEVER" : time.Value.ToString(); Assert.Equal(expected, res); }
public void TestOverlap(int a1, int a2, int b1, int b2, int expected) { var l1 = new LineSegment1D(FixedPoint.FromInt(a1), FixedPoint.FromInt(a2)); var l2 = new LineSegment1D(FixedPoint.FromInt(b1), FixedPoint.FromInt(b2)); var overlap1 = l1.MeasureOverlap(l2); var overlapInt1 = (int)overlap1; Assert.Equal(expected, overlapInt1); var overlap2 = l2.MeasureOverlap(l1); var overlapInt2 = (int)overlap2; Assert.Equal(expected, overlapInt2); }