Conversation
|
I am not a fan of having a trait for I would prefer using a
I don't think its really needed. Might cause more confusion than practicality. Its just two fields/values so I would rather just construct it manually. |
|
Gotcha, I'll admit I'm still new to traits so I really appreciate your feedback here!
Hmm I'm not sure how How would you feel about having a With this approach the conversions could be implemented like this: impl Position<Twoxel> {
fn to_native(self) -> Position<Native> {
Position::new(self.x, self.y / 2)
}
fn to_octad(self) -> Position<Octad> {
Position::new(self.x * 2, self.y * 2)
}
}
I understand, in hindsight it's probably clearer to construct it manually. One idea: what if we used a single type for both positions and size args, e.g. |
It doesn't really convey the information but we can create a type alias if we want to. This way we don't have to define new traits or duplicate a bunch of logic by other structs. Not saying we should do that as using separate types also has advantages. Just mentioning alternatives solutions.
We can just make twoxel functions accept a
Aside from the naming being confusing its blocks us from separating |
|
We could do type aliases for coord-spaces and After rewriting the examples I personally find that dedicated types helped a lot with avoiding logic errors. I also don't really think we need traits for making this PR work with the approach I suggested. It would also reduce a lot of the repetition the current PR implementation suffers from.
Gotcha, no problem. We can keep them separate. I'd like to try implementing the |
Draft since the docs still require tweaking.
Coordinate spaces for each drawing format
Each drawing format has a set of corresponding coordinate space structs.
FooPositionhasxandyfields,FooSizehaswidthandheight. All builtin types:NativePosition,NativeSize)TwoxelPosition,TwoxelSize)OctadPosition,OctadSize)BlocktadPosition,BlocktadSize)Relative conversions
Positiontypes can convert to otherPositiontypes freely in a relative fashion. Same goes forSize. This is done through dedicatedto_*()methods, as some conversions are lossy (e.gOctadPosition->NativePosition)The
PositionandSizetraits include default convenience helpers such asoffset_x(),offset_xy(),to_tuple().Drawing functions API changes
Drawing functions now each take a dedicated
impl Into<FooPosition>(orFooSize) argument. The onlyFrom<>implementation included isFrom<(i16, i16)>for all built-in types for convenience. This means that twoxels and octads no longer usef32s for sub-cell positioning.Convenience arithmetic impls
I'm not entirely sure if this is a good thing or not, but I added the following macros which implement the simplest form of arithmetic for
PositionandSizetypes:impl_coord_space_position_arithmetic!()impl_coord_space_size_arithmetic!()The main reason for their inclusion is reducing boilerplate when adding custom coordinate spaces.
I thought of the following, but decided to hold off for now:
to_*()methods for tuplesSizetypes as they are quite repetitive and most operations seem to be done onPositiontypesSizeandPositionof the same type (e.g. twoxel) convertable. I'm not sure whether anx->width&y->heightconversion makes sense though.Is there anything in here that doesn't belong or should be changed?