linebender / kurbo

A Rust library for manipulating curves
Apache License 2.0
727 stars 71 forks source link

Enhancement: Point #389

Closed papyDoctor closed 1 month ago

papyDoctor commented 1 month ago

Hi, It would be useful to add some functions to the Point struct, I'm thinking (and using) of:

#[inline]
pub fn mag2(&self) -> f64 {
    self.x * self.x + self.y * self.y
}
#[inline]
pub fn mag(&self) -> f64 {
    self.mag2().sqrt()
}
#[inline]
pub fn dotp(&self, other: &Point) -> f64 {
    self.x * other.x + self.y * other.y
}

I can create a PR if you agree. Also, why can't we multiply (and divide) a Point with a f64? I can also do a PR for this?

raphlinus commented 1 month ago

These methods exist on Vec2 but not Point, because they make mathematical sense for the former but not the latter. If you are using these methods, the type should be vector.

That said, there is an argument to be made that the .to_vec2() calls are boilerplate and noise, so making the distinction in the type system is a tradeoff. But, for better or worse, that's where kurbo is.