Skip to content

Clarification about @turf-angle#1192

Merged
DenisCarriere merged 11 commits intomasterfrom
angle-tests
Dec 22, 2017
Merged

Clarification about @turf-angle#1192
DenisCarriere merged 11 commits intomasterfrom
angle-tests

Conversation

@stebogit
Copy link
Copy Markdown
Collaborator

Currently the new @turf-angle is calculating the angle defined by three points (A, o and B in the picture) is defined/calculated as the angle (< 180˚) between the lines extending Ao and oB; as a result the angles AoB and BoA are equals.
Note: passing the option exterior=true will return the explementary angle (360 - angle).
angle2

Now, I believe a more useful calculation (maybe in addition to the current one) would be defining the angle as the clockwise (or counterclockwise) angle between A (startPoint) and B (endPoint) with center in o (midPoint). This would allow comparison between angles due to the reference Ao segment.
angle

In the picture above the current implementation of the module would return the red angle for AoB and the blue dotted angle for AoB'. I believe it would be more useful getting AoB' as the solid blue line, otherwise there is no way to properly compare the two angles.

In this PR I just added a few test cases to confirm and highlight the current behavior.

@DenisCarriere @rowanwins I propose to modify the output as suggested (here a possible implementation, but I'm sure we can find a better one) and adding an option (absolute?) to provide the current result.
I'd also rename the external option to explementary.

If the current output is fine I'd probably add some notes to the docs to clarify the output.

@DenisCarriere
Copy link
Copy Markdown
Contributor

adding an option (absolute?) to provide the current result.
👍

I'd also rename the external option to explementary.
👍

@stebogit I agree with all your comments, this was more a "draft" module, it's still not implemented in @turf/turf so we can still do some changes as patches.

@DenisCarriere DenisCarriere added this to the 5.2.0 milestone Dec 21, 2017
@DenisCarriere
Copy link
Copy Markdown
Contributor

@stebogit I implemented your bearingToAzimuth change to @turf/angle (with minor changes).

Have a look at it to see if that's what you were thinking.

@DenisCarriere DenisCarriere self-assigned this Dec 21, 2017
Copy link
Copy Markdown
Contributor

@DenisCarriere DenisCarriere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stebogit 👍 Looks good to merge

@DenisCarriere
Copy link
Copy Markdown
Contributor

@stebogit I've added some color the test outputs, a lot easier to visualize the outputs now.

Obtuse Angle

  • Red: Interior Angle
  • Blue: Explementary Angle

image

Acute Angle

  • Red: Interior Angle
  • Blue: Explementary Angle

image

@stebogit
Copy link
Copy Markdown
Collaborator Author

@DenisCarriere I tried to add a short description in the jdocs, but I believe it can be explained better. I also added few tests.

This looks ok to me, you did all the work! 😄 👍

@DenisCarriere
Copy link
Copy Markdown
Contributor

This looks ok to me, you did all the work!

You did the initial work 👍 😄

Good stuff, i'll merge


// Explementary angle
if (explementary === true) return 360 - angleAO;
if (options.explementary === true) return 360 - angleAO;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'm also starting to like using options.* instead of defining them at the beginning, it's easier to tell which variables are derived from the options.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const pt1 = point([-10, -30]);
const pt2 = point([-11, -33]);
const pt3 = point([-12, -36]);
t.throws(() => angle(null, pt2, pt3), /obj is required/, 'missing startPoint');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should throw an Error that says missing startPoint instead of obj is required

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was concerned about the performance, but it should not be a big deal.
Have you checked the benchmark by any chance?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry about performance for those types of checks, it doesn't slow anything down.

The biggest performance hits is reiterating over a FeatureCollection twice when 1 pass can achieve the same result.

I'd say all the input type checking is always valid to add, the "heavy" performance hit will be the main logic and not the input checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants