maths: rename limit to clamp
This commit is contained in:
parent
93ddd4c11d
commit
b01173d82b
@ -71,7 +71,7 @@ namespace util {
|
||||
bezier<1>::distance (util::point2f q) const noexcept
|
||||
{
|
||||
const auto ab = m_points[1] - m_points[0];
|
||||
const auto t = limit (closest (q), 0.f, 1.f);
|
||||
const auto t = clamp (closest (q), 0.f, 1.f);
|
||||
const auto p = m_points[0] + t * ab;
|
||||
|
||||
return util::distance (q, p);
|
||||
|
@ -1001,7 +1001,7 @@ namespace util {
|
||||
>
|
||||
>
|
||||
constexpr auto
|
||||
limit (K k, K lo, K hi)
|
||||
clamp (K k, K lo, K hi)
|
||||
{
|
||||
assert (all (lo <= hi));
|
||||
return max (min (k, hi), lo);
|
||||
@ -1016,9 +1016,9 @@ namespace util {
|
||||
>
|
||||
>
|
||||
constexpr auto
|
||||
limit (K k, typename K::value_type lo, K hi)
|
||||
clamp (K k, typename K::value_type lo, K hi)
|
||||
{
|
||||
return limit (k, K {lo}, hi);
|
||||
return clamp (k, K {lo}, hi);
|
||||
}
|
||||
|
||||
|
||||
@ -1030,9 +1030,9 @@ namespace util {
|
||||
>
|
||||
>
|
||||
constexpr auto
|
||||
limit (K k, K lo, typename K::value_type hi)
|
||||
clamp (K k, K lo, typename K::value_type hi)
|
||||
{
|
||||
return limit (k, lo, K {hi});
|
||||
return clamp (k, lo, K {hi});
|
||||
}
|
||||
|
||||
|
||||
@ -1044,9 +1044,9 @@ namespace util {
|
||||
>
|
||||
>
|
||||
constexpr auto
|
||||
limit (K k, typename K::value_type lo, typename K::value_type hi)
|
||||
clamp (K k, typename K::value_type lo, typename K::value_type hi)
|
||||
{
|
||||
return limit (k, K {lo}, K {hi});
|
||||
return clamp (k, K {lo}, K {hi});
|
||||
}
|
||||
|
||||
|
||||
|
@ -68,7 +68,7 @@ namespace util::geom {
|
||||
point<S,T>
|
||||
closest (point<S,T> query) const
|
||||
{
|
||||
return limit (query, lo, hi);
|
||||
return clamp (query, lo, hi);
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +36,5 @@ template uint64_t util::log2up (uint64_t);
|
||||
// so it's easier to instantiate early and check for broken code at library
|
||||
// build time.
|
||||
|
||||
template float util::limit (float, float, float);
|
||||
|
||||
template float util::smoothstep (float, float, float);
|
||||
template double util::smoothstep (double, double, double);
|
||||
|
@ -713,7 +713,7 @@ namespace util {
|
||||
std::is_scalar_v<T> && std::is_scalar_v<U> && std::is_scalar_v<V>,
|
||||
std::common_type_t<T,U,V>
|
||||
>
|
||||
limit (const T val, const U lo, const V hi)
|
||||
clamp (const T val, const U lo, const V hi)
|
||||
{
|
||||
assert (lo <= hi);
|
||||
|
||||
@ -731,7 +731,7 @@ namespace util {
|
||||
smoothstep (T a, T b, T x)
|
||||
{
|
||||
assert (a <= b);
|
||||
x = limit ((x - a) / (b - a), T{0}, T{1});
|
||||
x = clamp ((x - a) / (b - a), T{0}, T{1});
|
||||
return x * x * (3 - 2 * x);
|
||||
}
|
||||
|
||||
@ -787,7 +787,7 @@ namespace util {
|
||||
size_t available = sizeof (U) * 8;
|
||||
size_t shift = std::max (available, usable) - usable;
|
||||
|
||||
t = limit (t, 0, 1);
|
||||
t = clamp (t, 0, 1);
|
||||
|
||||
// construct an integer of the float's mantissa size, multiply it by our
|
||||
// parameter, then shift it back into the full range of the integer type.
|
||||
|
@ -172,7 +172,7 @@ typename region<S,T>::point_t
|
||||
region<S,T>::constrain (point_t q) const noexcept
|
||||
{
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
q[i] = limit (q[i], p[i], p[i] + e[i]);
|
||||
q[i] = clamp (q[i], p[i], p[i] + e[i]);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
@ -78,17 +78,17 @@ main (void)
|
||||
tap.expect_eq (select (a > b, a, b), hi, "select with points and max");
|
||||
};
|
||||
|
||||
// ensure that util::limit resolves to the coord overload. the exact
|
||||
// ensure that util::clamp resolves to the coord overload. the exact
|
||||
// values are less useful than exercising the compiler/linker.
|
||||
{
|
||||
const util::vector3f val { 0, -1, 2 };
|
||||
const util::vector3f lo { -1, 1, -2 };
|
||||
const util::vector3f hi { 1, 2, 0 };
|
||||
|
||||
tap.expect_eq (limit (val, lo, hi), util::vector3f { 0, 1, 0 }, "limit with vec/vec/vec");
|
||||
tap.expect_eq (limit (val, 0.f, hi), util::vector3f { 0, 0, 0 }, "limit with vec/num/vec");
|
||||
tap.expect_eq (limit (val, lo, 2.f), util::vector3f { 0, 1, 2 }, "limit with vec/vec/num");
|
||||
tap.expect_eq (limit (val, 0.f, 2.f), util::vector3f { 0, 0, 2 }, "limit with vec/num/num");
|
||||
tap.expect_eq (clamp (val, lo, hi), util::vector3f { 0, 1, 0 }, "clamp with vec/vec/vec");
|
||||
tap.expect_eq (clamp (val, 0.f, hi), util::vector3f { 0, 0, 0 }, "clamp with vec/num/vec");
|
||||
tap.expect_eq (clamp (val, lo, 2.f), util::vector3f { 0, 1, 2 }, "clamp with vec/vec/num");
|
||||
tap.expect_eq (clamp (val, 0.f, 2.f), util::vector3f { 0, 0, 2 }, "clamp with vec/num/num");
|
||||
}
|
||||
|
||||
// ensure that klass::indices appears to link correctly
|
||||
|
Loading…
Reference in New Issue
Block a user