1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +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:
Jelle Raaijmakers 2023-05-22 00:41:18 +02:00 committed by Andreas Kling
parent b7f4363791
commit f391ccfe53
88 changed files with 524 additions and 518 deletions

View file

@ -133,9 +133,8 @@ Gfx::Bitmap& Layer::get_scratch_edited_bitmap()
RefPtr<Gfx::Bitmap> Layer::copy_bitmap(Selection const& selection) const
{
if (selection.is_empty()) {
if (selection.is_empty())
return {};
}
auto selection_rect = selection.bounding_rect();
auto bitmap_or_error = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, selection_rect.size());
@ -144,9 +143,8 @@ RefPtr<Gfx::Bitmap> Layer::copy_bitmap(Selection const& selection) const
auto result = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
VERIFY(result->has_alpha_channel());
for (int y = selection_rect.top(); y <= selection_rect.bottom(); y++) {
for (int x = selection_rect.left(); x <= selection_rect.right(); x++) {
for (int y = selection_rect.top(); y < selection_rect.bottom(); y++) {
for (int x = selection_rect.left(); x < selection_rect.right(); x++) {
Gfx::IntPoint image_point { x, y };
auto layer_point = image_point - m_location;
auto result_point = image_point - selection_rect.top_left();
@ -180,9 +178,8 @@ void Layer::erase_selection(Selection const& selection)
for (int x = translated_to_layer_space.left(); x < translated_to_layer_space.left() + translated_to_layer_space.width(); ++x) {
// Selection is still in pre-translated coordinates, account for this by adding the layer's relative location
if (content_bitmap().rect().contains(x, y) && selection.is_selected(x + location().x(), y + location().y())) {
if (content_bitmap().rect().contains(x, y) && selection.is_selected(x + location().x(), y + location().y()))
content_bitmap().set_pixel(x, y, Color::Transparent);
}
}
}