pbpt
Loading...
Searching...
No Matches
pbpt::math::Point< T, N > Class Template Reference

A template class for an N-dimensional point in space. More...

#include <point.hpp>

Public Member Functions

constexpr Point () noexcept
 Default constructor. Initializes the point at the origin.
constexpr Point (const Vector< T, N > &vec) noexcept
 Constructs a point from a coordinate vector.
template<std::convertible_to< T >... Args>
requires (sizeof...(Args) == N)
constexpr Point (Args &&... args) noexcept
 Constructs a point from a list of individual coordinate values.
constexpr T & x () noexcept
 Accesses the first coordinate (x-axis).
constexpr T & y () noexcept
 Accesses the second coordinate (y-axis).
constexpr T & z () noexcept
 Accesses the third coordinate (z-axis).
constexpr T & w () noexcept
 Accesses the fourth coordinate (w-axis).
constexpr T x () const noexcept
 Const access to the first coordinate (x-axis).
constexpr T y () const noexcept
 Const access to the second coordinate (y-axis).
constexpr T z () const noexcept
 Const access to the third coordinate (z-axis).
constexpr T w () const noexcept
 Const access to the fourth coordinate (w-axis).
constexpr int dims () const noexcept
 Returns the number of dimensions of the point.
constexpr const T & operator[] (int index) const
 Provides const access to the point's coordinates by index.
constexpr T & operator[] (int index)
 Provides mutable access to the point's coordinates by index.
constexpr const T & at (int index) const
 Provides safe const access to the point's coordinates by index.
constexpr Vector< T, N > to_vector () const noexcept
 Explicitly converts the point to its underlying coordinate vector.
constexpr Pointoperator+= (const Vector< T, N > &rhs) noexcept
 Translates the point by adding a vector.
constexpr bool operator< (const Point &rhs) const
constexpr bool operator<= (const Point &rhs) const
constexpr bool operator> (const Point &rhs) const
 greater than
constexpr bool operator>= (const Point &rhs) const
 greater than or equal
constexpr bool operator== (const Point &rhs) const
 equal
constexpr Pointoperator-= (const Vector< T, N > &rhs) noexcept
 Translates the point by subtracting a vector.
constexpr Vector< T, N > operator- (const Point &rhs) const noexcept
 Rule 1: Calculates the displacement vector between two points (Point - Point = Vector).
constexpr Point operator+ (const Vector< T, N > &rhs) const noexcept
 Rule 2: Translates a point by a vector, resulting in a new point (Point + Vector = Point).
constexpr Point operator- (const Vector< T, N > &rhs) const noexcept
 Rule 3: Translates a point by the negative of a vector (Point - Vector = Point).
constexpr Point mid (const Point< T, N > &rhs) const noexcept
 Calculates the midpoint between two points.

Static Public Member Functions

static constexpr Point filled (T value) noexcept
 Creates a point filled with a specified value.
static constexpr Point zeros () noexcept
 Creates a point at the origin (0, 0, ...).
static constexpr Point ones () noexcept
 Creates a point with all coordinates set to one.

Friends

std::ostream & operator<< (std::ostream &os, const Point &point)
 Stream insertion operator for printing the point's coordinates.

Detailed Description

template<typename T, int N>
class pbpt::math::Point< T, N >

A template class for an N-dimensional point in space.

Represents a specific location in an N-dimensional affine space. Unlike a Vec, which represents direction and magnitude (a displacement), a Point represents a coordinate.

The class's interface enforces these geometric distinctions through its operator overloads:

  • You can subtract two points to get the vector between them (Point - Point = Vec).
  • You can add or subtract a vector to a point to get a new, translated point (Point +/- Vec = Point).
  • Operations like adding two points are deliberately not defined, as they are geometrically meaningless in most contexts.
Template Parameters
TThe underlying floating-point type of the point's coordinates.
NThe number of dimensions.
See also
Vec

Constructor & Destructor Documentation

◆ Point() [1/2]

template<typename T, int N>
pbpt::math::Point< T, N >::Point ( const Vector< T, N > & vec)
inlineexplicitconstexprnoexcept

Constructs a point from a coordinate vector.

Parameters
vecThe vector representing the point's coordinates from the origin.

◆ Point() [2/2]

template<typename T, int N>
template<std::convertible_to< T >... Args>
requires (sizeof...(Args) == N)
pbpt::math::Point< T, N >::Point ( Args &&... args)
inlineexplicitconstexprnoexcept

Constructs a point from a list of individual coordinate values.

The number of arguments must exactly match the point's dimension N.

Template Parameters
ArgsA parameter pack of types convertible to T.
Parameters
argsThe coordinate values.
Note
The number of arguments sizeof...(args) must be equal to N.

Member Function Documentation

◆ filled()

template<typename T, int N>
constexpr Point pbpt::math::Point< T, N >::filled ( T value)
inlinestaticconstexprnoexcept

Creates a point filled with a specified value.

Parameters
valueThe value to fill all coordinates with.
Returns
A new Point instance filled with the given value.

◆ mid()

template<typename T, int N>
Point pbpt::math::Point< T, N >::mid ( const Point< T, N > & rhs) const
inlineconstexprnoexcept

Calculates the midpoint between two points.

Parameters
rhsThe second point.
Returns
The point that lies exactly halfway between lhs and rhs.

◆ ones()

template<typename T, int N>
constexpr Point pbpt::math::Point< T, N >::ones ( )
inlinestaticconstexprnoexcept

Creates a point with all coordinates set to one.

Returns
A new Point instance with all coordinates set to 1.0.

◆ operator+()

template<typename T, int N>
Point pbpt::math::Point< T, N >::operator+ ( const Vector< T, N > & rhs) const
inlineconstexprnoexcept

Rule 2: Translates a point by a vector, resulting in a new point (Point + Vector = Point).

Parameters
rhsThe displacement vector.
Returns
The new, translated point.

◆ operator+=()

template<typename T, int N>
Point & pbpt::math::Point< T, N >::operator+= ( const Vector< T, N > & rhs)
inlineconstexprnoexcept

Translates the point by adding a vector.

Parameters
rhsThe displacement vector to add.
Returns
A reference to the modified point.

◆ operator-() [1/2]

template<typename T, int N>
Vector< T, N > pbpt::math::Point< T, N >::operator- ( const Point< T, N > & rhs) const
inlineconstexprnoexcept

Rule 1: Calculates the displacement vector between two points (Point - Point = Vector).

Parameters
rhsThe starting point.
Returns
The Vec<T, N> that goes from rhs to lhs.

◆ operator-() [2/2]

template<typename T, int N>
Point pbpt::math::Point< T, N >::operator- ( const Vector< T, N > & rhs) const
inlineconstexprnoexcept

Rule 3: Translates a point by the negative of a vector (Point - Vector = Point).

Parameters
rhsThe displacement vector to subtract.
Returns
The new, translated point.

◆ operator-=()

template<typename T, int N>
Point & pbpt::math::Point< T, N >::operator-= ( const Vector< T, N > & rhs)
inlineconstexprnoexcept

Translates the point by subtracting a vector.

Parameters
rhsThe displacement vector to subtract.
Returns
A reference to the modified point.

◆ operator==()

template<typename T, int N>
bool pbpt::math::Point< T, N >::operator== ( const Point< T, N > & rhs) const
inlineconstexpr

equal

Parameters
rhs
Returns
true
false

◆ to_vector()

template<typename T, int N>
Vector< T, N > pbpt::math::Point< T, N >::to_vector ( ) const
inlineconstexprnoexcept

Explicitly converts the point to its underlying coordinate vector.

This allows a point to be treated as a vector from the origin when an explicit cast is used.

Returns
The Vec<T, N> representing the point's coordinates.

◆ w() [1/2]

template<typename T, int N>
T pbpt::math::Point< T, N >::w ( ) const
inlineconstexprnoexcept

Const access to the fourth coordinate (w-axis).

Note
N > 3.

◆ w() [2/2]

template<typename T, int N>
T & pbpt::math::Point< T, N >::w ( )
inlineconstexprnoexcept

Accesses the fourth coordinate (w-axis).

Note
N > 3.

◆ x() [1/2]

template<typename T, int N>
T pbpt::math::Point< T, N >::x ( ) const
inlineconstexprnoexcept

Const access to the first coordinate (x-axis).

Note
N > 0.

◆ x() [2/2]

template<typename T, int N>
T & pbpt::math::Point< T, N >::x ( )
inlineconstexprnoexcept

Accesses the first coordinate (x-axis).

Note
N > 0.

◆ y() [1/2]

template<typename T, int N>
T pbpt::math::Point< T, N >::y ( ) const
inlineconstexprnoexcept

Const access to the second coordinate (y-axis).

Note
N > 1.

◆ y() [2/2]

template<typename T, int N>
T & pbpt::math::Point< T, N >::y ( )
inlineconstexprnoexcept

Accesses the second coordinate (y-axis).

Note
N > 1.

◆ z() [1/2]

template<typename T, int N>
T pbpt::math::Point< T, N >::z ( ) const
inlineconstexprnoexcept

Const access to the third coordinate (z-axis).

Note
N > 2.

◆ z() [2/2]

template<typename T, int N>
T & pbpt::math::Point< T, N >::z ( )
inlineconstexprnoexcept

Accesses the third coordinate (z-axis).

Note
N > 2.

◆ zeros()

template<typename T, int N>
constexpr Point pbpt::math::Point< T, N >::zeros ( )
inlinestaticconstexprnoexcept

Creates a point at the origin (0, 0, ...).

Returns
A new Point instance at the origin.

◆ operator<<

template<typename T, int N>
std::ostream & operator<< ( std::ostream & os,
const Point< T, N > & point )
friend

Stream insertion operator for printing the point's coordinates.

Parameters
osThe output stream.
pointThe point to print.
Returns
A reference to the output stream.

The documentation for this class was generated from the following file:
  • /Users/jinceyang/Desktop/codebase/pbpt/engine/math/point.hpp