/
redgpu
/
r500
Обзор
Документация
Войти
/
redgpu
/
r500
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
drm/math/vec2.hpp
154 строки
3 KB
Zack Buhman
drm: add matrix
30 окт 2025, 07:18
30 окт 2025, 07:18
5716b2b
Код
Авторство
О чём код?
#pragma once #include "vec.hpp" // // vec3 // template <typename T> struct vec<2, T> { union { T val[2]; struct { T x, y; }; struct { T u, v; }; }; inline constexpr vec(); inline constexpr vec(T scalar); inline constexpr vec(T _x, T _y); constexpr inline vec<2, T> operator-() const; inline constexpr T & operator[](int i); inline constexpr T const& operator[](int i) const; inline constexpr vec<2, T>& operator=(vec<2, T> const& v); inline constexpr vec<2, T>& operator+=(vec<2, T> const& v); inline constexpr vec<2, T>& operator-=(vec<2, T> const& v); }; template <typename T> inline constexpr vec<2, T>::vec() : x(0), y(0) {} template <typename T> inline constexpr vec<2, T>::vec(T scalar) : x(scalar), y(scalar) {} template <typename T> inline constexpr vec<2, T>::vec(T _x, T _y) : x(_x), y(_y) {} template <typename T> constexpr inline vec<2, T> vec<2, T>::operator-() const { return vec<2, T>(-x, -y); } template <typename T> inline constexpr T & vec<2, T>::operator[](int i) { return val[i]; } template <typename T> inline constexpr T const& vec<2, T>::operator[](int i) const { return val[i]; } template <typename T> inline constexpr vec<2, T>& vec<2, T>::operator=(vec<2, T> const& v) { this->x = static_cast<T>(v.x); this->y = static_cast<T>(v.y); return *this; } template <typename T> inline constexpr vec<2, T>& vec<2, T>::operator+=(vec<2, T> const& v) { *this = *this + vec<2, T>(v); return *this; } template <typename T> inline constexpr vec<2, T>& vec<2, T>::operator-=(vec<2, T> const& v) { *this = *this - vec<2, T>(v); return *this; } template <typename T> inline constexpr vec<2, T> operator+(vec<2, T> const& v1, vec<2, T> const& v2) { return vec<2, T>(v1.x + v2.x, v1.y + v2.y); } template <typename T> inline constexpr vec<2, T> operator-(vec<2, T> const& v1, vec<2, T> const& v2) { return vec<2, T>(v1.x - v2.x, v1.y - v2.y); } template <typename T> inline constexpr vec<2, T> operator*(vec<2, T> const& v1, vec<2, T> const& v2) { return vec<2, T>(v1.x * v2.x, v1.y * v2.y); } template <typename T> inline constexpr vec<2, T> operator*(vec<2, T> const& v1, T const& scalar) { return v1 * vec<2, T>(scalar); } template <typename T> inline constexpr vec<2, T> operator*(T const& scalar, vec<2, T> const& v1) { return vec<2, T>(scalar) * v1; } template <typename T> inline constexpr vec<2, T> operator/(vec<2, T> const& v1, vec<2, T> const& v2) { return vec<2, T>(v1.x / v2.x, v1.y / v2.y); } template <typename T> inline constexpr vec<2, T> operator/(vec<2, T> const& v1, T const& scalar) { return v1 / vec<2, T>(scalar); } template <typename T> inline constexpr T dot(vec<2, T> const& v1, vec<2, T> const& v2) { vec<2, T> tmp(v1 * v2); return tmp.x + tmp.y; } template <typename T> inline constexpr T cross(vec<2, T> const& v1, vec<2, T> const& v2) { return v1.x * v2.y - v2.x * v1.y; } template <typename T> inline constexpr vec<2, T> functor1(T (&func) (T const& x), vec<2, T> const& v) { return vec<2, T>(func(v.x), func(v.y)); } template <typename T, typename U> inline constexpr vec<2, U> functor1(U (&func) (T const& x), vec<2, T> const& v) { return vec<2, U>(func(v.x), func(v.y)); }