flo_curves icon indicating copy to clipboard operation
flo_curves copied to clipboard

Suggestion: Add `Coord2::from_theta`

Open ctrlcctrlv opened this issue 3 years ago • 2 comments

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 avatar Nov 26 '21 07:11 ctrlcctrlv

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

ctrlcctrlv avatar Nov 26 '21 07:11 ctrlcctrlv

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)

Logicalshift avatar Dec 04 '21 23:12 Logicalshift