3/////////////////////////////////////////////////
4template <typename Type>
5constexpr sf::Vector2<Type> round (const sf::Vector2<Type>& value)
7 return sf::Vector2<Type> { std::round (value.x), std::round (value.y) };
10/////////////////////////////////////////////////
11template <typename Type>
12constexpr sf::Vector2<Type> round (const sf::Vector3<Type>& value)
14 return sf::Vector3<Type> { std::round (value.x), std::round (value.y), std::round (value.z) };
17/////////////////////////////////////////////////
18template <typename Type>
24 if constexpr (std::is_same_v <Type, sf::Color>) {
25 const uint32_t red = lerp (min.r, max.r, value);
26 const uint32_t green = lerp (min.g, max.g, value);
27 const uint32_t blue = lerp (min.b, max.b, value);
28 const uint32_t alpha = lerp (min.a, max.a, value);
29 return sf::Color (red, green, blue, alpha);
31 return (1.f - value)*min + value*max;
34/////////////////////////////////////////////////
35template <typename Type>
41 return std::min (max, std::max (value, min));
44/////////////////////////////////////////////////
45template <typename Type>
46constexpr Type clampedLerp (
51 return clamp (min, max, lerp (min, max, value));
54/////////////////////////////////////////////////
55template <typename Type>
56constexpr float inverseLerp (
61 auto fMin = static_cast<float> (min);
62 auto fMax = static_cast<float> (max);
63 auto fValue = static_cast<float> (value);
64 return clamp (0.f, 1.f, (fValue - fMin) / (fMax - fMin));
67/////////////////////////////////////////////////
68template <typename InputType,
70constexpr OutputType remap (
71 const InputType& minInput,
72 const InputType& maxInput,
73 const OutputType& minOutput,
74 const OutputType& maxOutput,
75 const InputType& value)
77 auto t = inverseLerp (minInput, maxInput, value);
78 return clampedLerp (minOutput, maxOutput, t);