-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Line2D.TryIntersect to pass nullable Point2D #187
Conversation
/// <returns>True if an intersection exists; otherwise false</returns> | ||
[Pure] | ||
public bool TryIntersect(LineSegment2D other, out Point2D intersection, Angle tolerance) | ||
public bool TryIntersect(LineSegment2D other, out Point2D? intersection, Angle tolerance) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialization intersection = null;
{ | ||
if (this.IsParallelTo(other, tolerance)) | ||
{ | ||
intersection = default(Point2D); | ||
intersection = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed here if the initialization is done at the function entry point
intersection = p + (t * r); | ||
return true; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify all this by simply return intersection != null;
and completely removing the else
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken, this is exactly the bug fix in this PR, correct? There is no intersection in your example, you can verify it using LineSegment2DTests.IntersectWithTest2
I helped a bit in the implementation of this PR if you don't mind, this has already been merged to master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a comment.
Your understanding is correct that we can verify it by using LineSegment2DTests.IntersectWithTest2
.
I'm happy with the merged code. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank YOU for opening the issue and providing a PR 😃
This pull-request is asking for help to solve #178.
The problem is that
LineSegment2D.TryIntersect()
always passes by referencePoint2D
of intersection, regardless of whether the twoLineSegment2D
actually have a valid intersection or not.In my fix,
LineSegment2D.TryIntersect()
passes by refPoint2D?
, which can indicate that there is no intersection.My fix used #111 as reference.
I'm not sure that this breaking change is acceptable or not.
If there is another way to solve this, I'm happy to learn it.
I considered these fix-plans: