diff --git a/core/math/aabb.h b/core/math/aabb.h index 7927c431eb3..48a883e64c9 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -101,7 +101,7 @@ struct _NO_DISCARD_ AABB { _FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */ _FORCE_INLINE_ AABB abs() const { - return AABB(Vector3(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0), position.z + MIN(size.z, (real_t)0)), size.abs()); + return AABB(position + size.min(Vector3()), size.abs()); } Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index 7df8c37e3ca..846acdecc37 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -281,9 +281,7 @@ public: } Vector3i grid_pos = Vector3i(points[i] * ACCEL_GRID_SIZE); - grid_pos.x = CLAMP(grid_pos.x, 0, ACCEL_GRID_SIZE - 1); - grid_pos.y = CLAMP(grid_pos.y, 0, ACCEL_GRID_SIZE - 1); - grid_pos.z = CLAMP(grid_pos.z, 0, ACCEL_GRID_SIZE - 1); + grid_pos = grid_pos.clamp(Vector3i(), Vector3i(ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1)); for (List::Element *E = acceleration_grid[grid_pos.x][grid_pos.y][grid_pos.z].front(); E;) { List::Element *N = E->next(); //may be deleted @@ -339,12 +337,8 @@ public: Vector3 extents = Vector3(radius2, radius2, radius2); Vector3i from = Vector3i((center - extents) * ACCEL_GRID_SIZE); Vector3i to = Vector3i((center + extents) * ACCEL_GRID_SIZE); - from.x = CLAMP(from.x, 0, ACCEL_GRID_SIZE - 1); - from.y = CLAMP(from.y, 0, ACCEL_GRID_SIZE - 1); - from.z = CLAMP(from.z, 0, ACCEL_GRID_SIZE - 1); - to.x = CLAMP(to.x, 0, ACCEL_GRID_SIZE - 1); - to.y = CLAMP(to.y, 0, ACCEL_GRID_SIZE - 1); - to.z = CLAMP(to.z, 0, ACCEL_GRID_SIZE - 1); + from = from.clamp(Vector3i(), Vector3i(ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1)); + to = to.clamp(Vector3i(), Vector3i(ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1)); for (int32_t x = from.x; x <= to.x; x++) { for (int32_t y = from.y; y <= to.y; y++) { diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h index f586b845c38..26fc517f7f9 100644 --- a/core/math/dynamic_bvh.h +++ b/core/math/dynamic_bvh.h @@ -376,13 +376,8 @@ void DynamicBVH::convex_query(const Plane *p_planes, int p_plane_count, const Ve volume.min = p_points[0]; volume.max = p_points[0]; } else { - volume.min.x = MIN(volume.min.x, p_points[i].x); - volume.min.y = MIN(volume.min.y, p_points[i].y); - volume.min.z = MIN(volume.min.z, p_points[i].z); - - volume.max.x = MAX(volume.max.x, p_points[i].x); - volume.max.y = MAX(volume.max.y, p_points[i].y); - volume.max.z = MAX(volume.max.z, p_points[i].z); + volume.min = volume.min.min(p_points[i]); + volume.max = volume.max.max(p_points[i]); } } diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index fbcaa018a8a..1502b2807c9 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -377,10 +377,8 @@ public: Vector2 further_away_opposite(1e20, 1e20); for (int i = 0; i < c; i++) { - further_away.x = MAX(p[i].x, further_away.x); - further_away.y = MAX(p[i].y, further_away.y); - further_away_opposite.x = MIN(p[i].x, further_away_opposite.x); - further_away_opposite.y = MIN(p[i].y, further_away_opposite.y); + further_away = further_away.max(p[i]); + further_away_opposite = further_away_opposite.min(p[i]); } // Make point outside that won't intersect with points in segment from p_point. diff --git a/core/math/rect2.h b/core/math/rect2.h index 0f874d4857f..497ed8cf04a 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -152,14 +152,12 @@ struct _NO_DISCARD_ Rect2 { return Rect2(); } - new_rect.position.x = MAX(p_rect.position.x, position.x); - new_rect.position.y = MAX(p_rect.position.y, position.y); + new_rect.position = p_rect.position.max(position); Point2 p_rect_end = p_rect.position + p_rect.size; Point2 end = position + size; - new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x; - new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y; + new_rect.size = p_rect_end.min(end) - new_rect.position; return new_rect; } @@ -172,11 +170,9 @@ struct _NO_DISCARD_ Rect2 { #endif Rect2 new_rect; - new_rect.position.x = MIN(p_rect.position.x, position.x); - new_rect.position.y = MIN(p_rect.position.y, position.y); + new_rect.position = p_rect.position.min(position); - new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x); - new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y); + new_rect.size = (p_rect.position + p_rect.size).max(position + size); new_rect.size = new_rect.size - new_rect.position; // Make relative again. @@ -282,7 +278,7 @@ struct _NO_DISCARD_ Rect2 { } _FORCE_INLINE_ Rect2 abs() const { - return Rect2(Point2(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0)), size.abs()); + return Rect2(position + size.min(Point2()), size.abs()); } _FORCE_INLINE_ Rect2 round() const { diff --git a/core/math/rect2i.h b/core/math/rect2i.h index 205b2c7198d..64806414c77 100644 --- a/core/math/rect2i.h +++ b/core/math/rect2i.h @@ -95,14 +95,12 @@ struct _NO_DISCARD_ Rect2i { return Rect2i(); } - new_rect.position.x = MAX(p_rect.position.x, position.x); - new_rect.position.y = MAX(p_rect.position.y, position.y); + new_rect.position = p_rect.position.max(position); Point2i p_rect_end = p_rect.position + p_rect.size; Point2i end = position + size; - new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x; - new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y; + new_rect.size = p_rect_end.min(end) - new_rect.position; return new_rect; } @@ -115,11 +113,9 @@ struct _NO_DISCARD_ Rect2i { #endif Rect2i new_rect; - new_rect.position.x = MIN(p_rect.position.x, position.x); - new_rect.position.y = MIN(p_rect.position.y, position.y); + new_rect.position = p_rect.position.min(position); - new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x); - new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y); + new_rect.size = (p_rect.position + p_rect.size).max(position + size); new_rect.size = new_rect.size - new_rect.position; // Make relative again. @@ -217,7 +213,7 @@ struct _NO_DISCARD_ Rect2i { } _FORCE_INLINE_ Rect2i abs() const { - return Rect2i(Point2i(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); + return Rect2i(position + size.min(Point2i()), size.abs()); } _FORCE_INLINE_ void set_end(const Vector2i &p_end) { diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index a0325358275..c955b3f7080 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -2812,8 +2812,7 @@ void TextureStorage::_render_target_allocate_sdf(RenderTarget *rt) { } rt->process_size = size * scale / 100; - rt->process_size.x = MAX(rt->process_size.x, 1); - rt->process_size.y = MAX(rt->process_size.y, 1); + rt->process_size = rt->process_size.max(Size2i(1, 1)); glGenTextures(2, rt->sdf_texture_process); glBindTexture(GL_TEXTURE_2D, rt->sdf_texture_process[0]); diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp index 297407da41b..1906d168fe5 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.cpp +++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp @@ -760,8 +760,7 @@ Error RenderingDeviceDriverVulkan::_check_device_capabilities() { vrs_capabilities.max_texel_size.y = vrs_properties.maxFragmentShadingRateAttachmentTexelSize.height; // We'll attempt to default to a texel size of 16x16. - vrs_capabilities.texel_size.x = CLAMP(16, vrs_capabilities.min_texel_size.x, vrs_capabilities.max_texel_size.x); - vrs_capabilities.texel_size.y = CLAMP(16, vrs_capabilities.min_texel_size.y, vrs_capabilities.max_texel_size.y); + vrs_capabilities.texel_size = Vector2i(16, 16).clamp(vrs_capabilities.min_texel_size, vrs_capabilities.max_texel_size); print_verbose(String(" Attachment fragment shading rate") + String(", min texel size: (") + itos(vrs_capabilities.min_texel_size.x) + String(", ") + itos(vrs_capabilities.min_texel_size.y) + String(")") + String(", max texel size: (") + itos(vrs_capabilities.max_texel_size.x) + String(", ") + itos(vrs_capabilities.max_texel_size.y) + String(")")); } diff --git a/editor/editor_atlas_packer.cpp b/editor/editor_atlas_packer.cpp index 5de4869c882..a0f5f1bf118 100644 --- a/editor/editor_atlas_packer.cpp +++ b/editor/editor_atlas_packer.cpp @@ -72,8 +72,7 @@ void EditorAtlasPacker::chart_pack(Vector &charts, int &r_width, int &r_h Vector2 vtx = chart.vertices[chart.faces[j].vertex[k]]; vtx -= aabb.position; vtx /= divide_by; - vtx.x = MIN(vtx.x, w - 1); - vtx.y = MIN(vtx.y, h - 1); + vtx = vtx.min(Vector2(w - 1, h - 1)); v[k] = vtx; } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index a14c6e84623..ff2b305a464 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -86,8 +86,7 @@ Size2 EditorProperty::get_minimum_size() const { } Size2 minsize = c->get_combined_minimum_size(); - ms.width = MAX(ms.width, minsize.width); - ms.height = MAX(ms.height, minsize.height); + ms = ms.max(minsize); } if (keying) { @@ -1463,8 +1462,7 @@ Size2 EditorInspectorSection::get_minimum_size() const { continue; } Size2 minsize = c->get_combined_minimum_size(); - ms.width = MAX(ms.width, minsize.width); - ms.height = MAX(ms.height, minsize.height); + ms = ms.max(minsize); } Ref font = get_theme_font(SNAME("font"), SNAME("Tree")); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index a9225a30574..5450040bea3 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -112,7 +112,7 @@ void EditorResourcePicker::_update_resource_preview(const String &p_path, const preview_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); int thumbnail_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; - assign_button->set_custom_minimum_size(Size2(MAX(1, assign_button_min_size.x), MAX(thumbnail_size, assign_button_min_size.y))); + assign_button->set_custom_minimum_size(assign_button_min_size.max(Size2(1, thumbnail_size))); } preview_rect->set_texture(p_preview); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index dbfb143b227..15dc518a675 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -337,10 +337,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Refis_pressed() && mb->get_button_index() == MouseButton::LEFT && tool_select->is_pressed()) { box_selecting = true; box_selecting_from = box_selecting_to = state_machine_draw->get_local_mouse_position(); - box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x), - MIN(box_selecting_from.y, box_selecting_to.y), - ABS(box_selecting_from.x - box_selecting_to.x), - ABS(box_selecting_from.y - box_selecting_to.y)); + box_selecting_rect = Rect2(box_selecting_from.min(box_selecting_to), (box_selecting_from - box_selecting_to).abs()); if (mb->is_command_or_control_pressed() || mb->is_shift_pressed()) { previous_selected = selected_nodes; @@ -423,10 +420,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Refget_local_mouse_position(); - box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x), - MIN(box_selecting_from.y, box_selecting_to.y), - ABS(box_selecting_from.x - box_selecting_to.x), - ABS(box_selecting_from.y - box_selecting_to.y)); + box_selecting_rect = Rect2(box_selecting_from.min(box_selecting_to), (box_selecting_from - box_selecting_to).abs()); for (int i = 0; i < node_rects.size(); i++) { bool in_box = node_rects[i].node.intersects(box_selecting_rect); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index e8804fdf124..70213b280ca 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -130,7 +130,7 @@ Ref EditorTexturePreviewPlugin::generate(const Ref &p_from, if (new_size.y > p_size.y) { new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y); } - Vector2i new_size_i(MAX(1, (int)new_size.x), MAX(1, (int)new_size.y)); + Vector2i new_size_i = Vector2i(new_size).max(Vector2i(1, 1)); img->resize(new_size_i.x, new_size_i.y, Image::INTERPOLATE_CUBIC); post_process_preview(img); diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index ffc59a34292..6a66a984c0b 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -505,10 +505,8 @@ void Skeleton3DEditor::_file_selected(const String &p_file) { position_max = Vector2(grest.origin.x, grest.origin.y); position_min = Vector2(grest.origin.x, grest.origin.y); } else { - position_max.x = MAX(grest.origin.x, position_max.x); - position_max.y = MAX(grest.origin.y, position_max.y); - position_min.x = MIN(grest.origin.x, position_min.x); - position_min.y = MIN(grest.origin.y, position_min.y); + position_max = position_max.max(Vector2(grest.origin.x, grest.origin.y)); + position_min = position_min.min(Vector2(grest.origin.x, grest.origin.y)); } } diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index 8c2cb68413e..c3900b82356 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -501,8 +501,7 @@ Vector2i TileAtlasView::get_atlas_tile_coords_at_pos(const Vector2 p_pos, bool p // Clamp. if (p_clamp) { Vector2i size = tile_set_atlas_source->get_atlas_grid_size(); - ret.x = CLAMP(ret.x, 0, size.x - 1); - ret.y = CLAMP(ret.y, 0, size.y - 1); + ret = ret.clamp(Vector2i(), size - Vector2i(1, 1)); } return ret; diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index 9460f9fef2c..1a602568fe0 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -93,8 +93,7 @@ void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_ba if (!available_plugins.is_empty()) { Size2 popup_size = Size2(400, 100); Size2 window_size = p_gui_base->get_viewport_rect().size; - popup_size.x = MIN(window_size.x * 0.5, popup_size.x); - popup_size.y = MIN(window_size.y * 0.5, popup_size.y); + popup_size = popup_size.min(window_size * 0.5); _populate_available_vcs_names(); diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 5d22cb1301c..b6f5d6ce57e 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -233,8 +233,7 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ MeshInstance &mi = mesh_instances.write[m_i]; Size2i s = Size2i(mi.data.albedo_on_uv2->get_width(), mi.data.albedo_on_uv2->get_height()); sizes.push_back(s); - atlas_size.width = MAX(atlas_size.width, s.width + 2); - atlas_size.height = MAX(atlas_size.height, s.height + 2); + atlas_size = atlas_size.max(s + Size2i(2, 2)); } int max = nearest_power_of_2_templated(atlas_size.width); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 34aa15abbb7..226e1236488 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -1995,8 +1995,7 @@ void DisplayServerX11::window_set_current_screen(int p_screen, WindowID p_window Size2i wsize = window_get_size(p_window); wpos += srect.position; if (srect != Rect2i()) { - wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - wsize.width / 3); - wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - wsize.height / 3); + wpos = wpos.clamp(srect.position, srect.position + srect.size - wsize / 3); } window_set_position(wpos, p_window); } @@ -2224,8 +2223,7 @@ void DisplayServerX11::window_set_size(const Size2i p_size, WindowID p_window) { ERR_FAIL_COND(!windows.has(p_window)); Size2i size = p_size; - size.x = MAX(1, size.x); - size.y = MAX(1, size.y); + size = size.max(Size2i(1, 1)); WindowData &wd = windows[p_window]; @@ -5451,8 +5449,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V } else { Rect2i srect = screen_get_usable_rect(rq_screen); Point2i wpos = p_rect.position; - wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - p_rect.size.width / 3); - wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - p_rect.size.height / 3); + wpos = wpos.clamp(srect.position, srect.position + srect.size - p_rect.size / 3); win_rect.position = wpos; } diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index c52ed00b3d9..99e9d20f2be 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -83,8 +83,7 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod Rect2i srect = screen_get_usable_rect(rq_screen); Point2i wpos = p_rect.position; if (srect != Rect2i()) { - wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - p_rect.size.width / 3); - wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - p_rect.size.height / 3); + wpos = wpos.clamp(srect.position, srect.position + srect.size - p_rect.size / 3); } // macOS native y-coordinate relative to _get_screens_origin() is negative, // Godot passes a positive value. @@ -1877,8 +1876,7 @@ void DisplayServerMacOS::window_set_current_screen(int p_screen, WindowID p_wind Size2i wsize = window_get_size(p_window); wpos += srect.position; - wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - wsize.width / 3); - wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - wsize.height / 3); + wpos = wpos.clamp(srect.position, srect.position + srect.size - wsize / 3); window_set_position(wpos, p_window); if (was_fullscreen) { @@ -2309,8 +2307,7 @@ void DisplayServerMacOS::window_set_window_buttons_offset(const Vector2i &p_offs WindowData &wd = windows[p_window]; float scale = screen_get_max_scale(); wd.wb_offset = p_offset / scale; - wd.wb_offset.x = MAX(wd.wb_offset.x, 12); - wd.wb_offset.y = MAX(wd.wb_offset.y, 12); + wd.wb_offset = wd.wb_offset.max(Vector2i(12, 12)); if (wd.window_button_view) { [wd.window_button_view setOffset:NSMakePoint(wd.wb_offset.x, wd.wb_offset.y)]; } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 074d40bf4bd..79078456a56 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -903,8 +903,7 @@ static BOOL CALLBACK _MonitorEnumProcPos(HMONITOR hMonitor, HDC hdcMonitor, LPRE static BOOL CALLBACK _MonitorEnumProcOrigin(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { EnumPosData *data = (EnumPosData *)dwData; - data->pos.x = MIN(data->pos.x, lprcMonitor->left); - data->pos.y = MIN(data->pos.y, lprcMonitor->top); + data->pos = data->pos.min(Point2(lprcMonitor->left, lprcMonitor->top)); return TRUE; } @@ -1637,8 +1636,7 @@ void DisplayServerWindows::window_set_current_screen(int p_screen, WindowID p_wi Size2i wsize = window_get_size(p_window); wpos += srect.position; - wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - wsize.width / 3); - wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - wsize.height / 3); + wpos = wpos.clamp(srect.position, srect.position + srect.size - wsize / 3); window_set_position(wpos, p_window); } } @@ -5076,8 +5074,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, Rect2i srect = screen_get_usable_rect(rq_screen); Point2i wpos = p_rect.position; if (srect != Rect2i()) { - wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - p_rect.size.width / 3); - wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - p_rect.size.height / 3); + wpos = wpos.clamp(srect.position, srect.position + srect.size - p_rect.size / 3); } WindowRect.left = wpos.x; diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index 3c19dd00209..5745a592972 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -374,8 +374,7 @@ bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const { q.y = texture->get_size().height - q.y - 1; } } else { - q.x = MIN(q.x, texture->get_size().width - 1); - q.y = MIN(q.y, texture->get_size().height - 1); + q = q.min(texture->get_size() - Vector2(1, 1)); } return texture->is_pixel_opaque((int)q.x, (int)q.y); diff --git a/scene/3d/decal.cpp b/scene/3d/decal.cpp index 6878df21d8e..caabb4225f3 100644 --- a/scene/3d/decal.cpp +++ b/scene/3d/decal.cpp @@ -31,7 +31,7 @@ #include "decal.h" void Decal::set_size(const Vector3 &p_size) { - size = Vector3(MAX(0.001, p_size.x), MAX(0.001, p_size.y), MAX(0.001, p_size.z)); + size = p_size.max(Vector3(0.001, 0.001, 0.001)); RS::get_singleton()->decal_set_size(decal, size); update_gizmos(); } diff --git a/scene/3d/fog_volume.cpp b/scene/3d/fog_volume.cpp index 12ca1888c47..8af386f282b 100644 --- a/scene/3d/fog_volume.cpp +++ b/scene/3d/fog_volume.cpp @@ -73,9 +73,7 @@ bool FogVolume::_get(const StringName &p_name, Variant &r_property) const { void FogVolume::set_size(const Vector3 &p_size) { size = p_size; - size.x = MAX(0.0, size.x); - size.y = MAX(0.0, size.y); - size.z = MAX(0.0, size.z); + size = size.max(Vector3()); RS::get_singleton()->fog_volume_set_size(_get_volume(), size); update_gizmos(); } diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp index cbc75801b0a..8fd5f25749c 100644 --- a/scene/3d/gpu_particles_collision_3d.cpp +++ b/scene/3d/gpu_particles_collision_3d.cpp @@ -330,7 +330,7 @@ void GPUParticlesCollisionSDF3D::_find_closest_distance(const Vector3 &p_pos, co Vector3 center = p_bvh[p_bvh_cell].bounds.position + he; Vector3 rel = (p_pos - center).abs(); - Vector3 closest(MIN(rel.x, he.x), MIN(rel.y, he.y), MIN(rel.z, he.z)); + Vector3 closest = rel.min(he); float d = rel.distance_to(closest); if (d >= r_closest_distance) { @@ -382,9 +382,7 @@ Vector3i GPUParticlesCollisionSDF3D::get_estimated_cell_size() const { float cell_size = aabb.get_longest_axis_size() / float(subdiv); Vector3i sdf_size = Vector3i(aabb.size / cell_size); - sdf_size.x = MAX(1, sdf_size.x); - sdf_size.y = MAX(1, sdf_size.y); - sdf_size.z = MAX(1, sdf_size.z); + sdf_size = sdf_size.max(Vector3i(1, 1, 1)); return sdf_size; } @@ -397,9 +395,7 @@ Ref GPUParticlesCollisionSDF3D::bake() { float cell_size = aabb.get_longest_axis_size() / float(subdiv); Vector3i sdf_size = Vector3i(aabb.size / cell_size); - sdf_size.x = MAX(1, sdf_size.x); - sdf_size.y = MAX(1, sdf_size.y); - sdf_size.z = MAX(1, sdf_size.z); + sdf_size = sdf_size.max(Vector3i(1, 1, 1)); if (bake_begin_function) { bake_begin_function(100); diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp index 8d995a87850..2f77185d0da 100644 --- a/scene/3d/occluder_instance_3d.cpp +++ b/scene/3d/occluder_instance_3d.cpp @@ -236,7 +236,7 @@ void BoxOccluder3D::set_size(const Vector3 &p_size) { return; } - size = Vector3(MAX(p_size.x, 0.0f), MAX(p_size.y, 0.0f), MAX(p_size.z, 0.0f)); + size = p_size.max(Vector3()); _update(); } diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp index eb8569fa30f..938d6e56990 100644 --- a/scene/3d/voxel_gi.cpp +++ b/scene/3d/voxel_gi.cpp @@ -294,7 +294,7 @@ VoxelGI::Subdiv VoxelGI::get_subdiv() const { void VoxelGI::set_size(const Vector3 &p_size) { // Prevent very small size dimensions as these breaks baking if other size dimensions are set very high. - size = Vector3(MAX(1.0, p_size.x), MAX(1.0, p_size.y), MAX(1.0, p_size.z)); + size = p_size.max(Vector3(1.0, 1.0, 1.0)); update_gizmos(); } diff --git a/scene/gui/aspect_ratio_container.cpp b/scene/gui/aspect_ratio_container.cpp index 94240cceadd..711dd137813 100644 --- a/scene/gui/aspect_ratio_container.cpp +++ b/scene/gui/aspect_ratio_container.cpp @@ -46,8 +46,7 @@ Size2 AspectRatioContainer::get_minimum_size() const { continue; } Size2 minsize = c->get_combined_minimum_size(); - ms.width = MAX(ms.width, minsize.width); - ms.height = MAX(ms.height, minsize.height); + ms = ms.max(minsize); } return ms; } @@ -144,8 +143,7 @@ void AspectRatioContainer::_notification(int p_what) { } break; } child_size *= scale_factor; - child_size.x = MAX(child_size.x, child_minsize.x); - child_size.y = MAX(child_size.y, child_minsize.y); + child_size = child_size.max(child_minsize); float align_x = 0.5; switch (alignment_horizontal) { diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp index 7a860cdea7d..acdeae289b9 100644 --- a/scene/gui/center_container.cpp +++ b/scene/gui/center_container.cpp @@ -47,8 +47,7 @@ Size2 CenterContainer::get_minimum_size() const { continue; } Size2 minsize = c->get_combined_minimum_size(); - ms.width = MAX(ms.width, minsize.width); - ms.height = MAX(ms.height, minsize.height); + ms = ms.max(minsize); } return ms; diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index 46c20e4a1c0..af6696834ec 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -36,28 +36,28 @@ Size2 CheckBox::get_icon_size() const { Size2 tex_size = Size2(0, 0); if (!theme_cache.checked.is_null()) { - tex_size = Size2(theme_cache.checked->get_width(), theme_cache.checked->get_height()); + tex_size = theme_cache.checked->get_size(); } if (!theme_cache.unchecked.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.unchecked->get_width()), MAX(tex_size.height, theme_cache.unchecked->get_height())); + tex_size = tex_size.max(theme_cache.unchecked->get_size()); } if (!theme_cache.radio_checked.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.radio_checked->get_width()), MAX(tex_size.height, theme_cache.radio_checked->get_height())); + tex_size = tex_size.max(theme_cache.radio_checked->get_size()); } if (!theme_cache.radio_unchecked.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.radio_unchecked->get_width()), MAX(tex_size.height, theme_cache.radio_unchecked->get_height())); + tex_size = tex_size.max(theme_cache.radio_unchecked->get_size()); } if (!theme_cache.checked_disabled.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.checked_disabled->get_width()), MAX(tex_size.height, theme_cache.checked_disabled->get_height())); + tex_size = tex_size.max(theme_cache.checked_disabled->get_size()); } if (!theme_cache.unchecked_disabled.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.unchecked_disabled->get_width()), MAX(tex_size.height, theme_cache.unchecked_disabled->get_height())); + tex_size = tex_size.max(theme_cache.unchecked_disabled->get_size()); } if (!theme_cache.radio_checked_disabled.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.radio_checked_disabled->get_width()), MAX(tex_size.height, theme_cache.radio_checked_disabled->get_height())); + tex_size = tex_size.max(theme_cache.radio_checked_disabled->get_size()); } if (!theme_cache.radio_unchecked_disabled.is_null()) { - tex_size = Size2(MAX(tex_size.width, theme_cache.radio_unchecked_disabled->get_width()), MAX(tex_size.height, theme_cache.radio_unchecked_disabled->get_height())); + tex_size = tex_size.max(theme_cache.radio_unchecked_disabled->get_size()); } return tex_size; } diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index ca2ef220fdf..ab3b74a3c37 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -57,10 +57,10 @@ Size2 CheckButton::get_icon_size() const { Size2 tex_size = Size2(0, 0); if (!on_tex.is_null()) { - tex_size = Size2(on_tex->get_width(), on_tex->get_height()); + tex_size = on_tex->get_size(); } if (!off_tex.is_null()) { - tex_size = Size2(MAX(tex_size.width, off_tex->get_width()), MAX(tex_size.height, off_tex->get_height())); + tex_size = tex_size.max(off_tex->get_size()); } return tex_size; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index d65399446ca..342b90bb525 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1653,8 +1653,7 @@ Size2 Control::get_custom_minimum_size() const { void Control::_update_minimum_size_cache() { Size2 minsize = get_minimum_size(); - minsize.x = MAX(minsize.x, data.custom_minimum_size.x); - minsize.y = MAX(minsize.y, data.custom_minimum_size.y); + minsize = minsize.max(data.custom_minimum_size); data.minimum_size_cache = minsize; data.minimum_size_valid = true; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 3746b667f68..c13a2e281a6 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -252,8 +252,7 @@ Size2 AcceptDialog::_get_contents_minimum_size() const { } Size2 child_minsize = c->get_combined_minimum_size(); - content_minsize.x = MAX(child_minsize.x, content_minsize.x); - content_minsize.y = MAX(child_minsize.y, content_minsize.y); + content_minsize = child_minsize.max(content_minsize); } // Then we take the background panel as it provides the offsets, diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 056872a4fe4..8bce5c0caa3 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -181,8 +181,7 @@ void GraphEditMinimap::gui_input(const Ref &p_ev) { if (is_resizing) { // Prevent setting minimap wider than GraphEdit. Vector2 new_minimap_size; - new_minimap_size.width = MIN(get_size().width - mm->get_relative().x, ge->get_size().width - 2.0 * minimap_padding.x); - new_minimap_size.height = MIN(get_size().height - mm->get_relative().y, ge->get_size().height - 2.0 * minimap_padding.y); + new_minimap_size = (get_size() - mm->get_relative()).min(ge->get_size() - 2.0 * minimap_padding); ge->set_minimap_size(new_minimap_size); queue_redraw(); diff --git a/scene/gui/graph_element.cpp b/scene/gui/graph_element.cpp index 7fa5b0ceec9..9eb9578b2ca 100644 --- a/scene/gui/graph_element.cpp +++ b/scene/gui/graph_element.cpp @@ -74,8 +74,7 @@ Size2 GraphElement::get_minimum_size() const { Size2i size = child->get_combined_minimum_size(); - minsize.width = MAX(minsize.width, size.width); - minsize.height = MAX(minsize.height, size.height); + minsize = minsize.max(size); } return minsize; diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index 306ef4936f6..ef859198595 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -44,8 +44,7 @@ Size2 PanelContainer::get_minimum_size() const { } Size2 minsize = c->get_combined_minimum_size(); - ms.width = MAX(ms.width, minsize.width); - ms.height = MAX(ms.height, minsize.height); + ms = ms.max(minsize); } if (theme_cache.panel_style.is_valid()) { diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 0c5a882044f..09274049474 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -224,8 +224,7 @@ Size2 PopupPanel::_get_contents_minimum_size() const { } Size2 cms = c->get_combined_minimum_size(); - ms.x = MAX(cms.x, ms.x); - ms.y = MAX(cms.y, ms.y); + ms = cms.max(ms); } return ms + theme_cache.panel_style->get_minimum_size(); diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index c66b30f130b..b2617e6fc74 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -35,15 +35,13 @@ Size2 ProgressBar::get_minimum_size() const { Size2 minimum_size = theme_cache.background_style->get_minimum_size(); - minimum_size.height = MAX(minimum_size.height, theme_cache.fill_style->get_minimum_size().height); - minimum_size.width = MAX(minimum_size.width, theme_cache.fill_style->get_minimum_size().width); + minimum_size = minimum_size.max(theme_cache.fill_style->get_minimum_size()); if (show_percentage) { String txt = "100%"; TextLine tl = TextLine(txt, theme_cache.font, theme_cache.font_size); minimum_size.height = MAX(minimum_size.height, theme_cache.background_style->get_minimum_size().height + tl.get_size().y); } else { // this is needed, else the progressbar will collapse - minimum_size.width = MAX(minimum_size.width, 1); - minimum_size.height = MAX(minimum_size.height, 1); + minimum_size = minimum_size.max(Size2(1, 1)); } return minimum_size; } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index cb7ccb583e8..1baf71dd075 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -951,7 +951,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o case ITEM_IMAGE: { ItemImage *img = static_cast(it); if (img->pad) { - Size2 pad_size = Size2(MIN(rect.size.x, img->image->get_width()), MIN(rect.size.y, img->image->get_height())); + Size2 pad_size = rect.size.min(img->image->get_size()); Vector2 pad_off = (rect.size - pad_size) / 2; img->image->draw_rect(ci, Rect2(p_ofs + rect.position + off + pad_off, pad_size), false, img->color); } else { diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 89d308de3f6..1447d2f0023 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -56,8 +56,7 @@ Size2 ScrollContainer::get_minimum_size() const { Size2 child_min_size = c->get_combined_minimum_size(); - largest_child_min_size.x = MAX(largest_child_min_size.x, child_min_size.x); - largest_child_min_size.y = MAX(largest_child_min_size.y, child_min_size.y); + largest_child_min_size = largest_child_min_size.max(child_min_size); } if (horizontal_scroll_mode == SCROLL_MODE_DISABLED) { diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp index 0d33774e208..f6cfe6ab184 100644 --- a/scene/gui/subviewport_container.cpp +++ b/scene/gui/subviewport_container.cpp @@ -45,8 +45,7 @@ Size2 SubViewportContainer::get_minimum_size() const { } Size2 minsize = c->get_size(); - ms.width = MAX(ms.width, minsize.width); - ms.height = MAX(ms.height, minsize.height); + ms = ms.max(minsize); } return ms; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 741b38a35ae..df3c9631f9e 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -871,8 +871,7 @@ Size2 TabContainer::get_minimum_size() const { } Size2 cms = c->get_combined_minimum_size(); - largest_child_min_size.x = MAX(largest_child_min_size.x, cms.x); - largest_child_min_size.y = MAX(largest_child_min_size.y, cms.y); + largest_child_min_size = largest_child_min_size.max(cms); } ms.y += largest_child_min_size.y; diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index dcbb25c41d9..0b197c8c023 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -103,8 +103,8 @@ bool TextureButton::has_point(const Point2 &p_point) const { point *= scale; // finally, we need to check if the point is inside a rectangle with a position >= 0,0 and a size <= mask_size - rect.position = Point2(MAX(0, _texture_region.position.x), MAX(0, _texture_region.position.y)); - rect.size = Size2(MIN(mask_size.x, _texture_region.size.x), MIN(mask_size.y, _texture_region.size.y)); + rect.position = Point2().max(_texture_region.position); + rect.size = mask_size.min(_texture_region.size); } if (!rect.has_point(point)) { diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp index 248260a7d2f..5261cbe3eb5 100644 --- a/scene/gui/texture_progress_bar.cpp +++ b/scene/gui/texture_progress_bar.cpp @@ -249,8 +249,7 @@ Point2 TextureProgressBar::get_relative_center() { p += rad_center_off; p.x /= progress->get_width(); p.y /= progress->get_height(); - p.x = CLAMP(p.x, 0, 1); - p.y = CLAMP(p.y, 0, 1); + p = p.clamp(Point2(), Point2(1, 1)); return p; } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index c8d2d71c2af..41f3ff108cd 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2747,8 +2747,7 @@ bool Viewport::_sub_windows_forward_input(const Ref &p_event) { Size2i min_size = gui.currently_dragged_subwindow->get_min_size(); Size2i min_size_clamped = gui.currently_dragged_subwindow->get_clamped_minimum_size(); - min_size_clamped.x = MAX(min_size_clamped.x, 1); - min_size_clamped.y = MAX(min_size_clamped.y, 1); + min_size_clamped = min_size_clamped.max(Size2i(1, 1)); Rect2i r = gui.subwindow_resize_from_rect; @@ -2809,8 +2808,7 @@ bool Viewport::_sub_windows_forward_input(const Ref &p_event) { Size2i max_size = gui.currently_dragged_subwindow->get_max_size(); if ((max_size.x > 0 || max_size.y > 0) && (max_size.x >= min_size.x && max_size.y >= min_size.y)) { - max_size.x = MAX(max_size.x, 1); - max_size.y = MAX(max_size.y, 1); + max_size = max_size.max(Size2i(1, 1)); if (r.size.x > max_size.x) { r.size.x = max_size.x; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 6632dd90339..bced493d986 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1033,8 +1033,7 @@ void Window::_update_window_size() { } if (embedder) { - size.x = MAX(size.x, 1); - size.y = MAX(size.y, 1); + size = size.max(Size2i(1, 1)); embedder->_sub_window_update(this); } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { @@ -1545,8 +1544,7 @@ Size2 Window::_get_contents_minimum_size() const { Point2i pos = c->get_position(); Size2i min = c->get_combined_minimum_size(); - max.x = MAX(pos.x + min.x, max.x); - max.y = MAX(pos.y + min.y, max.y); + max = max.max(pos + min); } } @@ -1703,7 +1701,7 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio Vector2i size_ratio = parent_rect.size * p_fallback_ratio; Rect2i popup_rect; - popup_rect.size = Vector2i(MIN(size_ratio.x, expected_size.x), MIN(size_ratio.y, expected_size.y)); + popup_rect.size = size_ratio.min(expected_size); popup_rect.size = _clamp_window_size(popup_rect.size); if (parent_rect != Rect2()) { diff --git a/scene/resources/2d/polygon_path_finder.cpp b/scene/resources/2d/polygon_path_finder.cpp index 617a53f0a3d..3aa292431d9 100644 --- a/scene/resources/2d/polygon_path_finder.cpp +++ b/scene/resources/2d/polygon_path_finder.cpp @@ -64,8 +64,7 @@ void PolygonPathFinder::setup(const Vector &p_points, const Vector points.write[i].pos = p_points[i]; points.write[i].penalty = 0; - outside_point.x = i == 0 ? p_points[0].x : (MAX(p_points[i].x, outside_point.x)); - outside_point.y = i == 0 ? p_points[0].y : (MAX(p_points[i].y, outside_point.y)); + outside_point = i == 0 ? p_points[0] : p_points[i].max(outside_point); if (i == 0) { bounds.position = points[i].pos; diff --git a/scene/resources/2d/tile_set.cpp b/scene/resources/2d/tile_set.cpp index d09723d7652..66d97398b9f 100644 --- a/scene/resources/2d/tile_set.cpp +++ b/scene/resources/2d/tile_set.cpp @@ -4650,7 +4650,7 @@ Ref TileSetAtlasSource::get_texture() const { void TileSetAtlasSource::set_margins(Vector2i p_margins) { if (p_margins.x < 0 || p_margins.y < 0) { WARN_PRINT("Atlas source margins should be positive."); - margins = Vector2i(MAX(0, p_margins.x), MAX(0, p_margins.y)); + margins = p_margins.max(Vector2i()); } else { margins = p_margins; } @@ -4666,7 +4666,7 @@ Vector2i TileSetAtlasSource::get_margins() const { void TileSetAtlasSource::set_separation(Vector2i p_separation) { if (p_separation.x < 0 || p_separation.y < 0) { WARN_PRINT("Atlas source separation should be positive."); - separation = Vector2i(MAX(0, p_separation.x), MAX(0, p_separation.y)); + separation = p_separation.max(Vector2i()); } else { separation = p_separation; } @@ -4682,7 +4682,7 @@ Vector2i TileSetAtlasSource::get_separation() const { void TileSetAtlasSource::set_texture_region_size(Vector2i p_tile_size) { if (p_tile_size.x <= 0 || p_tile_size.y <= 0) { WARN_PRINT("Atlas source tile_size should be strictly positive."); - texture_region_size = Vector2i(MAX(1, p_tile_size.x), MAX(1, p_tile_size.y)); + texture_region_size = p_tile_size.max(Vector2i(1, 1)); } else { texture_region_size = p_tile_size; } diff --git a/scene/resources/3d/primitive_meshes.cpp b/scene/resources/3d/primitive_meshes.cpp index c2b2a6d68bb..ee772f960a0 100644 --- a/scene/resources/3d/primitive_meshes.cpp +++ b/scene/resources/3d/primitive_meshes.cpp @@ -2845,10 +2845,8 @@ void TextMesh::_generate_glyph_mesh_data(const GlyphMeshKey &p_key, const Glyph for (int j = 0; j < gl_data.contours[i].size(); j++) { int next = (j + 1 == gl_data.contours[i].size()) ? 0 : (j + 1); - gl_data.min_p.x = MIN(gl_data.min_p.x, gl_data.contours[i][j].point.x); - gl_data.min_p.y = MIN(gl_data.min_p.y, gl_data.contours[i][j].point.y); - gl_data.max_p.x = MAX(gl_data.max_p.x, gl_data.contours[i][j].point.x); - gl_data.max_p.y = MAX(gl_data.max_p.y, gl_data.contours[i][j].point.y); + gl_data.min_p = gl_data.min_p.min(gl_data.contours[i][j].point); + gl_data.max_p = gl_data.max_p.max(gl_data.contours[i][j].point); length += (gl_data.contours[i][next].point - gl_data.contours[i][j].point).length(); inp.GetPoint(j) = gl_data.contours[i][j].point; diff --git a/scene/resources/navigation_polygon.cpp b/scene/resources/navigation_polygon.cpp index e830153330a..274b13a487e 100644 --- a/scene/resources/navigation_polygon.cpp +++ b/scene/resources/navigation_polygon.cpp @@ -251,8 +251,7 @@ void NavigationPolygon::make_polygons_from_outlines() { } const Vector2 *r = ol.ptr(); for (int j = 0; j < olsize; j++) { - outside_point.x = MAX(r[j].x, outside_point.x); - outside_point.y = MAX(r[j].y, outside_point.y); + outside_point = outside_point.max(r[j]); } } diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp index 872d26aff64..ea389ff59cd 100644 --- a/servers/physics_3d/godot_shape_3d.cpp +++ b/servers/physics_3d/godot_shape_3d.cpp @@ -2016,9 +2016,7 @@ void GodotHeightMapShape3D::_get_cell(const Vector3 &p_point, int &r_x, int &r_y Vector3 pos_local = shape_aabb.position + local_origin; Vector3 clamped_point(p_point); - clamped_point.x = CLAMP(p_point.x, pos_local.x, pos_local.x + shape_aabb.size.x); - clamped_point.y = CLAMP(p_point.y, pos_local.y, pos_local.y + shape_aabb.size.y); - clamped_point.z = CLAMP(p_point.z, pos_local.z, pos_local.z + shape_aabb.size.z); + clamped_point = p_point.clamp(pos_local, pos_local + shape_aabb.size); r_x = (clamped_point.x < 0.0) ? (clamped_point.x - 0.5) : (clamped_point.x + 0.5); r_y = (clamped_point.y < 0.0) ? (clamped_point.y - 0.5) : (clamped_point.y + 0.5); diff --git a/servers/rendering/renderer_rd/environment/fog.cpp b/servers/rendering/renderer_rd/environment/fog.cpp index 1d144bedcff..48537a97d9f 100644 --- a/servers/rendering/renderer_rd/environment/fog.cpp +++ b/servers/rendering/renderer_rd/environment/fog.cpp @@ -509,9 +509,7 @@ Vector3i Fog::_point_get_position_in_froxel_volume(const Vector3 &p_point, float fog_position.z = Math::pow(float(fog_position.z), float(1.0 / volumetric_fog_detail_spread)); fog_position = fog_position * fog_size - Vector3(0.5, 0.5, 0.5); - fog_position.x = CLAMP(fog_position.x, 0.0, fog_size.x); - fog_position.y = CLAMP(fog_position.y, 0.0, fog_size.y); - fog_position.z = CLAMP(fog_position.z, 0.0, fog_size.z); + fog_position = fog_position.clamp(Vector3(), fog_size); return Vector3i(fog_position); } @@ -680,8 +678,8 @@ void Fog::volumetric_fog_update(const VolumetricFogSettings &p_settings, const P max = Vector3i(1, 1, 1); for (int j = 0; j < 8; j++) { - min = Vector3i(MIN(min.x, points[j].x), MIN(min.y, points[j].y), MIN(min.z, points[j].z)); - max = Vector3i(MAX(max.x, points[j].x), MAX(max.y, points[j].y), MAX(max.z, points[j].z)); + min = min.min(points[j]); + max = max.max(points[j]); } kernel_size = max - min; diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index dd94982f1aa..f3ce432495c 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -3637,8 +3637,7 @@ void TextureStorage::_render_target_allocate_sdf(RenderTarget *rt) { } rt->process_size = size * scale / 100; - rt->process_size.x = MAX(rt->process_size.x, 1); - rt->process_size.y = MAX(rt->process_size.y, 1); + rt->process_size = rt->process_size.max(Size2i(1, 1)); tformat.format = RD::DATA_FORMAT_R16G16_SINT; tformat.width = rt->process_size.width; diff --git a/servers/rendering/renderer_scene_occlusion_cull.h b/servers/rendering/renderer_scene_occlusion_cull.h index 565b3930948..149d7b1cdb5 100644 --- a/servers/rendering/renderer_scene_occlusion_cull.h +++ b/servers/rendering/renderer_scene_occlusion_cull.h @@ -65,7 +65,7 @@ public: return false; } - Vector3 closest_point = Vector3(CLAMP(p_cam_position.x, p_bounds[0], p_bounds[3]), CLAMP(p_cam_position.y, p_bounds[1], p_bounds[4]), CLAMP(p_cam_position.z, p_bounds[2], p_bounds[5])); + Vector3 closest_point = p_cam_position.clamp(Vector3(p_bounds[0], p_bounds[1], p_bounds[2]), Vector3(p_bounds[3], p_bounds[4], p_bounds[5])); if (closest_point == p_cam_position) { return false;