BlueEngine icon indicating copy to clipboard operation
BlueEngine copied to clipboard

Use `impl Into<T>`

Open suprohub opened this issue 1 year ago • 3 comments

some functions like set_color or set position use multiple arguments, it bit discomfort if you want set position of tuple or Array4. Solution: position: impl Into<Array4>

suprohub avatar Aug 12 '24 09:08 suprohub

or use from

suprohub avatar Aug 12 '24 09:08 suprohub

The issue with that is that the function does more than setting just values, it also updates the uniform buffer and transform matrices.

A solution can be to add a whole new copy of the functions that accepts from array/list and internally maps them. But that will add extra confusion and cluttering.

e.g.

// the main
fn set_position(&mut self, x: f32, y: f32, z: f32);

// for array, an extra function can be added
fn set_position_with_array(&mut self, value: impl Into<[f32; 3]>) {
    self.set_position(value[0], value[1], value[2]);
}

ElhamAryanpur avatar Aug 12 '24 17:08 ElhamAryanpur

@Gipson62 @NickJasonHagen What do you guys think?

ElhamAryanpur avatar Aug 12 '24 17:08 ElhamAryanpur

Honestly, having more functions like this would help, it'll help as much as functions overloading is useful in OOP languages and don't most people use the set_position() like this already?

let pos: Position3D = ...;
set_position(pos.x, pos.y, pos.z);

So making it takes an impl Into<[f32; 3]> instead of 3 f32 wouldn't be stupid imho

Gipson62 avatar Jan 11 '25 13:01 Gipson62