-
Notifications
You must be signed in to change notification settings - Fork 942
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
Lines with a 180 degree angle between them should be considered parallel (turf-boolean-parallel
)
#2475
Conversation
Another issue I've identified is that lines that are parallel to the y-axis have a slope of The question is - are there situations where both lines have slope of |
Hi Mark. Going to review this for you if I can. Think you're right though in that calculateRhumbBearing might need some improvements, and would like to find out if we should tackle that first in case it has implications for your PR. For a bit more background, the geodesy lib function calculateRhumbBearing is based on has an explicit check that returns NaN if the points are the same i.e. the line has no length so can have no bearing. Might return NaN in other cases too, though not sure what they would be.
If either slope is NaN they can't be parallel as at least one line has an unknowable bearing. That might be why NaN was chosen as return type - even if both lines are illegitimate the caller is less likely to accidentally to do a simple compare and think they're parallel.
Do you have some example data for this? Would like to reproduce that locally if I can as a first step. |
Thanks @smallsaucepan!
Hm, actually I can't seem to reproduce this right now. I added a very simple vertical line test (60a9925) which is passing. If I come across the situation where I was seeing |
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.
Looks good to me.
@smallsaucepan I found the failing test case, it involves 3d lines: 8c2d806 Any idea what might be causing this to fail? |
Thanks @mracette. These coords are failing because they're outside the generally expected values for lon and lat: -180 to 180, and -90 to 90 respectively. Removing the altitude component gives the same NaN result. Here's what they look like projected: Now whether turf-rhumb-bearing (which is what returns NaN) should be more forgiving, I can't say. Most calculators I've seen though insist on inputs being within those ranges. |
Ah, thanks for pointing that out @smallsaucepan. I think that clears everything up then, and I think we can merge this as an isolated fix for |
Hi @smallsaucepan, would you like to take another look at this before merge? |
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.
Looks good to me Mark. Think a maintainer also needs to approve for it to progress though.
Hi @mracette - you will need to update the coordinates in verticals3d.geojson as mentioned above, or the tests will keep failing. |
@smallsaucepan Thank you, that should be fixed. I'm not seeing anything about code review in the contribution guidelines, but if you know who the maintainers are that need to approve this would you mind looping them in? |
Thanks @mracette! You can expect it in the next release. |
Checklist
npm test
at the sub modules where changes have occurred.npm run lint
to ensure code style at the turf module level.Description
booleanParallel
currently does not recognize when parallel lines have opposite directions. This can be verified with a new test that compares the lines[ [0, 0], [0, 1] ]
and[ [0, 1], [0, 0] ]
.The slopes for these lines are 90 and 270 degrees, so they fail the
slope1 === slope2
check. But according to the conditions for parallelism these 2 lines should be considered parallel.A new condition is added in this PR that checks if the lines have an angle of 180 degrees between them. If so, they are considered parallel.