Skip to content

Implemented azimuthToBearing#2410

Closed
basvdijk wants to merge 0 commit intoTurfjs:masterfrom
basvdijk:master
Closed

Implemented azimuthToBearing#2410
basvdijk wants to merge 0 commit intoTurfjs:masterfrom
basvdijk:master

Conversation

@basvdijk
Copy link
Copy Markdown
Contributor

@basvdijk basvdijk commented Mar 9, 2023

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Have read How To Contribute.
  • Run npm test at the sub modules where changes have occurred.
  • Run npm run lint to ensure code style at the turf module level.

Submitting a new TurfJS Module.

  • Overview description of proposed module.
  • Include JSDocs with a basic example.
  • Execute ./scripts/generate-readmes to create README.md.
  • Add yourself to contributors in package.json using "Full Name <@github Username>".

@basvdijk
Copy link
Copy Markdown
Contributor Author

basvdijk commented Mar 9, 2023

Implemented #2399

@basvdijk basvdijk mentioned this pull request Mar 9, 2023
Copy link
Copy Markdown
Member

@rowanwins rowanwins left a comment

Choose a reason for hiding this comment

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

👍 @basvdijk

@JamesLMilner
Copy link
Copy Markdown
Collaborator

I think we can merge this :)

@rowanwins rowanwins self-requested a review May 8, 2023 11:50
Copy link
Copy Markdown
Member

@rowanwins rowanwins left a comment

Choose a reason for hiding this comment

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

Requires a tidyup of the function so that the tests pass

* @returns {number} bearing between -180 and +180 degrees
*/
export function azimuthToBearing(angle: number): number {
return angle < 0 ? angle + 360 : angle;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty sure this isn't working as expected @basvdijk now that I've run CI and seen the failing tests.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this works 😃:

function azimuthToBearing(angle) {
  angle = angle % 360;
  if (angle > 0) return angle > 180 ? angle - 360 : angle;
  return angle < -180 ? angle + 360 : angle;
}

test('azimuthToBearing', t => {
  t.equal(azimuthToBearing(0), 0);
  t.equal(azimuthToBearing(360), 0);
  t.equal(azimuthToBearing(180), 180);

  t.equal(azimuthToBearing(40), 40);
  t.equal(azimuthToBearing(40 + 360), 40);

  t.equal(azimuthToBearing(-35), -35);
  t.equal(azimuthToBearing(-35 - 360), -35);

  t.equal(azimuthToBearing(255), -105);
  t.equal(azimuthToBearing(255 + 360), -105);

  t.equal(azimuthToBearing(-200), 160);
  t.equal(azimuthToBearing(-200 - 360), 160);

  t.end();
});

* and returns an angle between -180 and +180 degrees (positive clockwise), 0 being the north line
*
* @name azimuthToBearing
* @param {number} angle between 0 and 360 degrees
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think angle should not be restricted to 0-360, but any number, you can easily normalize it with mod 360

* @returns {number} bearing between -180 and +180 degrees
*/
export function azimuthToBearing(angle: number): number {
return angle < 0 ? angle + 360 : angle;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this works 😃:

function azimuthToBearing(angle) {
  angle = angle % 360;
  if (angle > 0) return angle > 180 ? angle - 360 : angle;
  return angle < -180 ? angle + 360 : angle;
}

test('azimuthToBearing', t => {
  t.equal(azimuthToBearing(0), 0);
  t.equal(azimuthToBearing(360), 0);
  t.equal(azimuthToBearing(180), 180);

  t.equal(azimuthToBearing(40), 40);
  t.equal(azimuthToBearing(40 + 360), 40);

  t.equal(azimuthToBearing(-35), -35);
  t.equal(azimuthToBearing(-35 - 360), -35);

  t.equal(azimuthToBearing(255), -105);
  t.equal(azimuthToBearing(255 + 360), -105);

  t.equal(azimuthToBearing(-200), 160);
  t.equal(azimuthToBearing(-200 - 360), 160);

  t.end();
});

Copy link
Copy Markdown
Collaborator

@mfedderly mfedderly left a comment

Choose a reason for hiding this comment

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

I'm open to merging this but can you update this branch and incorporate the suggestions from stebogit? Thanks!

@basvdijk
Copy link
Copy Markdown
Contributor Author

basvdijk commented Aug 5, 2024

@mfedderly just added the fixes according to comment of @stebogit

@mfedderly
Copy link
Copy Markdown
Collaborator

It looks like you picked up a merge conflict along the way can you knock that out too?

@basvdijk basvdijk closed this Aug 5, 2024
@basvdijk
Copy link
Copy Markdown
Contributor Author

basvdijk commented Aug 5, 2024

@mfedderly somehow I can't get it to work. I keep getting issues, merge conflicts and I am currently unable to make it work. I guess it has something to do with being 100 commits behind after a year.

@mfedderly
Copy link
Copy Markdown
Collaborator

It might have been that you just needed to pull from the turf repo instead of your fork? If you're just opening a new PR can you @ me so I see it? Thanks.

@basvdijk basvdijk mentioned this pull request Aug 6, 2024
8 tasks
@basvdijk
Copy link
Copy Markdown
Contributor Author

basvdijk commented Aug 6, 2024

@mfedderly Created #2674 to replace this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants