Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::clamp #2595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/common/move-drag-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ void adjust_view_on_output(drag_done_signal *ev)
target_ws = target_ws + current_ws;

auto gsize = ev->focused_output->wset()->get_workspace_grid_size();
target_ws.x = wf::clamp(target_ws.x, 0, gsize.width - 1);
target_ws.y = wf::clamp(target_ws.y, 0, gsize.height - 1);
target_ws.x = std::clamp(target_ws.x, 0, gsize.width - 1);
target_ws.y = std::clamp(target_ws.y, 0, gsize.height - 1);

// view to focus at the end of drag
auto focus_view = ev->main_view;
Expand Down
2 changes: 1 addition & 1 deletion plugins/cube/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ class wayfire_cube : public wf::per_output_plugin_instance_t, public wf::pointer
double current_off_y = animation.cube_animation.offset_y;
double off_y = current_off_y + ydiff * YVelocity;

off_y = wf::clamp(off_y, -1.5, 1.5);
off_y = std::clamp(off_y, -1.5, 1.5);
animation.cube_animation.offset_y.set(current_off_y, off_y);
animation.cube_animation.offset_z.restart_with_end(
animation.cube_animation.offset_z.end);
Expand Down
6 changes: 3 additions & 3 deletions plugins/single_plugins/vswipe-processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ static inline double vswipe_process_delta(const double delta,

// If we're moving further in the limit direction, slow down all the way
// to extremely slow, but reversing the direction should be easier.
const double slowdown = wf::clamp(ease,
const double slowdown = std::clamp(ease,
std::signbit(delta) == std::signbit(sdx_offset) ? 0.005 : 0.2, 1.0);

return wf::clamp(delta, -speed_cap, speed_cap) * slowdown;
return std::clamp(delta, -speed_cap, speed_cap) * slowdown;
}

static inline int vswipe_finish_target(const double accumulated_dx,
Expand Down Expand Up @@ -71,7 +71,7 @@ static inline int vswipe_finish_target(const double accumulated_dx,

if (!free_movement)
{
target_dx = wf::clamp(target_dx, -1, 1);
target_dx = std::clamp(target_dx, -1, 1);
}

return target_dx;
Expand Down
6 changes: 3 additions & 3 deletions plugins/single_plugins/vswipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class vswipe : public wf::per_output_plugin_instance_t
/* Diagonal movement is possible if the slope is not too steep
* and we have moved enough */
double slope = deltas.x / deltas.y;
bool diagonal = wf::clamp(slope,
bool diagonal = std::clamp(slope,
1.0 / diagonal_threshold, diagonal_threshold) == slope;
diagonal &= (deltas.x * deltas.x + deltas.y * deltas.y) >=
initial_direction_threshold * initial_direction_threshold;
Expand Down Expand Up @@ -326,9 +326,9 @@ class vswipe : public wf::per_output_plugin_instance_t
}

state.swiping = false;
const double move_threshold = wf::clamp((double)threshold, 0.0, 1.0);
const double move_threshold = std::clamp((double)threshold, 0.0, 1.0);
const double fast_threshold =
wf::clamp((double)delta_threshold, 0.0, 1000.0);
std::clamp((double)delta_threshold, 0.0, 1000.0);

wf::point_t target_delta = {0, 0};
wf::point_t target_workspace = {state.vx, state.vy};
Expand Down
2 changes: 1 addition & 1 deletion plugins/single_plugins/zoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class wayfire_zoom_screen : public wf::per_output_plugin_instance_t
{
float target = progression.end;
target -= target * delta * speed;
target = wf::clamp(target, 1.0f, 50.0f);
target = std::clamp(target, 1.0f, 50.0f);

if (target != progression.end)
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/tile/tree-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void resize_view_controller_t::adjust_geometry(int32_t& x1, int32_t& len1,
int maxNegative = std::max(0, len1 - MIN_SIZE);

/* Make sure we don't shrink one dimension too much */
delta = clamp(delta, -maxNegative, maxPositive);
delta = std::clamp(delta, -maxNegative, maxPositive);

/* Adjust sizes */
len1 += delta;
Expand Down
4 changes: 2 additions & 2 deletions plugins/wobbly/wobbly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ extern "C"
{
double wobbly_settings_get_friction()
{
return wf::clamp((double)wobbly_settings::friction,
return std::clamp((double)wobbly_settings::friction,
MINIMAL_FRICTION, MAXIMAL_FRICTION);
}

double wobbly_settings_get_spring_k()
{
return wf::clamp((double)wobbly_settings::spring_k,
return std::clamp((double)wobbly_settings::spring_k,
MINIMAL_SPRING_K, MAXIMAL_SPRING_K);
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/api/wayfire/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ wf::point_t operator -(const wf::point_t& a, const wf::point_t& b);

wf::point_t operator -(const wf::point_t& a);

/** Return the closest valume to @value which is in [@min, @max] */
template<class T>
T clamp(T value, T min, T max)
{
return std::min(std::max(value, min), max);
}

/**
* Return the closest geometry to window which is completely inside the output.
* The returned geometry might be smaller, but never bigger than window.
Expand Down
8 changes: 4 additions & 4 deletions src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ wf::geometry_t wf::geometry_intersection(const wf::geometry_t& r1,

wf::geometry_t wf::clamp(wf::geometry_t window, wf::geometry_t output)
{
window.width = wf::clamp(window.width, 0, output.width);
window.height = wf::clamp(window.height, 0, output.height);
window.width = std::clamp(window.width, 0, output.width);
window.height = std::clamp(window.height, 0, output.height);

window.x = wf::clamp(window.x,
window.x = std::clamp(window.x,
output.x, output.x + output.width - window.width);
window.y = wf::clamp(window.y,
window.y = std::clamp(window.y,
output.y, output.y + output.height - window.height);

return window;
Expand Down
8 changes: 4 additions & 4 deletions src/output/render-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ struct repaint_delay_manager_t
// We rendered last frame on time
if (get_current_time() - last_increase >= increase_window)
{
increase_window = clamp(int64_t(increase_window * 0.75),
increase_window = std::clamp(int64_t(increase_window * 0.75),
MIN_INCREASE_WINDOW, MAX_INCREASE_WINDOW);
update_delay(+1);
reset_increase_timer();
Expand All @@ -870,12 +870,12 @@ struct repaint_delay_manager_t
// We missed last frame.
update_delay(-consecutive_decrease);
// Next decrease should be faster
consecutive_decrease = clamp(consecutive_decrease * 2, 1, 32);
consecutive_decrease = std::clamp(consecutive_decrease * 2, 1, 32);

// Next increase should be tried after a longer interval
if (expand_inc_window_on_miss >= 0)
{
increase_window = clamp(increase_window * 2,
increase_window = std::clamp(increase_window * 2,
MIN_INCREASE_WINDOW, MAX_INCREASE_WINDOW);
}

Expand Down Expand Up @@ -912,7 +912,7 @@ struct repaint_delay_manager_t
max = config_delay;
}

delay = clamp(delay + delta, min, max);
delay = std::clamp(delay + delta, min, max);
}

void reset_increase_timer()
Expand Down
4 changes: 2 additions & 2 deletions src/output/workspace-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ struct grid_size_manager_t

wf::point_t closest_valid_ws(wf::point_t workspace)
{
workspace.x = wf::clamp(workspace.x, 0, grid.width - 1);
workspace.y = wf::clamp(workspace.y, 0, grid.height - 1);
workspace.x = std::clamp(workspace.x, 0, grid.width - 1);
workspace.y = std::clamp(workspace.y, 0, grid.height - 1);
return workspace;
}

Expand Down