sebcrozet/kiss3d

Consider `impl Into<PointX<_>>` in kiss3d API

Opened this issue · 3 comments

A series of From traits are defined on Point type (doc). We could combine it with impl Into<PointX<_>> to help user to write more compact syntax.

For example, the Window::draw_line receives a pair of point and color. We can turn it to the following.

pub fn draw_line(
    &mut self,
    a: impl Into<Point3<f32>>,
    b: impl Into<Point3<f32>>,
    color: impl Into<Point3<f32>>
)

In this way, we can call by window.draw_line([0.0, 0.0, 0.0], [0.8, 0.8, 0.8], [1.0, 1.0, 1.0]) instead of Point3::new() everywhere.

I tried once the run the tests. It does not work with borrowed types draw_line(&Point3::new(1., 2., 3.)), so imposing this feature will lead to breaking change.

Though using more complex trait bounds can solve this issue, we could add impl From<&Point<...>> for Point<...> to nalgebra as a simple solution.

Would it suffice, if you'd write a wrapper function for that? I wrote a wrapper around the kiss3d framework to adapt the window add_... functions to handle my own structs.

Would look something like this:

fn Wrapper::add_jerrys_line(input: &JerryInput, window: &mut Window) {
// first convert JerryInput into something-nalgebra like
// call Window::add_line_...
}

It's definitely a good idea. Writing a wrapper with Deref to the Window would be enough.

I opened this issue for a mild suggestion to make the API more handy. I dived into the impl and realized that we need both &Point -> Cow<Point> and Point -> Cow<Point> conversions to make the idea come true. It's not yet done on nalgebra.