From e7c24bf415e03e3264f56aa1054d9795bf303c98 Mon Sep 17 00:00:00 2001 From: RobotMan2412 Date: Mon, 12 Feb 2024 17:59:52 +0100 Subject: [PATCH] Fix rounding logic --- src/helpers/pax_dh_generic_rect.hpp | 8 ++++---- src/helpers/pax_dh_mcr_shaded.cpp | 2 +- src/helpers/pax_dh_shaded.cpp | 2 +- src/pax_matrix.h | 6 +++--- src/pax_text.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/helpers/pax_dh_generic_rect.hpp b/src/helpers/pax_dh_generic_rect.hpp index c675ea0..bb2c478 100644 --- a/src/helpers/pax_dh_generic_rect.hpp +++ b/src/helpers/pax_dh_generic_rect.hpp @@ -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 diff --git a/src/helpers/pax_dh_mcr_shaded.cpp b/src/helpers/pax_dh_mcr_shaded.cpp index 7c4f11a..7c290d0 100644 --- a/src/helpers/pax_dh_mcr_shaded.cpp +++ b/src/helpers/pax_dh_mcr_shaded.cpp @@ -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, diff --git a/src/helpers/pax_dh_shaded.cpp b/src/helpers/pax_dh_shaded.cpp index 8be48d3..846d311 100644 --- a/src/helpers/pax_dh_shaded.cpp +++ b/src/helpers/pax_dh_shaded.cpp @@ -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; } diff --git a/src/pax_matrix.h b/src/pax_matrix.h index 4948043..e2988cc 100644 --- a/src/pax_matrix.h +++ b/src/pax_matrix.h @@ -49,8 +49,8 @@ typedef struct matrix_stack_2d matrix_stack_2d_t; #ifdef __cplusplus #include -#include #include +#include namespace pax { @@ -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; \ } \ @@ -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. diff --git a/src/pax_text.c b/src/pax_text.c index c073387..3a6e10a 100644 --- a/src/pax_text.c +++ b/src/pax_text.c @@ -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