Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Spatial::Spline2D Class Reference

Two-dimensional spline curve for procedural path and shape generation. More...

#include <Spline.hpp>

Inheritance diagram for Infinity::Types::Spatial::Spline2D:
[legend]
Collaboration diagram for Infinity::Types::Spatial::Spline2D:
[legend]

Public Types

using Vec = Math::Vector2
 

Public Member Functions

 Spline2D ()
 Default constructor.
 
 Spline2D (SplineKind kind)
 Constructs a spline with specified interpolation type.
 
 Spline2D (const Spline2D &other)
 Copy constructor.
 
virtual ~Spline2D ()
 Destructor.
 
std::unique_ptr< Core::Baseclone () const override
 
Spline2Doperator= (const Spline2D &other)
 Copy assignment operator.
 
Vec evaluate (float t) const
 Evaluates the spline position at parameter t.
 
Vec tangent (float t) const
 Computes the tangent vector at parameter t.
 
void setCurveKind (SplineKind kind)
 Changes the spline interpolation type.
 
SplineKind type () const
 Gets the current spline interpolation type.
 
const Infinity::Types::TypeIDtypeId () const override
 Gets the TypeID for Spline2D.
 
- 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

Containers::Array< Vecpoints
 Control points defining the spline curve.
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Two-dimensional spline curve for procedural path and shape generation.

Spline2D provides smooth curve interpolation through 2D control points using various mathematical methods (Bezier, Catmull-Rom, B-Spline, or Linear). It is fundamental for procedural generation of:

  • 2D paths and roads
  • River and coastline generation
  • Profile curves for extrusion
  • 2D shape outlines and boundaries
  • Animation paths in 2D space
  • Contour lines and level curves

The spline can be evaluated at any parametric position t ∈ [0, 1] to obtain interpolated positions and tangent vectors along the curve. Control points are stored in a public Array for direct manipulation.

Note
The parameter t is normalized: 0 = start of curve, 1 = end of curve.
Tangent vectors are not normalized - normalize manually if unit vectors are needed.
Different SplineKind values produce different curve behaviors.

Example usage:

// Create a Catmull-Rom spline for a river path
Spline2D river(SplineKind::CatmullRom);
river.points.push_back(Vector2{0.0f, 0.0f});
river.points.push_back(Vector2{100.0f, 50.0f});
river.points.push_back(Vector2{200.0f, 60.0f});
river.points.push_back(Vector2{300.0f, 30.0f});
// Sample the curve for mesh generation
Array<Vector2> riverMesh;
for (int i = 0; i <= 100; ++i) {
float t = i / 100.0f;
riverMesh.push_back(river.evaluate(t));
}
// Get tangent for perpendicular offset (road width)
Vector2 tangent = river.tangent(0.5f);
Vector2 normal = Vector2{-tangent.y, tangent.x}.normalized();
Vector2 offset = normal * roadWidth;
// Use with ProceduralSystem
system->setIn("path_spline", std::move(river));
Two-dimensional spline curve for procedural path and shape generation.
Definition Spline.hpp:114
Vec tangent(float t) const
Computes the tangent vector at parameter t.
t_Vector2< float > Vector2
Alias for t_Vector2<float>, the default 2D vector type.
Definition Vector2.hpp:487
T y
Cartesian coordinate interpretation.
Definition Vector2.hpp:90
T x
Definition Vector2.hpp:90

Member Typedef Documentation

◆ Vec

Constructor & Destructor Documentation

◆ Spline2D() [1/3]

Infinity::Types::Spatial::Spline2D::Spline2D ( )

Default constructor.

Creates an empty spline with Bezier interpolation.

◆ Spline2D() [2/3]

Infinity::Types::Spatial::Spline2D::Spline2D ( SplineKind  kind)
explicit

Constructs a spline with specified interpolation type.

Parameters
kindInterpolation method to use (Bezier, CatmullRom, BSpline, or Linear).

◆ Spline2D() [3/3]

Infinity::Types::Spatial::Spline2D::Spline2D ( const Spline2D other)

Copy constructor.

Creates a deep copy of the spline, including all control points and settings.

Parameters
otherSpline to copy from.

◆ ~Spline2D()

virtual Infinity::Types::Spatial::Spline2D::~Spline2D ( )
virtual

Destructor.

Member Function Documentation

◆ clone()

std::unique_ptr< Core::Base > Infinity::Types::Spatial::Spline2D::clone ( ) const
overridevirtual

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

◆ evaluate()

Vec Infinity::Types::Spatial::Spline2D::evaluate ( float  t) const

Evaluates the spline position at parameter t.

Computes the interpolated position on the curve at the given parameter value. The curve is parameterized from 0 (start) to 1 (end).

Parameters
tParameter value in range [0, 1].
Returns
Interpolated position on the curve.
Note
Values of t outside [0, 1] may extrapolate or clamp depending on implementation.
Requires at least the minimum number of control points for the chosen SplineKind.

◆ operator=()

Spline2D & Infinity::Types::Spatial::Spline2D::operator= ( const Spline2D other)

Copy assignment operator.

Parameters
otherSpline to copy from.
Returns
Reference to this spline.

◆ setCurveKind()

void Infinity::Types::Spatial::Spline2D::setCurveKind ( SplineKind  kind)

Changes the spline interpolation type.

Switches between different curve types (Bezier, Catmull-Rom, B-Spline, Linear) while preserving the control points.

Parameters
kindNew interpolation method to use.
Note
The same control points may produce very different curves with different kinds.

◆ tangent()

Vec Infinity::Types::Spatial::Spline2D::tangent ( float  t) const

Computes the tangent vector at parameter t.

Calculates the derivative of the curve at the given parameter, providing the direction of the curve at that point. Useful for:

  • Computing normals (perpendicular to tangent)
  • Orienting objects along the curve
  • Calculating curve speed/velocity
Parameters
tParameter value in range [0, 1].
Returns
Tangent vector at the specified position.
Note
The tangent vector is NOT normalized - normalize it manually if needed.
The magnitude represents the "speed" of parameterization.

◆ type()

SplineKind Infinity::Types::Spatial::Spline2D::type ( ) const

Gets the current spline interpolation type.

Returns
Current SplineKind being used for interpolation.

◆ typeId()

const Infinity::Types::TypeID & Infinity::Types::Spatial::Spline2D::typeId ( ) const
overridevirtual

Gets the TypeID for Spline2D.

Returns
TypeID identifying this Spline2D type.

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

Member Data Documentation

◆ points

Containers::Array<Vec> Infinity::Types::Spatial::Spline2D::points

Control points defining the spline curve.

Public array of Vector2 control points that define the curve shape. Modify this array directly to change the spline geometry.

Note
For Bezier curves, points are interpreted as control points (curve may not pass through them).
For Catmull-Rom curves, the curve passes through all control points.
For B-Splines, points are control points with local influence.
For Linear curves, points are connected by straight line segments.