Skip to content

Commit

Permalink
Fix rounding logic
Browse files Browse the repository at this point in the history
  • Loading branch information
robotman2412 committed Feb 12, 2024
1 parent eb787ac commit e7c24bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/helpers/pax_dh_generic_rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ static

#if defined(PDHG_NORMAL_UV) || defined(PDHG_RESTRICT_UV)
// Adjust UVs to match pixel co-ordinates.
fixpt_t min_x = (int)(x + 0.5) + 0.5;
fixpt_t max_x = (int)(x + width - 0.5) + 0.5;
fixpt_t min_y = (int)(y + 0.5) + 0.5;
fixpt_t max_y = (int)(y + height - 0.5) + 0.5;
fixpt_t min_x = floorf(x + 0.5) + 0.5;
fixpt_t max_x = floorf(x + width - 0.5) + 0.5;
fixpt_t min_y = floorf(y + 0.5) + 0.5;
fixpt_t max_y = floorf(y + height - 0.5) + 0.5;
#endif

#ifdef PDHG_NORMAL_UV
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/pax_dh_mcr_shaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void paxmcr_rect_shaded(
if ((shader->callback == pax_shader_texture || shader->callback == pax_shader_texture_aa) && color == 0xffffffff) {
// Use a more direct copying of textures.
pax_buf_t *top = (pax_buf_t *)shader->callback_args;
if (is_default_uv && (int)(width + 0.5) == top->width && (int)(height + 0.5) == top->height) {
if (is_default_uv && roundf(width) == top->width && roundf(height) == top->height) {
paxmcr_overlay_buffer(
odd_scanline,
buf,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/pax_dh_shaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void pax_rect_shaded(
if ((shader->callback == pax_shader_texture || shader->callback == pax_shader_texture_aa) && color == 0xffffffff) {
// Use a more direct copying of textures.
pax_buf_t *top = (pax_buf_t *)shader->callback_args;
if (is_default_uv && (int)(width + 0.5) == top->width && (int)(height + 0.5) == top->height) {
if (is_default_uv && roundf(width) == top->width && roundf(height) == top->height) {
pax_overlay_buffer(buf, top, x + 0.5, y + 0.5, width + 0.5, height + 0.5, shader->alpha_promise_255);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/pax_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ typedef struct matrix_stack_2d matrix_stack_2d_t;

#ifdef __cplusplus
#include <assert.h>
#include <memory>
#include <initializer_list>
#include <memory>

namespace pax {

Expand Down Expand Up @@ -129,7 +129,7 @@ typedef struct matrix_stack_2d Matrix2fStack;
_type out; \
const size_t _size = sizeof(arr) / sizeof(float); \
for (size_t i = 0; i < _size; i++) { \
out.arr[i] = (int)(arr[i] + 0.5); \
out.arr[i] = roundf(arr[i]); \
} \
return out; \
} \
Expand Down Expand Up @@ -567,7 +567,7 @@ PAX_CXX_Vecf_union struct_pax_rectf {
}

pax::Rectf round() const {
return pax::Rectf{(float)(int)(x + 0.5), (float)(int)(y + 0.5), (float)(int)(w + 0.5), (float)(int)(h + 0.5)};
return pax::Rectf{floorf(x), floorf(y), floorf(w), floorf(h)};
}

// Get average position, i.e. center, of the rectangle.
Expand Down
4 changes: 2 additions & 2 deletions src/pax_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ static void pixel_aligned_render(
float height
) {
// Offset and pixel-align co-ordinates.
x = (int)(0.5 + x + buf->stack_2d.value.a2);
y = (int)(0.5 + y + buf->stack_2d.value.b2);
x = floorf(0.5 + x + buf->stack_2d.value.a2);
y = floorf(0.5 + y + buf->stack_2d.value.b2);
pax_mark_dirty2(buf, x, y, width, height);

#if PAX_COMPILE_ORIENTATION
Expand Down

0 comments on commit e7c24bf

Please sign in to comment.