5#include <Infinity/Types/Core/Data.hpp>
6#include <Infinity/Types/Math/Stop.hpp>
21 enum class INFINITY_API_TEMPLATE Interpolation
108 Interpolation interpolation = Interpolation::Linear;
117 std::unique_ptr<Core::Base>
clone()
const override
119 return std::make_unique<Ramp<T>>(*this);
140 Ramp(std::vector<
Stop<T>> inputStops, Interpolation interp = Interpolation::Linear) : interpolation(interp)
142 stops = std::move(inputStops);
143 std::sort(stops.begin(), stops.end(), [](
const Stop<T>& a,
const Stop<T>& b) {
144 return a.position < b.position;
170 return !(*
this == other);
212 if (position <= stops.front().position)
214 return stops.front().value;
217 if (position >= stops.back().position)
219 return stops.back().value;
222 for (
size_t i = 0; i < stops.size() - 1; ++i)
224 const auto& a = stops[i];
225 const auto& b = stops[i + 1];
227 if (position >= a.position && position <= b.position)
229 float t = (position - a.position) / (b.position - a.position);
230 return (interpolation == Interpolation::Linear)
231 ?
lerp(a.value, b.value, t)
232 : cubicInterp(a.value, b.value, t);
250 T
lerp(
const T& a,
const T& b,
float t)
const
252 return a + (b - a) * t;
267 T cubicInterp(
const T& a,
const T& b,
float t)
const {
270 return a * (2.0f * t3 - 3.0f * t2 + 1.0f) +
271 b * (-2.0f * t3 + 3.0f * t2);
Base class for complex data types with memory wrapping and property support.
Definition Data.hpp:49
Interpolated gradient for smoothly transitioning between values.
Definition Ramp.hpp:90
std::unique_ptr< Core::Base > clone() const override
Definition Ramp.hpp:117
const Infinity::Types::TypeID & typeId() const override
Gets the runtime type identifier for this Ramp<T> specialization.
Definition Ramp.hpp:178
T sample(float position) const
Samples the ramp at a given position.
Definition Ramp.hpp:205
std::vector< Stop< T > > stops
Collection of control points defining the ramp.
Definition Ramp.hpp:99
bool operator!=(const Ramp< T > &other) const
Inequality comparison operator.
Definition Ramp.hpp:168
Interpolation interpolation
Interpolation method used between stops.
Definition Ramp.hpp:108
Ramp(std::vector< Stop< T > > inputStops, Interpolation interp=Interpolation::Linear)
Constructs a ramp from a vector of stops.
Definition Ramp.hpp:140
bool operator==(const Ramp< T > &other) const
Equality comparison operator.
Definition Ramp.hpp:157
Ramp()=default
Default constructor.
Vector3 INFINITY_API_PUBLIC lerp(const Vector3 &a, const Vector3 &b, float t)
Linear interpolation between two 3D vectors.
Represents a control point in a gradient or interpolation ramp.
Definition Stop.hpp:64
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71