-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Rename Rect inset() method to inflate()
#13452
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
Rename Rect inset() method to inflate()
#13452
Conversation
alice-i-cecile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much clearer. Thanks for tackling this.
alice-i-cecile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, not quite ready. The docs on inflate (just above the changes) for both Rect and IRect need to be revised.
Thanks for taking a look at this @alice-i-cecile. Since the behavior is the same, I wonder how I could make the docs clearer. Would it be better to refer simply to a "value" that makes the Rect bigger when positive, instead of using the word "inset"? If so, maybe I could rename the parameter in the methods too. Any other suggestions? |
|
Existing docs: /// Create a new rectangle with a constant inset.
///
/// The inset is the extra border on all sides. A positive inset produces a larger rectangle,
/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative
/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty.
Proposed replacement: /// Create a new rectangle by expanding it evenly on all sides.
///
/// A positive expansion value produces a larger rectangle,
/// while a negative expansion value produces a smaller rectangle.
/// If this would result in zero or negative width or height, [`Rect::EMPTY`] is returned instead.
And then change the param name to |
|
@alice-i-cecile applied the suggested changes and also realized that the test could be renamed too. |
| /// An empty `IRect`, represented by maximum and minimum corner points | ||
| /// with all `i32::MAX` values. | ||
| pub const EMPTY: Self = Self { | ||
| max: IVec2::MAX, | ||
| min: IVec2::MAX, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use the maximum value? The docs seem to indicate that negative or zero sizes will return this empty rect, but a user might assume that in those cases its size would be limited to zero, not jump to the max value.
Some users may be storing positional data and stuff in these rects, meaning that jumping to the max value could be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW the behavior of the method was not changed, so it's not that we're explicitly returning these constants. It's a good point though, I just followed the requirements from the original issue. Might be good to open a new one if this is something we should address later, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EMPTY rect should be one in which max is set to MIN and min is set to MAX. In other words, it's a rectangle of infinite negative size.
This is a common practice in many other geometry libraries. The reasoning is simple: an empty rectangle is often used when calculating the union of a series of rectangles (that is, the outer bounds of all of them.). The union of a finite rect A with a negative infinite rect B is just A. So we can start with an empty rect and successively union with each rectangle in turn, using a classic "reduce" or "fold" method.
Note that the EMPTY rect is not the same as a zero-size rect. The rect that is the result of too much negative inflation is not the same as EMPTY because it is still centered at the point of the original rect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I like that convention. We should change to that and clearly document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mnmaita this might be better saved for a followup PR. Not sure we want to change these kinds of semantics in what's supposed to be a rename PR.
Objective
Solution
inset()method inRect,IRectandURecttoinflate().EMPTYconstants to allRectvariants, represented by corners with the maximum numerical values for each kind.Migration Guide
Rect::inset(),IRect::inset()andURect::inset()calls withinflate().