mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
LibGfx+Everywhere: Change Gfx::Rect
to be endpoint exclusive
Previously, calling `.right()` on a `Gfx::Rect` would return the last column's coordinate still inside the rectangle, or `left + width - 1`. This is called 'endpoint inclusive' and does not make a lot of sense for `Gfx::Rect<float>` where a rectangle of width 5 at position (0, 0) would return 4 as its right side. This same problem exists for `.bottom()`. This changes `Gfx::Rect` to be endpoint exclusive, which gives us the nice property that `width = right - left` and `height = bottom - top`. It enables us to treat `Gfx::Rect<int>` and `Gfx::Rect<float>` exactly the same. All users of `Gfx::Rect` have been updated accordingly.
This commit is contained in:
parent
b7f4363791
commit
f391ccfe53
88 changed files with 524 additions and 518 deletions
|
@ -60,8 +60,8 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
|
|||
auto const distance_from = [&](float v, float a, float b, auto distance_function) {
|
||||
return distance_function(fabs(a - v), fabs(b - v));
|
||||
};
|
||||
auto x_dist = distance_from(center.x(), size.left(), size.right(), distance_function);
|
||||
auto y_dist = distance_from(center.y(), size.top(), size.bottom(), distance_function);
|
||||
auto x_dist = distance_from(center.x(), size.left(), size.right() - 1, distance_function);
|
||||
auto y_dist = distance_from(center.y(), size.top(), size.bottom() - 1, distance_function);
|
||||
if (m_properties.ending_shape == EndingShape::Circle) {
|
||||
auto dist = distance_function(x_dist, y_dist);
|
||||
return Gfx::FloatSize { dist, dist };
|
||||
|
@ -80,20 +80,20 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
|
|||
|
||||
auto const corner_distance = [&](auto distance_compare, Gfx::FloatPoint& corner) {
|
||||
auto top_left_distance = size.top_left().distance_from(center);
|
||||
auto top_right_distance = size.top_right().distance_from(center);
|
||||
auto bottom_right_distance = size.bottom_right().distance_from(center);
|
||||
auto bottom_left_distance = size.bottom_left().distance_from(center);
|
||||
auto top_right_distance = size.top_right().moved_left(1).distance_from(center);
|
||||
auto bottom_right_distance = size.bottom_right().translated(-1).distance_from(center);
|
||||
auto bottom_left_distance = size.bottom_left().moved_up(1).distance_from(center);
|
||||
auto distance = top_left_distance;
|
||||
if (distance_compare(top_right_distance, distance)) {
|
||||
corner = size.top_right();
|
||||
corner = size.top_right().translated(-1, 0);
|
||||
distance = top_right_distance;
|
||||
}
|
||||
if (distance_compare(bottom_right_distance, distance)) {
|
||||
corner = size.top_right();
|
||||
corner = size.top_right().translated(-1, 0);
|
||||
distance = bottom_right_distance;
|
||||
}
|
||||
if (distance_compare(bottom_left_distance, distance)) {
|
||||
corner = size.top_right();
|
||||
corner = size.top_right().translated(-1, 0);
|
||||
distance = bottom_left_distance;
|
||||
}
|
||||
return distance;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue