aseprite / laf

A C++ library to create desktop applications
https://aseprite.github.io/laf/
MIT License
276 stars 60 forks source link

Add Rect floor function #44

Closed Gasparoken closed 2 years ago

Gasparoken commented 2 years ago

This 'floor' function is useful to adjust x, y float coordinates to the left most near integer for x, and top most near integer for y (instead of rounding towards 0). This function was included to solve issue aseprite/aseprite#2891

Example of use:

gfx::RectF boundsF(-0.25, -0.75, 1, 2);
gfx::Rect bounds = boundsF.floor();
bounds = (-1, -1, 1, 2)

When 'floor' is not used:

gfx::RectF boundsF(-0.25, -0.75, 1, 2);
gfx::Rect bounds = boundsF;
bounds = (0, 0, 1, 2)
dacap commented 2 years ago

Should this floor the size of the rectangle too? or should we call the function floorOrigin()?

dacap commented 2 years ago

I forgot to mention that there is no need to mention the issue in the code, the commit already will include that information.

Gasparoken commented 2 years ago

Should this floor the size of the rectangle too? or should we call the function floorOrigin()?

Since Rect size (w, h) are greater than 0, I think isn't need to apply floor on size. Yes, we can call floorOrigin() if you like.

dacap commented 2 years ago

Oh I see, we can keep floor() in that case, I'll merge this ASAP 👍

dacap commented 2 years ago

Merged in https://github.com/aseprite/laf/commit/871adbe48bc85cff8de08d243df1f42fc9f1f7e9 with a test.