-
Notifications
You must be signed in to change notification settings - Fork 135
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,19 +134,19 @@ public Point2D ClosestPointTo(Point2D p) | |
} | ||
|
||
/// <summary> | ||
/// Compute the intersection between two lines if the angle between them is greater than a specified | ||
/// Compute the intersection between two line segments if the angle between them is greater than a specified | ||
/// angle tolerance. | ||
/// </summary> | ||
/// <param name="other">The other line to compute the intersection with</param> | ||
/// <param name="intersection">When this method returns, contains the intersection point, if the conversion succeeded, or the default point if the conversion failed.</param> | ||
/// <param name="tolerance">The tolerance used when checking if the lines are parallel</param> | ||
/// <param name="other">The other line segment to compute the intersection with</param> | ||
/// <param name="intersection">The intersection if it exists; otherwise null</param> | ||
/// <param name="tolerance">The tolerance used when checking if the line segments are parallel</param> | ||
/// <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) | ||
{ | ||
if (this.IsParallelTo(other, tolerance)) | ||
{ | ||
intersection = default(Point2D); | ||
intersection = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return false; | ||
} | ||
|
||
|
@@ -159,8 +159,17 @@ public bool TryIntersect(LineSegment2D other, out Point2D intersection, Angle to | |
var t = (q - p).CrossProduct(s) / r.CrossProduct(s); | ||
var u = (p - q).CrossProduct(r) / s.CrossProduct(r); | ||
|
||
intersection = p + (t * r); | ||
return (0.0 <= t && t <= 1.0) && (0.0 <= u && u <= 1.0); | ||
var isIntersected = (0.0 <= t && t <= 1.0) && (0.0 <= u && u <= 1.0); | ||
if (isIntersected) | ||
{ | ||
intersection = p + (t * r); | ||
return true; | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify all this by simply There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for a comment. I'm happy with the merged code. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank YOU for opening the issue and providing a PR 😃 |
||
{ | ||
intersection = null; | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
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;