-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to name methods for integer type conversions? #46
Comments
I just got surprised by exactly the semantics of this in the current implementations of Personally, if I would expect let rgb8 = RGB8 { r: 0xff, g: 0x00, b: 0xff };
let rgbf: RGB<f32> = rgb8.into();
assert_eq!(rgbf.r, 1.0);
assert_eq!(rgbf.g, 0.0);
assert_eq!(rgbf.b, 1.0); because, to me, a "colour" type has made itself semantically different from a simple Of course, I recognise that there are assumptions about colour space being made here -- but they are incredibly minor. Sure, you could use |
Thanks for pointing that out. Scaling to unit range is yet another option. |
Complexity is the enemy of a crate aiming to standardize other crates, as such I suggest we provide only the most simple implementation of the blanket Other mappings can be trivially implemented by end-users for their particular semantics. |
|
More naming questions:
|
This seems contrary to this crates purpose in being agnostic on semantics, by providing an abstraction on a type of non-trivial conversion we are breaking our agnosticism.
This also seems to be extrapolating to particular usages, something this crate is supposed to be agnostic about, I would suggest we explicitly refuse to name and provide any such conversions.
I'm not sure I follow this one, would this not then count as an overflow since the division should happen in the larger type? |
This crate is explicitly for RGB pixels. I don't get the sense that it should be completely agnostic. Generic parameter types allow customization for special cases, but in practice the overwhelming majority of uses will be specifically on I suppose the core problem here is that a specific integer truncation gets in the way of having all methods on one |
True, perhaps if these specific conversions are really required we could offer them under an optional feature per conversion trait:
This way regular users don't have to be exposed to these methods unless they opt-in, also it is infinitely-expandable to any number of types of conversion. And it can have specific implementations between the different integer types unlike the blanket |
When converting from 8 to 16 bits (or 16 to 32, etc.), there are two ways:
Change 0x12 to 0x1212. This is semantically the same color, but with more precision.
Change 0x12 to 0x0012. This keeps the same numeric value, but makes the numeric range bigger. This is useful for arithmetic, e.g. when you calculate sums and averages of pixel values.
What do you call these operations? Are there existing libraries/standards that have established names for these functions?
And similarly conversion the other way: 0x1234 can become either 0x12 or 0x34, depending on use-cases and interpretation of the values.
How to name these things? Can the different conversions to larger and smaller types have names that are clearly opposites of each other?
The text was updated successfully, but these errors were encountered: