libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Point< T, NumValues > Class Template Reference

N-dimensional point with arithmetic, interpolation, and serialization. More...

#include <point.h>

Public Member Functions

 Point ()
 Default constructor. Initializes all values to zero.
 
 Point (const Array< T, NumValues > &val)
 Constructs a Point from an Array.
 
template<typename... Args>
 Point (Args... args)
 Constructs a Point from individual component values.
 
 Point (const String &str)
 Constructs a Point by parsing a comma-separated string.
 
virtual ~Point ()
 Destructor.
 
 operator String () const
 Converts the Point to a comma-separated String.
 
 operator const Array< T, NumValues > & () const
 Converts the Point to a const Array reference.
 
bool operator== (const Array< T, NumValues > &val) const
 Returns true if this Point equals the given Array.
 
bool operator!= (const Array< T, NumValues > &val) const
 Returns true if this Point does not equal the given Array.
 
Pointoperator+= (const Array< T, NumValues > &val)
 Adds the given Array component-wise to this Point.
 
Pointoperator-= (const Array< T, NumValues > &val)
 Subtracts the given Array component-wise from this Point.
 
Pointoperator*= (const Array< T, NumValues > &val)
 Multiplies this Point component-wise by the given Array.
 
Pointoperator/= (const Array< T, NumValues > &val)
 Divides this Point component-wise by the given Array.
 
NumValues lerp (const Point< T, NumValues > &other, double t) const
 
template<typename U >
Point< T, NumValuesclamp (const Point< U, NumValues > &minVal, const Point< U, NumValues > &maxVal) const
 Clamps each component of the Point to the given min and max bounds.
 
bool isWithinBounds (const Point< T, NumValues > &min, const Point< T, NumValues > &max) const
 Returns true if all components are within the given min and max bounds (inclusive).
 

Static Public Member Functions

static Error fromString (const String &val, Point &d)
 Parses a comma-separated string into a Point.
 
static Point fromString (const String &str, Error *err=nullptr)
 Parses a comma-separated string into a Point.
 

Public Attributes

 int
 

Friends

Point operator+ (const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
 Returns the component-wise sum of two Arrays as a Point.
 
Point operator- (const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
 Returns the component-wise difference of two Arrays as a Point.
 
Point operator* (const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
 Returns the component-wise product of two Arrays as a Point.
 
Point operator/ (const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
 Returns the component-wise quotient of two Arrays as a Point.
 

Detailed Description

template<typename T, size_t NumValues>
class Point< T, NumValues >

N-dimensional point with arithmetic, interpolation, and serialization.

A generic point class that stores NumValues components of type T, backed by an Array. Named accessors (x, y, z) are conditionally available depending

Example
Point<float, 2> a(1.0f, 2.0f);
Point<float, 2> b(3.0f, 4.0f);
auto c = a + b; // (4.0, 6.0)
float dist = a.dist(b); // distance between a and b
Dynamic array container wrapping std::vector.
Definition list.h:40
on the number of dimensions. Supports parsing from and formatting to comma-separated strings.
Template Parameters
TThe component value type (e.g. int, float, double).
NumValuesThe number of dimensions.

Member Function Documentation

◆ clamp()

template<typename T , size_t NumValues>
template<typename U >
Point< T, NumValues > Point< T, NumValues >::clamp ( const Point< U, NumValues > &  minVal,
const Point< U, NumValues > &  maxVal 
) const
inline

Clamps each component of the Point to the given min and max bounds.

Parameters
minValThe minimum bounds per component.
maxValThe maximum bounds per component.
Returns
A new Point with each component clamped to the specified range.

◆ fromString() [1/2]

template<typename T , size_t NumValues>
static Point Point< T, NumValues >::fromString ( const String str,
Error err = nullptr 
)
inlinestatic

Parses a comma-separated string into a Point.

Parameters
strThe string to parse.
errOptional pointer to receive the error result.
Returns
The parsed Point, or a default-constructed Point on failure.

◆ fromString() [2/2]

template<typename T , size_t NumValues>
static Error Point< T, NumValues >::fromString ( const String val,
Point< T, NumValues > &  d 
)
inlinestatic

Parses a comma-separated string into a Point.

Parameters
valThe string to parse.
dThe Point to populate with parsed values.
Returns
Error::Ok on success, Error::Invalid on failure.

◆ isWithinBounds()

template<typename T , size_t NumValues>
bool Point< T, NumValues >::isWithinBounds ( const Point< T, NumValues > &  min,
const Point< T, NumValues > &  max 
) const
inline

Returns true if all components are within the given min and max bounds (inclusive).

Parameters
minThe minimum bounds per component.
maxThe maximum bounds per component.
Returns
True if every component is within the specified range.

Member Data Documentation

◆ int

template<typename T , size_t NumValues>
Point< T, NumValues >::int
Initial value:
= 0> T &x() {
return d[0];
}
template<size_t N = NumValues

The documentation for this class was generated from the following file: