Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Math::Ramp< T > Class Template Reference

Interpolated gradient for smoothly transitioning between values. More...

#include <Ramp.hpp>

Inheritance diagram for Infinity::Types::Math::Ramp< T >:
[legend]
Collaboration diagram for Infinity::Types::Math::Ramp< T >:
[legend]

Public Member Functions

 Ramp ()=default
 Default constructor.
 
std::unique_ptr< Core::Baseclone () const override
 
 Ramp (std::vector< Stop< T > > inputStops, Interpolation interp=Interpolation::Linear)
 Constructs a ramp from a vector of stops.
 
bool operator== (const Ramp< T > &other) const
 Equality comparison operator.
 
bool operator!= (const Ramp< T > &other) const
 Inequality comparison operator.
 
const Infinity::Types::TypeIDtypeId () const override
 Gets the runtime type identifier for this Ramp<T> specialization.
 
sample (float position) const
 Samples the ramp at a given position.
 
- Public Member Functions inherited from Infinity::Types::Core::Data
 Data ()
 
 Data (const Data &other)
 
 Data (Data &&other)
 
Dataoperator= (const Data &other)
 
Dataoperator= (Data &&other)
 
virtual ~Data ()
 Virtual destructor.
 
bool hasProperty (const std::string &key) const
 
template<typename T >
void setProperty (const std::string &key, T &&value)
 Sets a typed property value.
 
template<typename T >
void setProperty (const std::string &key, const T &value)
 Sets a typed property value.
 
void setProperty (const std::string &key, PropertyValue &&value)
 Sets a typed property value.
 
const PropertyValuegetProperty (const std::string &key) const
 Gets a property value without type checking.
 
template<typename T >
const T & getProperty (const std::string &key) const
 Gets a typed property value.
 
void removeProperty (const std::string &key)
 
- Public Member Functions inherited from Infinity::Types::Core::Base
virtual ~Base ()
 Virtual destructor.
 
virtual std::istream & legibleDataRead (std::istream &in) override
 Deserializes the object from a single-line text representation.
 
virtual std::ostream & legibleDataWrite (std::ostream &out) const override
 Serializes the object to a single-line text representation.
 

Public Attributes

std::vector< Stop< T > > stops
 Collection of control points defining the ramp.
 
Interpolation interpolation = Interpolation::Linear
 Interpolation method used between stops.
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

template<typename T>
class Infinity::Types::Math::Ramp< T >

Interpolated gradient for smoothly transitioning between values.

Ramp provides a one-dimensional interpolation curve defined by a series of control points (Stops). It enables smooth transitions between values across a parameter range, with support for both linear and cubic interpolation.

Ramps are fundamental to procedural generation, providing control over:

  • Color gradients for textures and materials
  • Height/elevation curves for terrain generation
  • Density distributions for particle systems and volumes
  • Animation curves and easing functions
  • Falloff curves for blending and masking operations
  • Parameter transitions in procedural effects

The ramp automatically sorts stops by position and clamps sampling to the range defined by the first and last stops. Values between stops are interpolated using the specified interpolation method.

Example usage:

// Create a height curve for terrain
ValueRamp heightCurve;
heightCurve.stops = {
ValueStop(0.0f, 0.0f), // Sea level at start
ValueStop(0.3f, 0.2f), // Gentle slope
ValueStop(0.7f, 0.9f), // Steep mountain
ValueStop(1.0f, 1.0f) // Peak
};
heightCurve.interpolation = Interpolation::Cubic;
// Sample the curve
float height = heightCurve.sample(0.5f);
// Create a color gradient
Value3Ramp colorGradient({
Value3Stop(0.0f, Vector3(0, 0, 0.5)), // Dark blue
Value3Stop(0.5f, Vector3(0, 1, 1)), // Cyan
Value3Stop(1.0f, Vector3(1, 1, 1)) // White
}, Interpolation::Linear);
Vector3 color = colorGradient.sample(0.25f);
// Create an alpha falloff curve
ValueRamp alphaFalloff({
ValueStop(0.0f, 1.0f), // Full opacity at center
ValueStop(0.8f, 0.8f), // Gradual fadeout
ValueStop(1.0f, 0.0f) // Transparent at edge
});
Interpolated gradient for smoothly transitioning between values.
Definition Ramp.hpp:90
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
Interpolation interpolation
Interpolation method used between stops.
Definition Ramp.hpp:108
Ramp< float > ValueRamp
Alias for Ramp<float>, a scalar interpolation curve.
Definition Ramp.hpp:285
Stop< Vector3 > Value3Stop
Alias for Stop<Vector3>, a 3D vector gradient control point.
Definition Stop.hpp:219
Stop< float > ValueStop
Alias for Stop<float>, a scalar gradient control point.
Definition Stop.hpp:196
t_Vector3< float > Vector3
Alias for t_Vector3<float>, the default 3D vector type.
Definition Vector3.hpp:580
Template Parameters
TThe type of value to interpolate (float, Vector2, Vector3, Vector4).
Note
Stops are automatically sorted by position during construction.
Sampling outside the stop range returns the value of the first or last stop.
Empty ramps return a default-constructed value when sampled.
See also
Stop, Interpolation
ValueRamp, Value2Ramp, Value3Ramp, Value4Ramp

Constructor & Destructor Documentation

◆ Ramp() [1/2]

template<typename T >
Infinity::Types::Math::Ramp< T >::Ramp ( )
default

Default constructor.

Creates an empty ramp with linear interpolation.

◆ Ramp() [2/2]

template<typename T >
Infinity::Types::Math::Ramp< T >::Ramp ( std::vector< Stop< T > >  inputStops,
Interpolation  interp = Interpolation::Linear 
)
inline

Constructs a ramp from a vector of stops.

Creates a ramp with the specified stops and interpolation method. Stops are automatically sorted by position.

Parameters
inputStopsVector of stops defining the ramp.
interpInterpolation method to use (default: Linear).
std::vector<ValueStop> stops = {
ValueStop(0.0f, 0.0f),
ValueStop(1.0f, 1.0f),
ValueStop(0.5f, 0.8f) // Out of order, will be sorted
};
ValueRamp ramp(stops, Interpolation::Cubic);

Member Function Documentation

◆ clone()

template<typename T >
std::unique_ptr< Core::Base > Infinity::Types::Math::Ramp< T >::clone ( ) const
inlineoverridevirtual

Reimplemented from Infinity::Types::Core::Data.

◆ operator!=()

template<typename T >
bool Infinity::Types::Math::Ramp< T >::operator!= ( const Ramp< T > &  other) const
inline

Inequality comparison operator.

Parameters
otherThe ramp to compare against.
Returns
true if ramps differ.

◆ operator==()

template<typename T >
bool Infinity::Types::Math::Ramp< T >::operator== ( const Ramp< T > &  other) const
inline

Equality comparison operator.

Two ramps are equal if they have the same stops (in the same order) and the same interpolation method.

Parameters
otherThe ramp to compare against.
Returns
true if ramps are equal.

◆ sample()

template<typename T >
T Infinity::Types::Math::Ramp< T >::sample ( float  position) const
inline

Samples the ramp at a given position.

Evaluates the ramp at the specified position, interpolating between stops using the configured interpolation method. The behavior depends on the position relative to the stop range:

  • Before first stop: Returns first stop's value
  • After last stop: Returns last stop's value
  • Between stops: Interpolates using the interpolation method
  • Empty ramp: Returns default-constructed value
Parameters
positionThe position to sample at (typically 0-1, but any value is valid).
Returns
The interpolated value at the given position.
ValueRamp ramp({
ValueStop(0.0f, 0.0f),
ValueStop(1.0f, 1.0f)
});
float value = ramp.sample(0.5f); // Returns 0.5 (linear interpolation)
float clamped = ramp.sample(-0.5f); // Returns 0.0 (clamped to first stop)
float overflow = ramp.sample(2.0f); // Returns 1.0 (clamped to last stop)

◆ typeId()

template<typename T >
const Infinity::Types::TypeID & Infinity::Types::Math::Ramp< T >::typeId ( ) const
inlineoverridevirtual

Gets the runtime type identifier for this Ramp<T> specialization.

Returns
Const reference to the TypeID for Ramp<T>.

Reimplemented from Infinity::Types::Core::Data.

Member Data Documentation

◆ interpolation

template<typename T >
Interpolation Infinity::Types::Math::Ramp< T >::interpolation = Interpolation::Linear

Interpolation method used between stops.

Determines how values are interpolated between control points:

  • Linear: Straight-line interpolation (sharp transitions)
  • Cubic: Smooth Hermite interpolation (gradual transitions)

◆ stops

template<typename T >
std::vector<Stop<T> > Infinity::Types::Math::Ramp< T >::stops

Collection of control points defining the ramp.

Stops should be added in any order; they will be automatically sorted by position. Each stop defines a value at a specific position along the parameter axis.