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

Suggestion: Add Coord2::from_theta #13

Open
ctrlcctrlv opened this issue Nov 26, 2021 · 2 comments
Open

Suggestion: Add Coord2::from_theta #13

ctrlcctrlv opened this issue Nov 26, 2021 · 2 comments

Comments

@ctrlcctrlv
Copy link
Contributor

I'm surprised there's no function like this:

impl Coord2 {
    fn from_theta(theta: impl Into<f64>) -> Self {
        Coord2(theta.into().cos(), theta.into().sin())
    }
}
@ctrlcctrlv
Copy link
Contributor Author

Then again, perhaps I'm "holding it wrong" by using the Coord2 type to represent vectors and not just coordinates? 🤔

@Logicalshift
Copy link
Owner

It's definitely an intended use for coordinates to represent vectors: they're used for normals and tangents already and have things like the dot product defined for them. (It's also definitely possible this lacks some purity, but so far I can't think of any practical problems)

This seems like a good idea to me: I've now added an initial implementation to this repository. I've chosen unit_vector_at_angle() for the name and made it an extension of anything that implements the Coordinate2D trait rather than something specific to Coord2. I've added a unit_vector() construction function as well for any coordinate, which I think complements the origin() function.

The main reason there aren't too many functions like this is that I've been adding functionality as it becomes necessary for FlowBetween, so this is just something that's never been needed there before (this helps with designing a usable API as well as making it less likely that something non-functional gets put in)

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

No branches or pull requests

2 participants