[algs] Add hb_clamp

Similar to stl and glsl's clamp
This commit is contained in:
Ebrahim Byagowi 2020-03-04 11:18:19 +03:30 committed by GitHub
parent 558f922788
commit b398748d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -360,6 +360,13 @@ struct
(hb_forward<T> (a) >= hb_forward<T2> (b) ? hb_forward<T> (a) : hb_forward<T2> (b))
}
HB_FUNCOBJ (hb_max);
struct
{
template <typename T, typename T2, typename T3> constexpr auto
operator () (T&& x, T2&& min, T3&& max) const HB_AUTO_RETURN
(hb_min (hb_max (hb_forward<T> (x), hb_forward<T2> (min)), hb_forward<T3> (max)))
}
HB_FUNCOBJ (hb_clamp);
/*

View File

@ -229,7 +229,7 @@ struct fvar
hb_ot_var_axis_info_t axis;
get_axis_info (axis_index, &axis);
v = hb_max (hb_min (v, axis.max_value), axis.min_value); /* Clamp. */
v = hb_clamp (v, axis.min_value, axis.max_value);
if (v == axis.default_value)
return 0;

View File

@ -201,8 +201,8 @@ struct hb_sanitize_context_t :
if (unlikely (hb_unsigned_mul_overflows (this->end - this->start, HB_SANITIZE_MAX_OPS_FACTOR)))
this->max_ops = HB_SANITIZE_MAX_OPS_MAX;
else
this->max_ops = hb_min (hb_max ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR,
(unsigned) HB_SANITIZE_MAX_OPS_MIN),
this->max_ops = hb_clamp ((unsigned) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR,
(unsigned) HB_SANITIZE_MAX_OPS_MIN,
(unsigned) HB_SANITIZE_MAX_OPS_MAX);
this->edit_count = 0;
this->debug_depth = 0;