mathnet / mathnet-spatial

Math.NET Spatial
http://spatial.mathdotnet.com
MIT License
378 stars 133 forks source link

LineSegment2D - TryIntersect - should this return the intersection of lines or line segments? #178

Closed gtodd258 closed 1 year ago

gtodd258 commented 4 years ago

When attempting to find the intersection between two line segments, the results are what I would expect to see when trying to find the intersection between two lines. My understanding is that line segments, as opposed to lines, do not continue infinitely in either direction, but the TryIntersect method returns results assuming that they do.

For example, from IntersectWithTest in LineSegment2DTests.cs, the first TestCase points as line segments do not intersect, but if they were Line2D then they would intersect. See:

2020-06-04 22_29_04-Book1 - Excel

I'm attempting to use this in a manner where I only want the TryIntersect to return a valid intersection as the passed by reference Point2D if the segments themselves intersect, which is what I would expect based on the naming of the LineSegment2D class and TryIntersect method.

If this is the intended behavior then I have a workaround, otherwise I'd be willing to help improve the project.

JohanLarsson commented 4 years ago

Looks like you found a bug, my expectation is the same as yours given that we have the two types Line and LineSegment. This is a breaking change but one we should probably make.

gtodd258 commented 4 years ago

Taking another look at this, it does appear that the correct boolean value is being returned, but I am unclear as to what the desired functionality with the intersection Point2D parameter is. The intersection as if the line segments were treated as lines is returned so long as an intersection is possible.

The parameter comment reads:

When this method returns, contains the intersection point, if the conversion succeeded, or the default point if the conversion failed.

so I suppose it depends on what exactly is meant by the conversion succeeding or failing.

This may be a non-issue, but the intersection Point2D parameter lead to some confusion on my end.

JohanLarsson commented 4 years ago

That piece of documentation reads like a copy-paste accident.