Val::MAX constant - #25096
Conversation
|
|
||
| /// Maximum curvature. The UI Node will take a capsule shape or circular if width and height are equal. | ||
| pub const MAX: Self = Self::all_circular(Val::Px(f32::MAX)); | ||
| pub const MAX: Self = Self::all_circular(Val::MAX); |
There was a problem hiding this comment.
Is it confusing that “px” has now been lost at call sites though? I suppose MAX matches what ZERO does, but possibly 0 is the same end result whether it’s in pixels or percents but is f32::MAX pixels the same as f32::MAX percent?
Also if I think of a maximum value of percentage units, I tend to think of that as 100% even though I know you can definitely provide a larger f32 than 100.0 when constructing a percentage Val.
There was a problem hiding this comment.
Oops yeah, what's written in the objective about wrapping f32::MAX by an arbitrary variant is wrong, I was just struggling to think of something smart to say hehe.
Using Val::percent(f32::Max) is not a good idea. The base value could be 0. in which case the resolved value will be 0., or inf if it's greater than 1.
Maybe that's an argument in favor of having a constant though, if you naively try to express a maximum value using one of the non-Px variants you might end up with a panic
There was a problem hiding this comment.
Using Val::percent(f32::Max) is not a good idea.
Yep I'm not surprised this is a bad idea. I was just using f32::Max for percents as a way to argue the question "why do pixels/Px get to claim the MAX name under Val even though there are many enum variants in it"?
Thinking about the change though, the const here is BorderRadius::Max and that's the one users are going to use, but it's really just an implementation detail what you put on the right hand side of that, right? Self::all_circular(Val::Px(f32::MAX)); seems a fine thing to put on the right hand side of it, and it seems fine for that to read as an implementation detail, no? That said, if there are cases where users want Val::MAX themselves, then maybe the const (or similar) is good to add, but do you think those use cases exist, or is Val::MAX really the only "user" here?
| impl Val { | ||
| pub const DEFAULT: Self = Self::Auto; | ||
| pub const ZERO: Self = Self::Px(0.0); | ||
| pub const MAX: Self = Self::Px(f32::MAX); |
There was a problem hiding this comment.
Docs on this and Zero that they're in Px units please.
Objective
ATM you wrap
f32::MAXby an arbitrary scalarValvariant to express a maximum value,To make it clearer that a max value is being used intentionally, add a canonical
Val::MAXconstant.Solution
Add a
Val::MAXconstant equal toVal::Px(f32::MAX)