API Reference¶
-
namespace tuple¶
Namespace containing 3D tuple math types and operations.
Functions
-
template<typename ...Ts>
constexpr tuple<4> point(Ts... args)¶ Creates a tuple representing a 3D point.
- Parameters:
args – X, Y, Z coordinates.
- Returns:
A tuple with w = 1.0.
-
template<typename ...Ts>
constexpr tuple<4> vector(Ts... args)¶ Creates a tuple representing a 3D vector.
- Parameters:
args – X, Y, Z coordinates.
- Returns:
A tuple with w = 0.0.
-
template<int N>
bool operator==(const tuple<N> &ls_tuple, const tuple<N> &rs_tuple)¶ Compares two tuples with epsilon 1e-5.
-
template<int N>
tuple<N> operator+(const tuple<N> &ls_tuple, const tuple<N> &rs_tuple)¶ Adds two tuples.
-
template<int N>
tuple<N> operator-(const tuple<N> &ls_tuple, const tuple<N> &rs_tuple)¶ Subtracts two tuples.
-
template<int N>
tuple<N> operator*(const tuple<N> &ls_tuple, const float num)¶ Multiply a tuple with a scalar.
-
template<int N>
tuple<N> operator/(const tuple<N> &ls_tuple, const float num)¶ Divide a tuple with a scalar.
-
template<int N>
tuple<N> normalize(const tuple<N> &in_tuple)¶ Returns the normalized version of the tuple.
-
template<int N>
class tuple¶ A 4D tuple representing either a point or vector in 3D space.
The 4th element distinguishes point (w=1.0) from vector (w=0.0).
Use
point(x, y, z)
andvector(x, y, z)
to create tuples.Public Functions
-
inline tuple(const std::initializer_list<float> &input_data)¶
Constructs a tuple from an initializer list.
-
inline constexpr bool is_point()¶
-
inline constexpr bool is_vector()¶
-
inline constexpr float x()¶
-
inline constexpr float y()¶
-
inline constexpr float z()¶
-
inline constexpr float w()¶
-
inline float &operator[](const int i)¶
returns a reference to coordinate
-
inline float operator[](const int i) const¶
returns the copy of the coordinate
-
inline void print() const¶
-
inline tuple(const std::initializer_list<float> &input_data)¶
-
template<typename ...Ts>
-
namespace color¶
Namespace containing color-related types and operations.
Functions
-
class color¶
RGB color with three float channels.
Stores color as an array of three floats representing red, green, and blue components.
Public Functions
-
inline color(const std::array<float, 3> &input_data)¶
Construct from array of 3 floats.
-
inline color(const std::initializer_list<float> &input_data)¶
Construct from initializer list of floats.
-
inline float &operator[](const int i)¶
-
inline float operator[](const int i) const¶
-
inline void print() const¶
Public Members
-
std::array<float, 3> channels = {}¶
-
inline color(const std::array<float, 3> &input_data)¶
-
class color¶
-
namespace canvas¶
Namespace for 2D drawing canvas functionality.
-
template<std::size_t w, std::size_t h>
class canvas¶ Fixed-size 2D canvas storing pixel colors and exporting to PPM format.
Template parameters:
w
: width of the canvas in pixelsh
: height of the canvas in pixels
Internally stores pixel data as an array of
color::color
. Provides methods to write pixels, read pixels, and export the canvas as a PPM image string.Public Functions
-
inline void write_pixel(const std::size_t x, const std::size_t y, color::color input_color)¶
Sets the pixel color at (x, y).
Public Members
-
template<std::size_t w, std::size_t h>
-
namespace matrix¶
Namespace containing matrix types and operations.
Functions
-
template<int row_c, int col_c>
bool operator==(const matrix<row_c, col_c> &lhs_matrix, const matrix<row_c, col_c> &rhs_matrix)¶
-
template<int row_c, int col_c>
matrix<row_c, col_c> operator*(const matrix<row_c, col_c> &ls_matrix, const float num)¶
-
template<int row_c, int col_c>
matrix<row_c, col_c> operator/(const matrix<row_c, col_c> &ls_matrix, const float num)¶
-
template<int row_c, int col_c>
class matrix¶ A generic matrix class supporting various dimensions.
- Template Parameters:
row_c – The number of columns in the matrix.
col_c – The number of rows in the matrix. Each tuple are columns not rowss
Public Functions
-
inline matrix(const std::array<tuple::tuple<row_c>, col_c> &input_data)¶
Constructs a matrix from an array of tuples.
-
inline matrix(const std::initializer_list<tuple::tuple<row_c>> &input_data)¶
Constructs a matrix from an initializer list of tuples.
-
inline float &operator()(const int row, const int col)¶
-
inline float operator()(const int row, const int col) const¶
-
inline int size()¶
-
inline void print() const¶
Prints a matrix + new line.
-
inline matrix<row_c - 1, col_c - 1> submatrix(const int ignore_row, const int ignore_col)¶
Returns the submatrix of a matrix.
-
inline float determinant()¶
Returns the determinant of a matrix with cofactor expansion.
-
inline float minor(const int ignore_row, const int ignore_col)¶
Returns the minor of a matrix.
-
inline float cofactor(const int ignored_row, const int ignored_col)¶
Returns the cofactor of a matrix.
-
inline bool invertible()¶
-
template<int row_c, int col_c>
-
namespace matrix_transformations¶
Functions
-
namespace ray_sphere_intersections¶
Functions
-
bool operator==(const intersection &lhs, const intersection &rhs)¶
-
template<typename ...Ts>
std::vector<intersection> intersections(const Ts&... args)¶ Combines multiple intersections and returns them sorted by time.
-
template<typename ...Ts>
std::optional<intersection> hit(Ts&... args)¶ Finds the hit (closest non-negative intersection) from a list of intersections passed as arguments.
- Template Parameters:
Ts – Variadic template parameter pack of intersections
- Parameters:
args – Intersection objects to evaluate
- Returns:
Optional intersection if a valid hit exists, nullopt otherwise
-
std::optional<intersection> hit(std::vector<intersection> &intersections)¶
Finds the hit (closest non-negative intersection) from a vector of intersections.
- Parameters:
intersections – Vector of intersections to evaluate
- Returns:
Optional intersection if a valid hit exists, nullopt otherwise
-
class intersection¶
Public Functions
-
class ray¶
Represents a ray in 3D space with an origin and direction.
-
class sphere¶
Public Functions
-
inline sphere(int id)¶
-
inline void set_transform(const matrix::matrix<4, 4> &t)¶
Sets the transformation matrix for the sphere.
-
inline std::vector<intersection> intersect(const ray &ray)¶
Computes intersections of a ray with this sphere. Transforms the ray into object space and solves the quadratic equation.ns.
-
inline sphere(int id)¶
-
bool operator==(const intersection &lhs, const intersection &rhs)¶