1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +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

@ -29,7 +29,7 @@ public:
return adopt_ref(*new Typed2DBuffer(buffer));
}
void fill(T value, Gfx::IntRect const& rect) { m_buffer->fill(value, rect.left(), rect.right(), rect.top(), rect.bottom(), 0, 0); }
void fill(T value, Gfx::IntRect const& rect) { m_buffer->fill(value, rect.left(), rect.right(), rect.top(), rect.bottom(), 0, 1); }
ALWAYS_INLINE T* scanline(int y) { return m_buffer->buffer_pointer(0, y, 0); }
ALWAYS_INLINE T const* scanline(int y) const { return m_buffer->buffer_pointer(0, y, 0); }
@ -40,7 +40,7 @@ public:
int source_y = 0;
// NOTE: we are flipping the Y-coordinate here, which is OpenGL-specific: (0, 0) is considered the lower-left corner of the window
for (int y = target.bottom(); y >= target.top(); --y) {
for (int y = target.bottom() - 1; y >= target.top(); --y) {
auto const* buffer_scanline = scanline(source_y++);
auto* bitmap_scanline = bitmap.scanline(y);
memcpy(bitmap_scanline + target.left(), buffer_scanline, sizeof(u32) * target.width());

View file

@ -41,10 +41,10 @@ public:
void fill(T value, int x1, int x2, int y1, int y2, int z1, int z2)
{
for (auto z = z1; z <= z2; ++z) {
for (auto y = y1; y <= y2; ++y) {
for (auto z = z1; z < z2; ++z) {
for (auto y = y1; y < y2; ++y) {
auto* xline = buffer_pointer(0, y, z);
for (auto x = x1; x <= x2; ++x)
for (auto x = x1; x < x2; ++x)
xline[x] = value;
}
}

View file

@ -231,9 +231,9 @@ ALWAYS_INLINE void Device::rasterize(Gfx::IntRect& render_bounds, CB1 set_covera
// Quad bounds
auto const render_bounds_left = render_bounds.left();
auto const render_bounds_right = render_bounds.right();
auto const render_bounds_right = render_bounds.right() - 1;
auto const render_bounds_top = render_bounds.top();
auto const render_bounds_bottom = render_bounds.bottom();
auto const render_bounds_bottom = render_bounds.bottom() - 1;
auto const qx0 = render_bounds_left & ~1;
auto const qx1 = render_bounds_right & ~1;
auto const qy0 = render_bounds_top & ~1;
@ -678,9 +678,9 @@ void Device::rasterize_triangle(Triangle& triangle)
// Calculate render bounds based on the triangle's vertices
Gfx::IntRect render_bounds;
render_bounds.set_left(min(min(v0.x(), v1.x()), v2.x()) / subpixel_factor);
render_bounds.set_right(max(max(v0.x(), v1.x()), v2.x()) / subpixel_factor);
render_bounds.set_right(max(max(v0.x(), v1.x()), v2.x()) / subpixel_factor + 1);
render_bounds.set_top(min(min(v0.y(), v1.y()), v2.y()) / subpixel_factor);
render_bounds.set_bottom(max(max(v0.y(), v1.y()), v2.y()) / subpixel_factor);
render_bounds.set_bottom(max(max(v0.y(), v1.y()), v2.y()) / subpixel_factor + 1);
// Calculate depth of fragment for fog;
// OpenGL 1.5 chapter 3.10: "An implementation may choose to approximate the