Loading...
Searching...
No Matches
yoda Namespace Reference

The Yoda namespace — core utilities for the doxyYoda demo. More...

Namespaces

namespace  palette
 Color palette constants from the Solarized scheme.
 

Classes

class  ScopedTimer
 A simple RAII-based timer for benchmarking. More...
 
class  Vec2
 A 2D vector with common geometric operations. More...
 

Typedefs

using Vec2d = Vec2<double>
 Convenience alias for a double-precision 2D vector.
 
using Vec2i = Vec2<int>
 Convenience alias for an integer 2D vector.
 

Enumerations

enum class  Interpolation { Linear , Cosine , Cubic , CatmullRom }
 Interpolation methods available for smoothing operations. More...
 

Functions

template<typename T>
std::optional< T > find_if (const std::vector< T > &values, std::function< bool(const T &)> pred)
 Find the first element satisfying a predicate.
 
double lerp (double a, double b, double t)
 Linearly interpolate between two values.
 
template<typename T>
std::vector< T > map (const std::vector< T > &values, std::function< T(T)> fn)
 Apply a function element-wise to a vector of values.
 

Detailed Description

The Yoda namespace — core utilities for the doxyYoda demo.

This namespace contains example classes, functions, and types that exercise every major Doxygen documentation construct.

See also
geometry for shape hierarchy examples.
containers for template container examples.
algorithms for grouped free functions.

Typedef Documentation

◆ Vec2d

using yoda::Vec2d = Vec2<double>

Convenience alias for a double-precision 2D vector.

Definition at line 151 of file yoda.hpp.

◆ Vec2i

using yoda::Vec2i = Vec2<int>

Convenience alias for an integer 2D vector.

Definition at line 154 of file yoda.hpp.

Enumeration Type Documentation

◆ Interpolation

enum class yoda::Interpolation
strong

Interpolation methods available for smoothing operations.

Demonstrates enum documentation with per-enumerator descriptions.

Enumerator
Linear 

Simple linear interpolation: \( f(t) = a + t(b - a) \).

Cosine 

Cosine-smoothed interpolation.

Cubic 

Cubic Hermite interpolation.

CatmullRom 

Catmull-Rom spline interpolation.

Definition at line 161 of file yoda.hpp.

161 {
162 Linear,
163 Cosine,
164 Cubic,
166};
@ Linear
Simple linear interpolation: .
Definition yoda.hpp:162
@ Cosine
Cosine-smoothed interpolation.
Definition yoda.hpp:163
@ Cubic
Cubic Hermite interpolation.
Definition yoda.hpp:164
@ CatmullRom
Catmull-Rom spline interpolation.
Definition yoda.hpp:165

Function Documentation

◆ find_if()

template<typename T>
std::optional< T > yoda::find_if ( const std::vector< T > & values,
std::function< bool(const T &)> pred )

Find the first element satisfying a predicate.

Template Parameters
TElement type.
Parameters
valuesThe input container.
predA unary predicate.
Returns
The first matching element, or std::nullopt.
Bug
Does not short-circuit on the first match if compiled without optimizations on some compilers.

Definition at line 228 of file yoda.hpp.

229 {
230 for (const auto& v : values) {
231 if (pred(v)) return v;
232 }
233 return std::nullopt;
234}

◆ lerp()

double yoda::lerp ( double a,
double b,
double t )
inline

Linearly interpolate between two values.

Computes:

\[ \text{lerp}(a, b, t) = (1 - t) \cdot a + t \cdot b \]

Parameters
aStart value.
bEnd value.
tInterpolation factor in \([0, 1]\).
Returns
The interpolated value.
Invariant
The result lies in \([a, b]\) when \(t \in [0, 1]\).
Todo
Add clamped variant that enforces \(t \in [0, 1]\).

Definition at line 185 of file yoda.hpp.

185 {
186 return a + t * (b - a);
187}

◆ map()

template<typename T>
std::vector< T > yoda::map ( const std::vector< T > & values,
std::function< T(T)> fn )

Apply a function element-wise to a vector of values.

Template Parameters
TElement type.
Parameters
valuesInput values.
fnThe transformation function.
Returns
A new vector with fn applied to each element.

Example usage:

auto squared = map({1.0, 2.0, 3.0}, [](double x) { return x * x; });
// squared == {1.0, 4.0, 9.0}
std::vector< T > map(const std::vector< T > &values, std::function< T(T)> fn)
Apply a function element-wise to a vector of values.
Definition yoda.hpp:206
Deprecated
Use std::ranges::transform with C++20 instead.

Definition at line 206 of file yoda.hpp.

207 {
208 std::vector<T> result;
209 result.reserve(values.size());
210 for (const auto& v : values) {
211 result.push_back(fn(v));
212 }
213 return result;
214}