CGVIS Utils
Loading...
Searching...
No Matches
Vec2.h File Reference

2D vector template with arithmetic, length utilities, and helpers. More...

#include <ostream>
#include <string>
#include <array>
#include <sstream>
#include <cmath>
#include "Rand.h"
Include dependency graph for Vec2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  Vec2t< T >

Typedefs

typedef Vec2t< float > Vec2
 Float vector (x,y).
typedef Vec2t< int32_t > Vec2i
 32-bit signed integer vector (x,y).
typedef Vec2t< uint32_t > Vec2ui
 32-bit unsigned integer vector (x,y).

Functions

template<typename T>
std::ostream & operator<< (std::ostream &os, const Vec2t< T > &v)
 Stream insertion for string representation of a vector.
template<typename T>
Vec2t< T > operator* (float scalar, const Vec2t< T > &vec)
 Scalar multiplication with scalar on the left.

Detailed Description

2D vector template with arithmetic, length utilities, and helpers.

This header defines a simple 2D vector type template, Vec2t<T>, that stores two components and exposes multiple alias views (x/y and r/g). It provides basic arithmetic operators, scalar operations, length helpers, and a few convenience utilities (random generation, normalization, clamping) suitable for lightweight math and graphics code.

Note
The implementation uses a union with multiple member layouts (an std::array and two structs for aliases). This is intentionally done for ergonomic access (e.g., v.x vs. v.e[0]).

Typedef Documentation

◆ Vec2

typedef Vec2t<float> Vec2

Float vector (x,y).

◆ Vec2i

typedef Vec2t<int32_t> Vec2i

32-bit signed integer vector (x,y).

◆ Vec2ui

typedef Vec2t<uint32_t> Vec2ui

32-bit unsigned integer vector (x,y).

Function Documentation

◆ operator*()

template<typename T>
Vec2t< T > operator* ( float scalar,
const Vec2t< T > & vec )

Scalar multiplication with scalar on the left.

Template Parameters
TComponent type of vector.
Parameters
scalarScalar factor.
vecVector to multiply.
Returns
Result of vec * scalar.

◆ operator<<()

template<typename T>
std::ostream & operator<< ( std::ostream & os,
const Vec2t< T > & v )

Stream insertion for string representation of a vector.

Template Parameters
TComponent type.
Parameters
osOutput stream.
vVector to print.
Returns
Reference to the output stream.
Here is the call graph for this function: