diff --git a/core/io/image.cpp b/core/io/image.cpp index 76693f98d57..51506258725 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -799,7 +799,7 @@ Image::Format Image::get_format() const { } static double _bicubic_interp_kernel(double x) { - x = ABS(x); + x = Math::abs(x); double bc = 0; diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 7e0e982c624..16dd7a32f5f 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -34,27 +34,27 @@ #include "core/variant/typed_array.h" static real_t heuristic_euclidean(const Vector2i &p_from, const Vector2i &p_to) { - real_t dx = (real_t)ABS(p_to.x - p_from.x); - real_t dy = (real_t)ABS(p_to.y - p_from.y); + real_t dx = (real_t)Math::abs(p_to.x - p_from.x); + real_t dy = (real_t)Math::abs(p_to.y - p_from.y); return (real_t)Math::sqrt(dx * dx + dy * dy); } static real_t heuristic_manhattan(const Vector2i &p_from, const Vector2i &p_to) { - real_t dx = (real_t)ABS(p_to.x - p_from.x); - real_t dy = (real_t)ABS(p_to.y - p_from.y); + real_t dx = (real_t)Math::abs(p_to.x - p_from.x); + real_t dy = (real_t)Math::abs(p_to.y - p_from.y); return dx + dy; } static real_t heuristic_octile(const Vector2i &p_from, const Vector2i &p_to) { - real_t dx = (real_t)ABS(p_to.x - p_from.x); - real_t dy = (real_t)ABS(p_to.y - p_from.y); + real_t dx = (real_t)Math::abs(p_to.x - p_from.x); + real_t dy = (real_t)Math::abs(p_to.y - p_from.y); real_t F = Math_SQRT2 - 1; return (dx < dy) ? F * dx + dy : F * dy + dx; } static real_t heuristic_chebyshev(const Vector2i &p_from, const Vector2i &p_to) { - real_t dx = (real_t)ABS(p_to.x - p_from.x); - real_t dy = (real_t)ABS(p_to.y - p_from.y); + real_t dx = (real_t)Math::abs(p_to.x - p_from.x); + real_t dy = (real_t)Math::abs(p_to.y - p_from.y); return MAX(dx, dy); } diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index a841d5c0398..f80499eaf58 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -186,7 +186,7 @@ class Delaunay3D { Plane p(p_points[p_simplex.points[i]], p_points[p_simplex.points[(i + 1) % 4]], p_points[p_simplex.points[(i + 2) % 4]]); // This tolerance should not be smaller than the one used with // Plane::has_point() when creating the LightmapGI probe BSP tree. - if (ABS(p.distance_to(p_points[p_simplex.points[(i + 3) % 4]])) < 0.001) { + if (Math::abs(p.distance_to(p_points[p_simplex.points[(i + 3) % 4]])) < 0.001) { return true; } } diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 1dff0ee4a6f..b9ab85e4af0 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -263,7 +263,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform, // check if edge is valid as a support real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n); - dot = ABS(dot); + dot = Math::abs(dot); if (dot < edge_support_threshold) { *p_count = MIN(2, p_max); diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 361a0607b5d..beb46aa371c 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -593,7 +593,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector &p_planes Vector3 ref = Vector3(0.0, 1.0, 0.0); - if (ABS(p.normal.dot(ref)) > 0.95f) { + if (Math::abs(p.normal.dot(ref)) > 0.95f) { ref = Vector3(0.0, 0.0, 1.0); // Change axis. } diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h index 26237a50bea..f4ab7361814 100644 --- a/core/math/geometry_3d.h +++ b/core/math/geometry_3d.h @@ -419,7 +419,7 @@ public: real_t ad = axis.dot(n2); - if (ABS(ad) > p_sphere_radius) { + if (Math::abs(ad) > p_sphere_radius) { // No chance with this edge, too far away. continue; } diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index ce879b67f79..47e5b7c65b7 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -221,7 +221,10 @@ public: static _ALWAYS_INLINE_ double abs(double g) { return absd(g); } static _ALWAYS_INLINE_ float abs(float g) { return absf(g); } - static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; } + static _ALWAYS_INLINE_ int8_t abs(int8_t g) { return g > 0 ? g : -g; } + static _ALWAYS_INLINE_ int16_t abs(int16_t g) { return g > 0 ? g : -g; } + static _ALWAYS_INLINE_ int32_t abs(int32_t g) { return ::abs(g); } + static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return ::llabs(g); } static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) { double value = Math::fmod(p_x, p_y); diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 5422fa9ca81..74783b2a692 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -58,7 +58,7 @@ Vector3 Plane::get_any_perpendicular_normal() const { static const Vector3 p2 = Vector3(0, 1, 0); Vector3 p; - if (ABS(normal.dot(p1)) > 0.99f) { // if too similar to p1 + if (Math::abs(normal.dot(p1)) > 0.99f) { // if too similar to p1 p = p2; // use p2 } else { p = p1; // use p1 diff --git a/core/math/plane.h b/core/math/plane.h index ef1d2f487e5..77a53e578d3 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -100,7 +100,7 @@ real_t Plane::distance_to(const Vector3 &p_point) const { bool Plane::has_point(const Vector3 &p_point, real_t p_tolerance) const { real_t dist = normal.dot(p_point) - d; - dist = ABS(dist); + dist = Math::abs(dist); return (dist <= p_tolerance); } diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 00a2d4b2bb6..a180176fc38 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1716,7 +1716,7 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) { c[chars] = 0; n = p_num; do { - int mod = ABS(n % base); + int mod = Math::abs(n % base); if (mod >= 10) { char a = (capitalize_hex ? 'A' : 'a'); c[--chars] = a + (mod - 10); @@ -5593,7 +5593,7 @@ String String::sprintf(const Array &values, bool *error) const { // Get basic number. String str; if (!as_unsigned) { - str = String::num_int64(ABS(value), base, capitalize); + str = String::num_int64(Math::abs(value), base, capitalize); } else { uint64_t uvalue = *((uint64_t *)&value); // In unsigned hex, if the value fits in 32 bits, trim it down to that. diff --git a/core/typedefs.h b/core/typedefs.h index 576f6a686d0..46e67cb733e 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -107,18 +107,11 @@ static_assert(__cplusplus >= 201703L); #endif // Make room for our constexpr's below by overriding potential system-specific macros. -#undef ABS #undef SIGN #undef MIN #undef MAX #undef CLAMP -// Generic ABS function, for math uses please use Math::abs. -template -constexpr T ABS(T m_v) { - return m_v < 0 ? -m_v : m_v; -} - template constexpr const T SIGN(const T m_v) { return m_v > 0 ? +1.0f : (m_v < 0 ? -1.0f : 0.0f); diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 1bcd8299da8..b07cc2a85b9 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -244,7 +244,7 @@ Variant VariantUtilityFunctions::abs(const Variant &x, Callable::CallError &r_er r_error.error = Callable::CallError::CALL_OK; switch (x.get_type()) { case Variant::INT: { - return ABS(VariantInternalAccessor::get(&x)); + return Math::abs(VariantInternalAccessor::get(&x)); } break; case Variant::FLOAT: { return Math::absd(VariantInternalAccessor::get(&x)); @@ -281,7 +281,7 @@ double VariantUtilityFunctions::absf(double x) { } int64_t VariantUtilityFunctions::absi(int64_t x) { - return ABS(x); + return Math::abs(x); } Variant VariantUtilityFunctions::sign(const Variant &x, Callable::CallError &r_error) { diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 31c0bb8af2d..d6c9c26f332 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -1767,7 +1767,7 @@ void RasterizerCanvasGLES3::light_update_directional_shadow(RID p_rid, int p_sha Vector2 center = p_clip_rect.get_center(); - float to_edge_distance = ABS(light_dir.dot(p_clip_rect.get_support(-light_dir)) - light_dir.dot(center)); + float to_edge_distance = Math::abs(light_dir.dot(p_clip_rect.get_support(-light_dir)) - light_dir.dot(center)); Vector2 from_pos = center - light_dir * (to_edge_distance + p_cull_distance); float distance = to_edge_distance * 2.0 + p_cull_distance; diff --git a/drivers/gles3/storage/light_storage.cpp b/drivers/gles3/storage/light_storage.cpp index 36c2514c493..b7cd22de9fc 100644 --- a/drivers/gles3/storage/light_storage.cpp +++ b/drivers/gles3/storage/light_storage.cpp @@ -1181,7 +1181,7 @@ void LightStorage::lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, return; // Nothing could be done. } - node = ABS(node) - 1; + node = Math::abs(node) - 1; uint32_t *tetrahedron = (uint32_t *)&lm->tetrahedra[node * 4]; Vector3 points[4] = { lm->points[tetrahedron[0]], lm->points[tetrahedron[1]], lm->points[tetrahedron[2]], lm->points[tetrahedron[3]] }; diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp index 28b3a3b6489..70d10ecf102 100644 --- a/drivers/wasapi/audio_driver_wasapi.cpp +++ b/drivers/wasapi/audio_driver_wasapi.cpp @@ -458,7 +458,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_i // so we need to select the closest multiple to the user-specified latency. UINT32 desired_period_frames = target_latency_ms * mix_rate / 1000; UINT32 period_frames = (desired_period_frames / fundamental_period_frames) * fundamental_period_frames; - if (ABS((int64_t)period_frames - (int64_t)desired_period_frames) > ABS((int64_t)(period_frames + fundamental_period_frames) - (int64_t)desired_period_frames)) { + if (Math::abs((int64_t)period_frames - (int64_t)desired_period_frames) > Math::abs((int64_t)(period_frames + fundamental_period_frames) - (int64_t)desired_period_frames)) { period_frames = period_frames + fundamental_period_frames; } period_frames = CLAMP(period_frames, min_period_frames, max_period_frames); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 516d9a0017d..e36790e3467 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -2806,7 +2806,7 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { if (rect.has_point(p_pos)) { if (const_cast(this)->is_key_selectable_by_distance()) { - float distance = ABS(offset - p_pos.x); + float distance = Math::abs(offset - p_pos.x); if (key_idx == -1 || distance < key_distance) { key_idx = i; key_distance = distance; @@ -3211,7 +3211,7 @@ void AnimationTrackEdit::gui_input(const Ref &p_event) { if (rect.has_point(pos)) { if (is_key_selectable_by_distance()) { - const float distance = ABS(offset - pos.x); + const float distance = Math::abs(offset - pos.x); if (key_idx == -1 || distance < key_distance) { key_idx = i; key_distance = distance; @@ -3275,7 +3275,7 @@ bool AnimationTrackEdit::_try_select_at_ui_pos(const Point2 &p_pos, bool p_aggre if (rect.has_point(p_pos)) { if (is_key_selectable_by_distance()) { - float distance = ABS(offset - p_pos.x); + float distance = Math::abs(offset - p_pos.x); if (key_idx == -1 || distance < key_distance) { key_idx = i; key_distance = distance; @@ -6737,7 +6737,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { to_restore.push_back(amr); } -#define NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * ABS(s) + from_t +#define NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * Math::abs(s) + from_t // 3 - Move the keys (re insert them). for (RBMap::Element *E = selection.back(); E; E = E->prev()) { float newpos = NEW_POS(E->get().pos); @@ -8675,7 +8675,7 @@ String AnimationMarkerEdit::get_tooltip(const Point2 &p_pos) const { if (rect.has_point(p_pos)) { if (const_cast(this)->is_key_selectable_by_distance()) { - float distance = ABS(offset - p_pos.x); + float distance = Math::abs(offset - p_pos.x); if (key_idx == -1 || distance < key_distance) { key_idx = i; key_distance = distance; diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index dc6d9c77d68..3bb10755865 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -1051,13 +1051,13 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref &p_event) { int end = ofs + len * get_timeline()->get_zoom_scale(); - if (end >= get_timeline()->get_name_limit() && end <= get_size().width - get_timeline()->get_buttons_width() && ABS(mm->get_position().x - end) < 5 * EDSCALE) { + if (end >= get_timeline()->get_name_limit() && end <= get_size().width - get_timeline()->get_buttons_width() && Math::abs(mm->get_position().x - end) < 5 * EDSCALE) { len_resizing_start = false; use_hsize_cursor = true; len_resizing_index = i; } - if (ofs >= get_timeline()->get_name_limit() && ofs <= get_size().width - get_timeline()->get_buttons_width() && ABS(mm->get_position().x - ofs) < 5 * EDSCALE) { + if (ofs >= get_timeline()->get_name_limit() && ofs <= get_size().width - get_timeline()->get_buttons_width() && Math::abs(mm->get_position().x - ofs) < 5 * EDSCALE) { len_resizing_start = true; use_hsize_cursor = true; len_resizing_index = i; diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 8406984b2a2..53793f35251 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -146,7 +146,7 @@ String EditorProfiler::_get_time_as_text(const Metric &m, float p_time, int p_ca Color EditorProfiler::_get_color_from_signature(const StringName &p_signature) const { Color bc = get_theme_color(SNAME("error_color"), EditorStringName(Editor)); - double rot = ABS(double(p_signature.hash()) / double(0x7FFFFFFF)); + double rot = Math::abs(double(p_signature.hash()) / double(0x7FFFFFFF)); Color c; c.set_hsv(rot, bc.get_s(), bc.get_v()); return c.lerp(get_theme_color(SNAME("base_color"), EditorStringName(Editor)), 0.07); diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index 4d1667b8478..e6c43ffe19d 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -136,7 +136,7 @@ String EditorVisualProfiler::_get_time_as_text(float p_time) { Color EditorVisualProfiler::_get_color_from_signature(const StringName &p_signature) const { Color bc = get_theme_color(SNAME("error_color"), EditorStringName(Editor)); - double rot = ABS(double(p_signature.hash()) / double(0x7FFFFFFF)); + double rot = Math::abs(double(p_signature.hash()) / double(0x7FFFFFFF)); Color c; c.set_hsv(rot, bc.get_s(), bc.get_v()); return c.lerp(get_theme_color(SNAME("base_color"), EditorStringName(Editor)), 0.07); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index f183cbaaafb..b4c78710370 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -885,7 +885,7 @@ void EditorPropertyArray::_reorder_button_gui_input(const Ref &p_eve } float required_y_distance = 20.0f * EDSCALE; - if (ABS(reorder_mouse_y_delta) > required_y_distance) { + if (Math::abs(reorder_mouse_y_delta) > required_y_distance) { int direction = reorder_mouse_y_delta > 0.0f ? 1 : -1; reorder_mouse_y_delta -= required_y_distance * direction; diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index a9d8e3ae6c6..5461c9b8773 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -95,7 +95,7 @@ void EditorSpinSlider::gui_input(const Ref &p_event) { } grabbing_spinner_dist_cache += diff_x * grabbing_spinner_speed; - if (!grabbing_spinner && ABS(grabbing_spinner_dist_cache) > 4 * grabbing_spinner_speed * EDSCALE) { + if (!grabbing_spinner && Math::abs(grabbing_spinner_dist_cache) > 4 * grabbing_spinner_speed * EDSCALE) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); grabbing_spinner = true; } diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 540e364a721..416073eae1a 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -423,7 +423,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref &p_event) //Move the point in a single axis. Should only work when editing a polygon and while holding shift. if (mode == MODE_EDIT && mm->is_shift_pressed()) { Vector2 old_point = pre_move_edit.get(selected_point.vertex); - if (ABS(cpoint.x - old_point.x) > ABS(cpoint.y - old_point.y)) { + if (Math::abs(cpoint.x - old_point.x) > Math::abs(cpoint.y - old_point.y)) { cpoint.y = old_point.y; } else { cpoint.x = old_point.x; diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 9aaf2c1d560..2586ab4216f 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -464,14 +464,14 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Refget_node_position(E); - float d_x = ABS(npos.x - cpos.x); + float d_x = Math::abs(npos.x - cpos.x); if (d_x < MIN(5, best_d_x)) { drag_ofs.x -= cpos.x - npos.x; best_d_x = d_x; snap_x = E; } - float d_y = ABS(npos.y - cpos.y); + float d_y = Math::abs(npos.y - cpos.y); if (d_y < MIN(5, best_d_y)) { drag_ofs.y -= cpos.y - npos.y; best_d_y = d_y; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index b365e6f11a9..423b6e0f841 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1116,7 +1116,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve if (m.is_valid() && m->get_position().x < RULER_WIDTH) { // Check if we are hovering an existing horizontal guide for (int i = 0; i < hguides.size(); i++) { - if (ABS(xform.xform(Point2(0, hguides[i])).y - m->get_position().y) < MIN(minimum, 8)) { + if (Math::abs(xform.xform(Point2(0, hguides[i])).y - m->get_position().y) < MIN(minimum, 8)) { is_hovering_h_guide = true; is_hovering_v_guide = false; break; @@ -1126,7 +1126,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve } else if (m.is_valid() && m->get_position().y < RULER_WIDTH) { // Check if we are hovering an existing vertical guide for (int i = 0; i < vguides.size(); i++) { - if (ABS(xform.xform(Point2(vguides[i], 0)).x - m->get_position().x) < MIN(minimum, 8)) { + if (Math::abs(xform.xform(Point2(vguides[i], 0)).x - m->get_position().x) < MIN(minimum, 8)) { is_hovering_v_guide = true; is_hovering_h_guide = false; break; @@ -1146,7 +1146,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve // Check if we drag an existing horizontal guide dragged_guide_index = -1; for (int i = 0; i < hguides.size(); i++) { - if (ABS(xform.xform(Point2(0, hguides[i])).y - b->get_position().y) < MIN(minimum, 8)) { + if (Math::abs(xform.xform(Point2(0, hguides[i])).y - b->get_position().y) < MIN(minimum, 8)) { dragged_guide_index = i; } } @@ -1163,7 +1163,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve // Check if we drag an existing vertical guide dragged_guide_index = -1; for (int i = 0; i < vguides.size(); i++) { - if (ABS(xform.xform(Point2(vguides[i], 0)).x - b->get_position().x) < MIN(minimum, 8)) { + if (Math::abs(xform.xform(Point2(vguides[i], 0)).x - b->get_position().x) < MIN(minimum, 8)) { dragged_guide_index = i; } } @@ -2220,7 +2220,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { bool single_axis = m->is_shift_pressed(); if (single_axis) { - if (ABS(new_pos.x - previous_pos.x) > ABS(new_pos.y - previous_pos.y)) { + if (Math::abs(new_pos.x - previous_pos.x) > Math::abs(new_pos.y - previous_pos.y)) { new_pos.y = previous_pos.y; } else { new_pos.x = previous_pos.x; @@ -3240,14 +3240,14 @@ void CanvasItemEditor::_draw_ruler_tool() { : (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 : Math_PI / 2.0 - vertical_angle_rad); real_t arc_1_end_angle = arc_1_start_angle + vertical_angle_rad; // Constrain arc to triangle height & max size. - real_t arc_1_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, ABS(end_to_begin.y)), arc_max_radius); + real_t arc_1_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, Math::abs(end_to_begin.y)), arc_max_radius); real_t arc_2_start_angle = end_to_begin.x < 0 ? (end_to_begin.y < 0 ? 0.0 : -horizontal_angle_rad) : (end_to_begin.y < 0 ? Math_PI - horizontal_angle_rad : Math_PI); real_t arc_2_end_angle = arc_2_start_angle + horizontal_angle_rad; // Constrain arc to triangle width & max size. - real_t arc_2_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, ABS(end_to_begin.x)), arc_max_radius); + real_t arc_2_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, Math::abs(end_to_begin.x)), arc_max_radius); viewport->draw_arc(begin, arc_1_radius, arc_1_start_angle, arc_1_end_angle, arc_point_count, ruler_primary_color, Math::round(EDSCALE * arc_line_width)); viewport->draw_arc(end, arc_2_radius, arc_2_start_angle, arc_2_end_angle, arc_point_count, ruler_primary_color, Math::round(EDSCALE * arc_line_width)); @@ -3288,13 +3288,13 @@ void CanvasItemEditor::_draw_ruler_tool() { h_angle_text_pos.x = CLAMP(end.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); if (begin.y < end.y) { h_angle_text_pos.y = end.y + text_height * 1.5; - if (ABS(text_pos2.x - h_angle_text_pos.x) < text_width) { + if (Math::abs(text_pos2.x - h_angle_text_pos.x) < text_width) { int height_multiplier = 1.5 + (int)grid_snap_active; h_angle_text_pos.y = MAX(text_pos.y + height_multiplier * text_height, MAX(end.y + text_height * 1.5, text_pos2.y + height_multiplier * text_height)); } } else { h_angle_text_pos.y = end.y - text_height * 0.5; - if (ABS(text_pos2.x - h_angle_text_pos.x) < text_width) { + if (Math::abs(text_pos2.x - h_angle_text_pos.x) < text_width) { int height_multiplier = 1 + (int)grid_snap_active; h_angle_text_pos.y = MIN(text_pos.y - height_multiplier * text_height, MIN(end.y - text_height * 0.5, text_pos2.y - height_multiplier * text_height)); } diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 291ffc24d2b..ad9894a9775 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -57,7 +57,7 @@ int GradientEdit::_get_point_at(int p_xpos) const { break; } // Check if we clicked at point. - float distance = ABS(p_xpos - gradient->get_offset(i) * total_w); + float distance = Math::abs(p_xpos - gradient->get_offset(i) * total_w); if (distance < min_distance) { result = i; min_distance = distance; @@ -385,14 +385,14 @@ void GradientEdit::gui_input(const Ref &p_event) { int nearest_idx = -1; // Only check the two adjacent points to find which one is the nearest. if (selected_index > 0) { - float temp_offset = ABS(gradient->get_offset(selected_index - 1) - new_offset); + float temp_offset = Math::abs(gradient->get_offset(selected_index - 1) - new_offset); if (temp_offset < smallest_offset) { smallest_offset = temp_offset; nearest_idx = selected_index - 1; } } if (selected_index < gradient->get_point_count() - 1) { - float temp_offset = ABS(gradient->get_offset(selected_index + 1) - new_offset); + float temp_offset = Math::abs(gradient->get_offset(selected_index + 1) - new_offset); if (temp_offset < smallest_offset) { smallest_offset = temp_offset; nearest_idx = selected_index + 1; diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index 0b56e8ba6ba..e58cd3969b1 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -668,7 +668,7 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, Transform3D orig_camera_transform = p_camera->get_camera_transform(); if (!orig_camera_transform.origin.is_equal_approx(t.origin) && - ABS(orig_camera_transform.basis.get_column(Vector3::AXIS_Z).dot(Vector3(0, 1, 0))) < 0.99) { + Math::abs(orig_camera_transform.basis.get_column(Vector3::AXIS_Z).dot(Vector3(0, 1, 0))) < 0.99) { p_camera->look_at(t.origin); } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 838c3b9dad9..29f3d01cf78 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -5360,7 +5360,7 @@ void Node3DEditorViewport::update_transform(bool p_shift) { } static const float orthogonal_threshold = Math::cos(Math::deg_to_rad(85.0f)); - bool axis_is_orthogonal = ABS(plane.normal.dot(global_axis)) < orthogonal_threshold; + bool axis_is_orthogonal = Math::abs(plane.normal.dot(global_axis)) < orthogonal_threshold; double angle = 0.0f; if (axis_is_orthogonal) { diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 521868a9de3..f0f476b7f02 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -953,7 +953,7 @@ void ScriptTextEditor::_on_caret_moved() { return; } int current_line = code_editor->get_text_editor()->get_caret_line(); - if (ABS(current_line - previous_line) >= 10) { + if (Math::abs(current_line - previous_line) >= 10) { Dictionary nav_state = get_navigation_state(); nav_state["row"] = previous_line; nav_state["scroll_position"] = -1; diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 6219772ad3c..4bbe4166355 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -183,7 +183,7 @@ void SpriteFramesEditor::_sheet_preview_input(const Ref &p_event) { const int from = last_frame_selected; const int to = idx; - const int diff = ABS(to - from); + const int diff = Math::abs(to - from); const int dir = SIGN(to - from); for (int i = 0; i <= diff; i++) { diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 30c3fd7923a..980e739fc57 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -197,7 +197,7 @@ void TextureRegionEditor::_texture_overlay_draw() { hscroll->set_min(scroll_rect.position.x); hscroll->set_max(scroll_rect.position.x + scroll_rect.size.x); - if (ABS(scroll_rect.position.x - (scroll_rect.position.x + scroll_rect.size.x)) <= scroll_margin.x) { + if (Math::abs(scroll_rect.position.x - (scroll_rect.position.x + scroll_rect.size.x)) <= scroll_margin.x) { hscroll->hide(); } else { hscroll->show(); @@ -207,7 +207,7 @@ void TextureRegionEditor::_texture_overlay_draw() { vscroll->set_min(scroll_rect.position.y); vscroll->set_max(scroll_rect.position.y + scroll_rect.size.y); - if (ABS(scroll_rect.position.y - (scroll_rect.position.y + scroll_rect.size.y)) <= scroll_margin.y) { + if (Math::abs(scroll_rect.position.y - (scroll_rect.position.y + scroll_rect.size.y)) <= scroll_margin.y) { vscroll->hide(); draw_ofs.y = scroll_rect.position.y; } else { diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index 3df9a9e15a5..4f09e738d1c 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -1007,7 +1007,7 @@ void TileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p String text = tile_set->local_to_map(edited_layer->get_local_mouse_position()); if (drawing_rect) { Vector2i size = tile_set->local_to_map(edited_layer->get_local_mouse_position()) - tile_set->local_to_map(drag_start_mouse_pos); - text += vformat(" %s (%dx%d)", TTR("Drawing Rect:"), ABS(size.x) + 1, ABS(size.y) + 1); + text += vformat(" %s (%dx%d)", TTR("Drawing Rect:"), Math::abs(size.x) + 1, Math::abs(size.y) + 1); } p_overlay->draw_string(font, msgpos + Point2(1, 1), text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8)); @@ -4029,18 +4029,18 @@ Vector TileMapLayerEditor::get_line(const TileMapLayer *p_tile_map_lay } Vector2i delta = p_to_cell - p_from_cell; - delta = Vector2i(2 * delta.x + ABS(p_to_cell.y % 2) - ABS(p_from_cell.y % 2), delta.y); + delta = Vector2i(2 * delta.x + Math::abs(p_to_cell.y % 2) - Math::abs(p_from_cell.y % 2), delta.y); Vector2i sign = delta.sign(); Vector2i current = p_from_cell; points.push_back(TileSet::transform_coords_layout(transposed ? Vector2i(current.y, current.x) : current, tile_set->get_tile_offset_axis(), TileSet::TILE_LAYOUT_STACKED, tile_set->get_tile_layout())); int err = 0; - if (ABS(delta.y) < ABS(delta.x)) { + if (Math::abs(delta.y) < Math::abs(delta.x)) { Vector2i err_step = 3 * delta.abs(); while (current != p_to_cell) { err += err_step.y; - if (err > ABS(delta.x)) { + if (err > Math::abs(delta.x)) { if (sign.x == 0) { current += Vector2(sign.y, 0); } else { diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index 3a8f16a3fed..da41378bc9a 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -334,7 +334,7 @@ Error ENetMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_si Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V_MSG(!_is_active(), ERR_UNCONFIGURED, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V_MSG(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED, "The multiplayer instance isn't currently connected to any server or client."); - ERR_FAIL_COND_V_MSG(target_peer != 0 && !peers.has(ABS(target_peer)), ERR_INVALID_PARAMETER, vformat("Invalid target peer: %d", target_peer)); + ERR_FAIL_COND_V_MSG(target_peer != 0 && !peers.has(Math::abs(target_peer)), ERR_INVALID_PARAMETER, vformat("Invalid target peer: %d", target_peer)); ERR_FAIL_COND_V(active_mode == MODE_CLIENT && !peers.has(1), ERR_BUG); int packet_flags = 0; @@ -394,7 +394,7 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size } else { if (target_peer <= 0) { - int exclude = ABS(target_peer); + int exclude = Math::abs(target_peer); for (KeyValue> &E : peers) { if (E.key == exclude) { continue; diff --git a/modules/godot_physics_2d/godot_body_pair_2d.cpp b/modules/godot_physics_2d/godot_body_pair_2d.cpp index 98f11d6c07a..2f0690cd11f 100644 --- a/modules/godot_physics_2d/godot_body_pair_2d.cpp +++ b/modules/godot_physics_2d/godot_body_pair_2d.cpp @@ -244,7 +244,7 @@ real_t combine_bounce(GodotBody2D *A, GodotBody2D *B) { } real_t combine_friction(GodotBody2D *A, GodotBody2D *B) { - return ABS(MIN(A->get_friction(), B->get_friction())); + return Math::abs(MIN(A->get_friction(), B->get_friction())); } bool GodotBodyPair2D::setup(real_t p_step) { diff --git a/modules/godot_physics_3d/godot_body_pair_3d.cpp b/modules/godot_physics_3d/godot_body_pair_3d.cpp index 101a7a95f3e..1c65d495ddf 100644 --- a/modules/godot_physics_3d/godot_body_pair_3d.cpp +++ b/modules/godot_physics_3d/godot_body_pair_3d.cpp @@ -255,7 +255,7 @@ real_t combine_bounce(GodotBody3D *A, GodotBody3D *B) { } real_t combine_friction(GodotBody3D *A, GodotBody3D *B) { - return ABS(MIN(A->get_friction(), B->get_friction())); + return Math::abs(MIN(A->get_friction(), B->get_friction())); } bool GodotBodyPair3D::setup(real_t p_step) { diff --git a/modules/godot_physics_3d/godot_shape_3d.cpp b/modules/godot_physics_3d/godot_shape_3d.cpp index dbda3da8ecb..84f3e9bfe30 100644 --- a/modules/godot_physics_3d/godot_shape_3d.cpp +++ b/modules/godot_physics_3d/godot_shape_3d.cpp @@ -960,7 +960,7 @@ void GodotConvexPolygonShape3D::get_supports(const Vector3 &p_normal, int p_max, for (int i = 0; i < ec; i++) { real_t dot = (vertices[edges[i].vertex_a] - vertices[edges[i].vertex_b]).normalized().dot(p_normal); - dot = ABS(dot); + dot = Math::abs(dot); if (dot < edge_support_threshold_lower && (edges[i].vertex_a == vtx || edges[i].vertex_b == vtx)) { r_amount = 2; r_type = FEATURE_EDGE; @@ -1238,7 +1238,7 @@ void GodotFaceShape3D::get_supports(const Vector3 &p_normal, int p_max, Vector3 // check if edge is valid as a support real_t dot = (vertex[i] - vertex[nx]).normalized().dot(n); - dot = ABS(dot); + dot = Math::abs(dot); if (dot < edge_support_threshold_lower) { r_amount = 2; r_type = FEATURE_EDGE; diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp index 3b679ecf8ba..b1f0cfd3f61 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.cpp +++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp @@ -865,7 +865,7 @@ EditorPlugin::AfterGUIInput GridMapEditor::forward_spatial_input_event(Camera3D const real_t delta = pan_gesture->get_delta().y * 0.5; accumulated_floor_delta += delta; int step = 0; - if (ABS(accumulated_floor_delta) > 1.0) { + if (Math::abs(accumulated_floor_delta) > 1.0) { step = SIGN(accumulated_floor_delta); accumulated_floor_delta -= step; } diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 3ede11d1962..833ef5ddca0 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -338,9 +338,9 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) { _recreate_octant_data(); } - ERR_FAIL_INDEX(ABS(p_position.x), 1 << 20); - ERR_FAIL_INDEX(ABS(p_position.y), 1 << 20); - ERR_FAIL_INDEX(ABS(p_position.z), 1 << 20); + ERR_FAIL_INDEX(Math::abs(p_position.x), 1 << 20); + ERR_FAIL_INDEX(Math::abs(p_position.y), 1 << 20); + ERR_FAIL_INDEX(Math::abs(p_position.z), 1 << 20); IndexKey key; key.x = p_position.x; @@ -412,9 +412,9 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) { } int GridMap::get_cell_item(const Vector3i &p_position) const { - ERR_FAIL_INDEX_V(ABS(p_position.x), 1 << 20, INVALID_CELL_ITEM); - ERR_FAIL_INDEX_V(ABS(p_position.y), 1 << 20, INVALID_CELL_ITEM); - ERR_FAIL_INDEX_V(ABS(p_position.z), 1 << 20, INVALID_CELL_ITEM); + ERR_FAIL_INDEX_V(Math::abs(p_position.x), 1 << 20, INVALID_CELL_ITEM); + ERR_FAIL_INDEX_V(Math::abs(p_position.y), 1 << 20, INVALID_CELL_ITEM); + ERR_FAIL_INDEX_V(Math::abs(p_position.z), 1 << 20, INVALID_CELL_ITEM); IndexKey key; key.x = p_position.x; @@ -428,9 +428,9 @@ int GridMap::get_cell_item(const Vector3i &p_position) const { } int GridMap::get_cell_item_orientation(const Vector3i &p_position) const { - ERR_FAIL_INDEX_V(ABS(p_position.x), 1 << 20, -1); - ERR_FAIL_INDEX_V(ABS(p_position.y), 1 << 20, -1); - ERR_FAIL_INDEX_V(ABS(p_position.z), 1 << 20, -1); + ERR_FAIL_INDEX_V(Math::abs(p_position.x), 1 << 20, -1); + ERR_FAIL_INDEX_V(Math::abs(p_position.y), 1 << 20, -1); + ERR_FAIL_INDEX_V(Math::abs(p_position.z), 1 << 20, -1); IndexKey key; key.x = p_position.x; diff --git a/modules/jolt_physics/spaces/jolt_space_3d.cpp b/modules/jolt_physics/spaces/jolt_space_3d.cpp index 840c165c3c6..354e747c955 100644 --- a/modules/jolt_physics/spaces/jolt_space_3d.cpp +++ b/modules/jolt_physics/spaces/jolt_space_3d.cpp @@ -122,7 +122,7 @@ JoltSpace3D::JoltSpace3D(JPH::JobSystem *p_job_system) : physics_system->SetSoftBodyContactListener(contact_listener); physics_system->SetCombineFriction([](const JPH::Body &p_body1, const JPH::SubShapeID &p_sub_shape_id1, const JPH::Body &p_body2, const JPH::SubShapeID &p_sub_shape_id2) { - return ABS(MIN(p_body1.GetFriction(), p_body2.GetFriction())); + return Math::abs(MIN(p_body1.GetFriction(), p_body2.GetFriction())); }); physics_system->SetCombineRestitution([](const JPH::Body &p_body1, const JPH::SubShapeID &p_sub_shape_id1, const JPH::Body &p_body2, const JPH::SubShapeID &p_sub_shape_id2) { diff --git a/modules/multiplayer/scene_rpc_interface.cpp b/modules/multiplayer/scene_rpc_interface.cpp index 5d117eb1df0..51022b49eb8 100644 --- a/modules/multiplayer/scene_rpc_interface.cpp +++ b/modules/multiplayer/scene_rpc_interface.cpp @@ -301,7 +301,7 @@ void SceneRPCInterface::_send_rpc(Node *p_node, int p_to, uint16_t p_rpc_id, con ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments (>255)."); - if (p_to != 0 && !multiplayer->get_connected_peers().has(ABS(p_to))) { + if (p_to != 0 && !multiplayer->get_connected_peers().has(Math::abs(p_to))) { ERR_FAIL_COND_MSG(p_to == multiplayer->get_unique_id(), "Attempt to call RPC on yourself! Peer unique ID: " + itos(multiplayer->get_unique_id()) + "."); ERR_FAIL_MSG("Attempt to call RPC with unknown peer ID: " + itos(p_to) + "."); diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 90336333a50..0d7a5fe0076 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -1453,10 +1453,10 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { int best_match = 0; - int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); + int diff = Math::abs(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); fd->scale = double(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; for (int i = 1; i < fd->face->num_fixed_sizes; i++) { - int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); + int ndiff = Math::abs(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index c70f5e00d11..a9090c3ee33 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -877,10 +877,10 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_f if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { int best_match = 0; - int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); + int diff = Math::abs(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); fd->scale = double(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; for (int i = 1; i < fd->face->num_fixed_sizes; i++) { - int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); + int ndiff = Math::abs(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index ab30475698b..eb5955ac56c 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -5081,7 +5081,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA int64_t pen_id = GET_POINTERID_WPARAM(wParam); if (uMsg == WM_POINTERDOWN) { mb->set_pressed(true); - if (pointer_down_time.has(pen_id) && (pointer_prev_button[pen_id] == mb->get_button_index()) && (ABS(coords.y - pointer_last_pos[pen_id].y) < GetSystemMetrics(SM_CYDOUBLECLK)) && GetMessageTime() - pointer_down_time[pen_id] < (LONG)GetDoubleClickTime()) { + if (pointer_down_time.has(pen_id) && (pointer_prev_button[pen_id] == mb->get_button_index()) && (Math::abs(coords.y - pointer_last_pos[pen_id].y) < GetSystemMetrics(SM_CYDOUBLECLK)) && GetMessageTime() - pointer_down_time[pen_id] < (LONG)GetDoubleClickTime()) { mb->set_double_click(true); pointer_down_time[pen_id] = 0; } else { diff --git a/scene/2d/physics/rigid_body_2d.cpp b/scene/2d/physics/rigid_body_2d.cpp index 4b1cde6b7af..5416d9082ab 100644 --- a/scene/2d/physics/rigid_body_2d.cpp +++ b/scene/2d/physics/rigid_body_2d.cpp @@ -643,7 +643,7 @@ PackedStringArray RigidBody2D::get_configuration_warnings() const { PackedStringArray warnings = PhysicsBody2D::get_configuration_warnings(); - if (ABS(t.columns[0].length() - 1.0) > 0.05 || ABS(t.columns[1].length() - 1.0) > 0.05) { + if (Math::abs(t.columns[0].length() - 1.0) > 0.05 || Math::abs(t.columns[1].length() - 1.0) > 0.05) { warnings.push_back(RTR("Size changes to RigidBody2D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); } diff --git a/scene/3d/physics/rigid_body_3d.cpp b/scene/3d/physics/rigid_body_3d.cpp index 6c8cea1ac39..6cf261ced7b 100644 --- a/scene/3d/physics/rigid_body_3d.cpp +++ b/scene/3d/physics/rigid_body_3d.cpp @@ -662,7 +662,7 @@ PackedStringArray RigidBody3D::get_configuration_warnings() const { PackedStringArray warnings = PhysicsBody3D::get_configuration_warnings(); Vector3 scale = get_transform().get_basis().get_scale(); - if (ABS(scale.x - 1.0) > 0.05 || ABS(scale.y - 1.0) > 0.05 || ABS(scale.z - 1.0) > 0.05) { + if (Math::abs(scale.x - 1.0) > 0.05 || Math::abs(scale.y - 1.0) > 0.05 || Math::abs(scale.z - 1.0) > 0.05) { warnings.push_back(RTR("Scale changes to RigidBody3D will be overridden by the physics engine when running.\nPlease change the size in children collision shapes instead.")); } diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index a2c7bf428da..0cbef89c507 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -105,7 +105,7 @@ void ReflectionProbe::set_size(const Vector3 &p_size) { half_size = 0.01; } - if (half_size - 0.01 < ABS(origin_offset[i])) { + if (half_size - 0.01 < Math::abs(origin_offset[i])) { origin_offset[i] = SIGN(origin_offset[i]) * (half_size - 0.01); } } @@ -125,7 +125,7 @@ void ReflectionProbe::set_origin_offset(const Vector3 &p_offset) { for (int i = 0; i < 3; i++) { float half_size = size[i] / 2; - if (half_size - 0.01 < ABS(origin_offset[i])) { + if (half_size - 0.01 < Math::abs(origin_offset[i])) { origin_offset[i] = SIGN(origin_offset[i]) * (half_size - 0.01); } } diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp index a4c36deabde..62763582962 100644 --- a/scene/3d/voxelizer.cpp +++ b/scene/3d/voxelizer.cpp @@ -86,7 +86,7 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co for (int i = 0; i < 3; i++) { Vector3 axis; axis[i] = 1.0; - real_t dot = ABS(normal.dot(axis)); + real_t dot = Math::abs(normal.dot(axis)); if (i == 0 || dot > closest_dot) { closest_axis = i; closest_dot = dot; @@ -136,7 +136,7 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co Vector3 intersection; if (!plane.intersects_segment(ray_from, ray_to, &intersection)) { - if (ABS(plane.distance_to(ray_from)) < ABS(plane.distance_to(ray_to))) { + if (Math::abs(plane.distance_to(ray_from)) < Math::abs(plane.distance_to(ray_to))) { intersection = plane.project(ray_from); } else { intersection = plane.project(ray_to); diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 019a14e556c..41414feac2b 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -907,7 +907,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlend3::_process(const AnimationMixer:: AnimationMixer::PlaybackInfo pi = p_playback_info; pi.weight = MAX(0, -amount); NodeTimeInfo nti0 = blend_input(0, pi, FILTER_IGNORE, sync, p_test_only); - pi.weight = 1.0 - ABS(amount); + pi.weight = 1.0 - Math::abs(amount); NodeTimeInfo nti1 = blend_input(1, pi, FILTER_IGNORE, sync, p_test_only); pi.weight = MAX(0, amount); NodeTimeInfo nti2 = blend_input(2, pi, FILTER_IGNORE, sync, p_test_only); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index fcee517d1d4..8b0fe63f5a1 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1663,7 +1663,7 @@ void GraphEdit::_draw_grid() { for (int i = from_pos.x; i < from_pos.x + len.x; i++) { Color color; - if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) { + if (Math::abs(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) { color = theme_cache.grid_major; } else { color = theme_cache.grid_minor; @@ -1676,7 +1676,7 @@ void GraphEdit::_draw_grid() { for (int i = from_pos.y; i < from_pos.y + len.y; i++) { Color color; - if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) { + if (Math::abs(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) { color = theme_cache.grid_major; } else { color = theme_cache.grid_minor; @@ -1694,7 +1694,7 @@ void GraphEdit::_draw_grid() { if (transparent_grid_minor.a != 0) { for (int i = from_pos.x; i < from_pos.x + len.x; i++) { for (int j = from_pos.y; j < from_pos.y + len.y; j++) { - if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0) { + if (Math::abs(i) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0 && Math::abs(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0) { continue; } diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index cbba65e0088..5b5657d7c05 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -299,7 +299,7 @@ Rect2i PopupPanel::_popup_adjust_rect() const { _update_child_rects(); if (is_layout_rtl()) { - current.position -= Vector2(ABS(panel->get_offset(SIDE_RIGHT)), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); + current.position -= Vector2(Math::abs(panel->get_offset(SIDE_RIGHT)), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); } else { current.position -= Vector2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 5d4ffc9ea08..dadb7e8ceb3 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1060,7 +1060,7 @@ Rect2i PopupMenu::_popup_adjust_rect() const { _update_shadow_offsets(); if (is_layout_rtl()) { - current.position -= Vector2(ABS(panel->get_offset(SIDE_RIGHT)), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); + current.position -= Vector2(Math::abs(panel->get_offset(SIDE_RIGHT)), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); } else { current.position -= Vector2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 2598ef23eb5..2359e135da4 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -217,7 +217,7 @@ String RichTextLabel::_letters(int p_num, bool p_capitalize) const { c[chars] = 0; n = p_num; do { - int mod = ABS(n % 24); + int mod = Math::abs(n % 24); char a = (p_capitalize ? 'A' : 'a'); c[--chars] = a + mod - 1; @@ -1262,7 +1262,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } else if (item_fx->type == ITEM_RAINBOW) { ItemRainbow *item_rainbow = static_cast(item_fx); - font_color = font_color.from_hsv(MAX(item_rainbow->frequency, 0) * ABS(item_rainbow->elapsed_time * item_rainbow->speed + ((p_ofs.x + off_step.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a); + font_color = font_color.from_hsv(MAX(item_rainbow->frequency, 0) * Math::abs(item_rainbow->elapsed_time * item_rainbow->speed + ((p_ofs.x + off_step.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a); } else if (item_fx->type == ITEM_PULSE) { ItemPulse *item_pulse = static_cast(item_fx); diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index c77fda1ac80..5e8a9f88d62 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -293,7 +293,7 @@ void SpinBox::gui_input(const Ref &p_event) { if (mm.is_valid() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) { if (drag.enabled) { drag.diff_y += mm->get_relative().y; - double diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8) * SIGN(drag.diff_y); + double diff_y = -0.01 * Math::pow(Math::abs(drag.diff_y), 1.8) * SIGN(drag.diff_y); use_custom_arrow_step = false; set_value(CLAMP(drag.base_val + step * diff_y, get_min(), get_max())); } else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index ac68acabb54..f6f700de2a6 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3858,10 +3858,10 @@ int TextEdit::get_last_unhidden_line() const { int TextEdit::get_next_visible_line_offset_from(int p_line_from, int p_visible_amount) const { // Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines). - ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(p_visible_amount)); + ERR_FAIL_INDEX_V(p_line_from, text.size(), Math::abs(p_visible_amount)); if (!_is_hiding_enabled()) { - return ABS(p_visible_amount); + return Math::abs(p_visible_amount); } int num_visible = 0; @@ -3877,7 +3877,7 @@ int TextEdit::get_next_visible_line_offset_from(int p_line_from, int p_visible_a } } } else { - p_visible_amount = ABS(p_visible_amount); + p_visible_amount = Math::abs(p_visible_amount); for (int i = p_line_from; i >= 0; i--) { num_total++; if (!_is_line_hidden(i)) { @@ -3895,10 +3895,10 @@ Point2i TextEdit::get_next_visible_line_index_offset_from(int p_line_from, int p // Returns the number of lines (hidden and unhidden) from (p_line_from + p_wrap_index_from) row to (p_line_from + visible_amount of unhidden and wrapped rows). // Wrap index is set to the wrap index of the last line. int wrap_index = 0; - ERR_FAIL_INDEX_V(p_line_from, text.size(), Point2i(ABS(p_visible_amount), 0)); + ERR_FAIL_INDEX_V(p_line_from, text.size(), Point2i(Math::abs(p_visible_amount), 0)); if (!_is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) { - return Point2i(ABS(p_visible_amount), 0); + return Point2i(Math::abs(p_visible_amount), 0); } int num_visible = 0; @@ -3931,7 +3931,7 @@ Point2i TextEdit::get_next_visible_line_index_offset_from(int p_line_from, int p wrap_index = backtrack.y; } } else { - p_visible_amount = ABS(p_visible_amount); + p_visible_amount = Math::abs(p_visible_amount); int i; num_visible -= get_line_wrap_count(p_line_from) - p_wrap_index_from; for (i = p_line_from; i >= 0; i--) { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 10cf912aabb..7e2bf6ab021 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3732,7 +3732,7 @@ void Tree::gui_input(const Ref &p_event) { } else { const TreeItem::Cell &c = popup_edited_item->cells[popup_edited_item_col]; float diff_y = -mm->get_relative().y; - diff_y = Math::pow(ABS(diff_y), 1.8f) * SIGN(diff_y); + diff_y = Math::pow(Math::abs(diff_y), 1.8f) * SIGN(diff_y); diff_y *= 0.1; range_drag_base = CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); popup_edited_item->set_range(popup_edited_item_col, range_drag_base); @@ -4386,15 +4386,15 @@ void Tree::_notification(int p_what) { if (scrolling && get_rect().grow(theme_cache.scroll_border).has_point(mouse_position)) { Point2 point; - if ((ABS(mouse_position.x) < ABS(mouse_position.x - get_size().width)) && (ABS(mouse_position.x) < theme_cache.scroll_border)) { + if ((Math::abs(mouse_position.x) < Math::abs(mouse_position.x - get_size().width)) && (Math::abs(mouse_position.x) < theme_cache.scroll_border)) { point.x = mouse_position.x - theme_cache.scroll_border; - } else if (ABS(mouse_position.x - get_size().width) < theme_cache.scroll_border) { + } else if (Math::abs(mouse_position.x - get_size().width) < theme_cache.scroll_border) { point.x = mouse_position.x - (get_size().width - theme_cache.scroll_border); } - if ((ABS(mouse_position.y) < ABS(mouse_position.y - get_size().height)) && (ABS(mouse_position.y) < theme_cache.scroll_border)) { + if ((Math::abs(mouse_position.y) < Math::abs(mouse_position.y - get_size().height)) && (Math::abs(mouse_position.y) < theme_cache.scroll_border)) { point.y = mouse_position.y - theme_cache.scroll_border; - } else if (ABS(mouse_position.y - get_size().height) < theme_cache.scroll_border) { + } else if (Math::abs(mouse_position.y - get_size().height) < theme_cache.scroll_border) { point.y = mouse_position.y - (get_size().height - theme_cache.scroll_border); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 9698b441990..56703372ee0 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2665,11 +2665,11 @@ Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subw int limit = p_subwindow->theme_cache.resize_margin; - if (ABS(dist_x) > limit) { + if (Math::abs(dist_x) > limit) { return SUB_WINDOW_RESIZE_DISABLED; } - if (ABS(dist_y) > limit) { + if (Math::abs(dist_y) > limit) { return SUB_WINDOW_RESIZE_DISABLED; } diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 109dceb0956..5c5febd7b54 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -4507,7 +4507,7 @@ struct AnimationCompressionDataState { if (p_delta == 0) { return 0; } else if (p_delta < 0) { - p_delta = ABS(p_delta) - 1; + p_delta = Math::abs(p_delta) - 1; if (p_delta == 0) { return 1; } @@ -4689,7 +4689,7 @@ struct AnimationCompressionDataState { uint16_t deltau; if (delta < 0) { - deltau = (ABS(delta) - 1) | (1 << max_shifts[j]); + deltau = (Math::abs(delta) - 1) | (1 << max_shifts[j]); } else { deltau = delta; } diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 7cfd9ae7f1e..91d825ee2ef 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -1488,7 +1488,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List *r_image_fi switch (block_type) { case 1: /* info */ { ERR_FAIL_COND_V_MSG(block_size < 15, ERR_CANT_CREATE, "Invalid BMFont info block size."); - base_size = ABS(static_cast(f->get_16())); + base_size = Math::abs(static_cast(f->get_16())); if (base_size == 0) { base_size = 16; } @@ -1782,7 +1782,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List *r_image_fi if (type == "info") { if (keys.has("size")) { - base_size = ABS(keys["size"].to_int()); + base_size = Math::abs(keys["size"].to_int()); if (base_size == 0) { base_size = 16; } diff --git a/servers/audio/effects/audio_effect_hard_limiter.cpp b/servers/audio/effects/audio_effect_hard_limiter.cpp index e717557af22..5be496c3d95 100644 --- a/servers/audio/effects/audio_effect_hard_limiter.cpp +++ b/servers/audio/effects/audio_effect_hard_limiter.cpp @@ -47,7 +47,7 @@ void AudioEffectHardLimiterInstance::process(const AudioFrame *p_src_frames, Aud sample_left *= pre_gain; sample_right *= pre_gain; - float largest_sample = MAX(ABS(sample_left), ABS(sample_right)); + float largest_sample = MAX(Math::abs(sample_left), Math::abs(sample_right)); release_factor = MAX(0.0, release_factor - 1.0 / sample_rate); release_factor = MIN(release_factor, release); diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index d2cfe0d1565..2a951c46c3e 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -300,13 +300,13 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) { for (int j = 0; j < to_copy; j++) { float l = CLAMP(buf[from + j].left, -1.0, 1.0); int32_t vl = l * ((1 << 20) - 1); - int32_t vl2 = (vl < 0 ? -1 : 1) * (ABS(vl) << 11); + int32_t vl2 = (vl < 0 ? -1 : 1) * (Math::abs(vl) << 11); *dest = vl2; dest++; float r = CLAMP(buf[from + j].right, -1.0, 1.0); int32_t vr = r * ((1 << 20) - 1); - int32_t vr2 = (vr < 0 ? -1 : 1) * (ABS(vr) << 11); + int32_t vr2 = (vr < 0 ? -1 : 1) * (Math::abs(vr) << 11); *dest = vr2; dest += stride_minus_one; } @@ -621,11 +621,11 @@ void AudioServer::_mix_step() { for (uint32_t j = 0; j < buffer_size; j++) { buf[j] *= volume; - float l = ABS(buf[j].left); + float l = Math::abs(buf[j].left); if (l > peak.left) { peak.left = l; } - float r = ABS(buf[j].right); + float r = Math::abs(buf[j].right); if (r > peak.right) { peak.right = r; } diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index 4b02aa4e25b..786a51fa545 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -1522,7 +1522,7 @@ void RendererCanvasCull::canvas_item_add_texture_rect(RID p_item, const Rect2 &p if (p_tile) { rect->flags |= RendererCanvasRender::CANVAS_RECT_TILE; rect->flags |= RendererCanvasRender::CANVAS_RECT_REGION; - rect->source = Rect2(0, 0, ABS(p_rect.size.width), ABS(p_rect.size.height)); + rect->source = Rect2(0, 0, Math::abs(p_rect.size.width), Math::abs(p_rect.size.height)); } if (p_rect.size.x < 0) { diff --git a/servers/rendering/renderer_rd/environment/gi.cpp b/servers/rendering/renderer_rd/environment/gi.cpp index 14bc61ed02b..574b217494b 100644 --- a/servers/rendering/renderer_rd/environment/gi.cpp +++ b/servers/rendering/renderer_rd/environment/gi.cpp @@ -1214,7 +1214,7 @@ void GI::SDFGI::update(RID p_env, const Vector3 &p_world_position) { if (cascade.dirty_regions[j] == 0) { continue; // not dirty - } else if (uint32_t(ABS(cascade.dirty_regions[j])) >= cascade_size) { + } else if (uint32_t(Math::abs(cascade.dirty_regions[j])) >= cascade_size) { //moved too much, just redraw everything (make all dirty) cascade.dirty_regions = SDFGI::Cascade::DIRTY_ALL; break; @@ -1226,7 +1226,7 @@ void GI::SDFGI::update(RID p_env, const Vector3 &p_world_position) { uint32_t total_volume = cascade_size * cascade_size * cascade_size; uint32_t safe_volume = 1; for (int j = 0; j < 3; j++) { - safe_volume *= cascade_size - ABS(cascade.dirty_regions[j]); + safe_volume *= cascade_size - Math::abs(cascade.dirty_regions[j]); } uint32_t dirty_volume = total_volume - safe_volume; if (dirty_volume > (safe_volume / 2)) { @@ -2079,9 +2079,9 @@ void GI::SDFGI::render_region(Ref p_render_buffers, int p_ Vector3i dirty = cascades[cascade].dirty_regions; Vector3i groups; - groups.x = cascade_size - ABS(dirty.x); - groups.y = cascade_size - ABS(dirty.y); - groups.z = cascade_size - ABS(dirty.z); + groups.x = cascade_size - Math::abs(dirty.x); + groups.y = cascade_size - Math::abs(dirty.y); + groups.z = cascade_size - Math::abs(dirty.z); RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(SDFGIShader::PreprocessPushConstant)); RD::get_singleton()->compute_list_dispatch_threads(compute_list, groups.x, groups.y, groups.z); diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index 0264d74de33..185e69ddcdb 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -1129,7 +1129,7 @@ void RendererCanvasRenderRD::light_update_directional_shadow(RID p_rid, int p_sh Vector2 center = p_clip_rect.get_center(); - float to_edge_distance = ABS(light_dir.dot(p_clip_rect.get_support(-light_dir)) - light_dir.dot(center)); + float to_edge_distance = Math::abs(light_dir.dot(p_clip_rect.get_support(-light_dir)) - light_dir.dot(center)); Vector2 from_pos = center - light_dir * (to_edge_distance + p_cull_distance); float distance = to_edge_distance * 2.0 + p_cull_distance; diff --git a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp index 124f1ebe5a7..1d5d144e79b 100644 --- a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp @@ -2000,7 +2000,7 @@ void LightStorage::lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, return; //nothing could be done } - node = ABS(node) - 1; + node = Math::abs(node) - 1; uint32_t *tetrahedron = (uint32_t *)&lm->tetrahedra[node * 4]; Vector3 points[4] = { lm->points[tetrahedron[0]], lm->points[tetrahedron[1]], lm->points[tetrahedron[2]], lm->points[tetrahedron[3]] }; diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index e77449947e9..c5a442da6ba 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -2167,7 +2167,7 @@ void RendererSceneCull::_update_instance_lightmap_captures(Instance *p_instance) Vector3 inner_pos = ((lm_pos - bounds.position) / bounds.size) * 2.0 - Vector3(1.0, 1.0, 1.0); - real_t blend = MAX(ABS(inner_pos.x), MAX(ABS(inner_pos.y), ABS(inner_pos.z))); + real_t blend = MAX(Math::abs(inner_pos.x), MAX(Math::abs(inner_pos.y), Math::abs(inner_pos.z))); //make blend more rounded blend = Math::lerp(inner_pos.length(), blend, blend); blend *= blend; @@ -3667,7 +3667,7 @@ bool RendererSceneCull::_render_reflection_probe_step(Instance *p_instance, int float mesh_lod_threshold = RSG::light_storage->reflection_probe_get_mesh_lod_threshold(p_instance->base) / atlas_size; Vector3 edge = view_normals[p_step] * probe_size / 2; - float distance = ABS(view_normals[p_step].dot(edge) - view_normals[p_step].dot(origin_offset)); //distance from origin offset to actual view distance limit + float distance = Math::abs(view_normals[p_step].dot(edge) - view_normals[p_step].dot(origin_offset)); //distance from origin offset to actual view distance limit max_distance = MAX(max_distance, distance); diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index dfd20d69cbf..b00916c0297 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -559,8 +559,8 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) { float cull_distance = light->directional_distance; Vector2 light_dir_sign; - light_dir_sign.x = (ABS(light_dir.x) < CMP_EPSILON) ? 0.0 : ((light_dir.x > 0.0) ? 1.0 : -1.0); - light_dir_sign.y = (ABS(light_dir.y) < CMP_EPSILON) ? 0.0 : ((light_dir.y > 0.0) ? 1.0 : -1.0); + light_dir_sign.x = (Math::abs(light_dir.x) < CMP_EPSILON) ? 0.0 : ((light_dir.x > 0.0) ? 1.0 : -1.0); + light_dir_sign.y = (Math::abs(light_dir.y) < CMP_EPSILON) ? 0.0 : ((light_dir.y > 0.0) ? 1.0 : -1.0); Vector2 points[6]; int point_count = 0; diff --git a/servers/rendering/renderer_viewport.h b/servers/rendering/renderer_viewport.h index b8b66bf27a9..2aec2542802 100644 --- a/servers/rendering/renderer_viewport.h +++ b/servers/rendering/renderer_viewport.h @@ -134,7 +134,7 @@ public: CanvasKey(const RID &p_canvas, int p_layer, int p_sublayer) { canvas = p_canvas; int64_t sign = p_layer < 0 ? -1 : 1; - stacking = sign * (((int64_t)ABS(p_layer)) << 32) + p_sublayer; + stacking = sign * (((int64_t)Math::abs(p_layer)) << 32) + p_sublayer; } int get_layer() const { return stacking >> 32; } }; diff --git a/tests/core/math/test_math_funcs.h b/tests/core/math/test_math_funcs.h index 2415d3936f7..001cc00289c 100644 --- a/tests/core/math/test_math_funcs.h +++ b/tests/core/math/test_math_funcs.h @@ -46,9 +46,9 @@ TEST_CASE("[Math] C++ macros") { // `max` is lower than `min`. CHECK(CLAMP(620, 600, 50) == 50); - CHECK(ABS(-5) == 5); - CHECK(ABS(0) == 0); - CHECK(ABS(5) == 5); + CHECK(Math::abs(-5) == 5); + CHECK(Math::abs(0) == 0); + CHECK(Math::abs(5) == 5); CHECK(SIGN(-5) == -1.0); CHECK(SIGN(0) == 0.0); diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index a1141c152a3..d3f4d538b97 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -619,7 +619,7 @@ TEST_CASE("[String] String to float") { static const double num[12] = { -12348298412.2, 0.05, 2.0002, -0.0001, 0.0, 0.0, 123.0, 0.0, 0.0, 0.007, 234.0, 3.0 }; for (int i = 0; i < 12; i++) { - CHECK(!(ABS(String(nums[i]).to_float() - num[i]) > 0.00001)); + CHECK(!(Math::abs(String(nums[i]).to_float() - num[i]) > 0.00001)); } // Invalid float strings should return 0. @@ -746,14 +746,14 @@ TEST_CASE("[String] Splitting") { const Vector d_arr = s.split_floats(";"); CHECK(d_arr.size() == 2); for (int i = 0; i < d_arr.size(); i++) { - CHECK(ABS(d_arr[i] - slices[i]) <= 0.00001); + CHECK(Math::abs(d_arr[i] - slices[i]) <= 0.00001); } const Vector keys = { ";", " " }; const Vector f_arr = s.split_floats_mk(keys); CHECK(f_arr.size() == 3); for (int i = 0; i < f_arr.size(); i++) { - CHECK(ABS(f_arr[i] - slices[i]) <= 0.00001); + CHECK(Math::abs(f_arr[i] - slices[i]) <= 0.00001); } } @@ -764,7 +764,7 @@ TEST_CASE("[String] Splitting") { const Vector arr = s.split_floats(" "); CHECK(arr.size() == 10); for (int i = 0; i < arr.size(); i++) { - CHECK(ABS(arr[i] - slices[i]) <= 0.00001); + CHECK(Math::abs(arr[i] - slices[i]) <= 0.00001); } const Vector keys = { ";", " " };