Skip to content
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

Angle between a Vector and the x axis. #235

Merged
merged 2 commits into from Nov 22, 2017
Merged

Conversation

@nical
Copy link
Collaborator

nical commented Nov 22, 2017

I use this a lot in lyon, and having it in euclid would be much nicer.

This PR implements computing the angle between a 2d vector and the x axis using an approximation of atan2. This approximation is faster enough that it made a difference in lyon, so I am very much inclined to use it by default here (or at least use it for f32 vectors).


This change is Reviewable

@nical
Copy link
Collaborator Author

nical commented Nov 22, 2017

r? @kvark

impl<T, U> TypedVector2D<T, U>
where T: Trig + Copy + Sub<T, Output = T> {
/// Returns the angle between this vector and the x axis between -PI and PI.
pub fn angle(&self) -> Radians<T> {

This comment has been minimized.

@kvark

kvark Nov 22, 2017

Member

can we have the name reflecting the fact X axis is compared to?

This comment has been minimized.

@nical

nical Nov 22, 2017

Author Collaborator

Yep sounds good, if you have suggestions let me know, maybe

  • x_angle
  • x_axis_angle
  • angle_from_x_axis (a bit long but very explicit) ?

This comment has been minimized.

@kvark

kvark Nov 22, 2017

Member

last one would be my preference. The method involves some math, so it's ok to have the name longer

@nical nical force-pushed the nical:vector_angle branch from eabc0f1 to 3a3803b Nov 22, 2017
@kvark
kvark approved these changes Nov 22, 2017
@kvark
Copy link
Member

kvark commented Nov 22, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Nov 22, 2017

📌 Commit 304c1f4 has been approved by kvark

bors-servo added a commit that referenced this pull request Nov 22, 2017
Angle between a Vector and the x axis.

I use this a lot in lyon, and having it in euclid would be much nicer.

This PR implements computing the angle between a 2d vector and the x axis using an approximation of atan2. This approximation is faster enough that it made a difference in lyon, so I am very much inclined to use it by default here (or at least use it for f32 vectors).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/235)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 22, 2017

Testing commit 304c1f4 with merge 1a5cdc3...

@bors-servo
Copy link
Contributor

bors-servo commented Nov 22, 2017

☀️ Test successful - status-travis
Approved by: kvark
Pushing 1a5cdc3 to master...

@bors-servo bors-servo merged commit 304c1f4 into servo:master Nov 22, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@nical nical deleted the nical:vector_angle branch Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.