Update lazyvec / vec api as well as rect are mostly constexpr now

This commit is contained in:
2026-03-22 00:15:14 +01:00
parent 4db5d98cb2
commit b49c0bd3dc
10 changed files with 108 additions and 105 deletions
+23 -23
View File
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// This file is generated by lazyvec 2.0.0 // This file is generated by lazyvec 2.1.0
#include <pd/common.hpp> #include <pd/common.hpp>
@@ -54,117 +54,117 @@ class vec2 {
// Operations // Operations
template <typename T1> template <typename T1>
vec2<T>& operator+=(T1 v) { constexpr vec2<T>& operator+=(T1 v) {
x += (T)v; x += (T)v;
y += (T)v; y += (T)v;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T>& operator+=(const vec2<T1>& v) { constexpr vec2<T>& operator+=(const vec2<T1>& v) {
x += (T)v.x; x += (T)v.x;
y += (T)v.y; y += (T)v.y;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T> operator+(T1 v) const { constexpr vec2<T> operator+(T1 v) const {
return vec2<T>(x + (T)v, y + (T)v); return vec2<T>(x + (T)v, y + (T)v);
} }
template <typename T1> template <typename T1>
vec2<T> operator+(const vec2<T1>& v) const { constexpr vec2<T> operator+(const vec2<T1>& v) const {
return vec2<T>(x + (T)v.x, y + (T)v.y); return vec2<T>(x + (T)v.x, y + (T)v.y);
} }
template <typename T1> template <typename T1>
vec2<T>& operator-=(T1 v) { constexpr vec2<T>& operator-=(T1 v) {
x -= (T)v; x -= (T)v;
y -= (T)v; y -= (T)v;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T>& operator-=(const vec2<T1>& v) { constexpr vec2<T>& operator-=(const vec2<T1>& v) {
x -= (T)v.x; x -= (T)v.x;
y -= (T)v.y; y -= (T)v.y;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T> operator-(T1 v) const { constexpr vec2<T> operator-(T1 v) const {
return vec2<T>(x - (T)v, y - (T)v); return vec2<T>(x - (T)v, y - (T)v);
} }
template <typename T1> template <typename T1>
vec2<T> operator-(const vec2<T1>& v) const { constexpr vec2<T> operator-(const vec2<T1>& v) const {
return vec2<T>(x - (T)v.x, y - (T)v.y); return vec2<T>(x - (T)v.x, y - (T)v.y);
} }
template <typename T1> template <typename T1>
vec2<T>& operator*=(T1 v) { constexpr vec2<T>& operator*=(T1 v) {
x *= (T)v; x *= (T)v;
y *= (T)v; y *= (T)v;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T>& operator*=(const vec2<T1>& v) { constexpr vec2<T>& operator*=(const vec2<T1>& v) {
x *= (T)v.x; x *= (T)v.x;
y *= (T)v.y; y *= (T)v.y;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T> operator*(T1 v) const { constexpr vec2<T> operator*(T1 v) const {
return vec2<T>(x * (T)v, y * (T)v); return vec2<T>(x * (T)v, y * (T)v);
} }
template <typename T1> template <typename T1>
vec2<T> operator*(const vec2<T1>& v) const { constexpr vec2<T> operator*(const vec2<T1>& v) const {
return vec2<T>(x * (T)v.x, y * (T)v.y); return vec2<T>(x * (T)v.x, y * (T)v.y);
} }
template <typename T1> template <typename T1>
vec2<T>& operator/=(T1 v) { constexpr vec2<T>& operator/=(T1 v) {
x /= (T)v; x /= (T)v;
y /= (T)v; y /= (T)v;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T>& operator/=(const vec2<T1>& v) { constexpr vec2<T>& operator/=(const vec2<T1>& v) {
x /= (T)v.x; x /= (T)v.x;
y /= (T)v.y; y /= (T)v.y;
return *this; return *this;
} }
template <typename T1> template <typename T1>
vec2<T> operator/(T1 v) const { constexpr vec2<T> operator/(T1 v) const {
return vec2<T>(x / (T)v, y / (T)v); return vec2<T>(x / (T)v, y / (T)v);
} }
template <typename T1> template <typename T1>
vec2<T> operator/(const vec2<T1>& v) const { constexpr vec2<T> operator/(const vec2<T1>& v) const {
return vec2<T>(x / (T)v.x, y / (T)v.y); return vec2<T>(x / (T)v.x, y / (T)v.y);
} }
// Generic Operations // Generic Operations
vec2 operator-() const { return vec2(-x, -y); } constexpr vec2 operator-() const { return vec2(-x, -y); }
template <typename T1> template <typename T1>
bool operator==(const vec2<T1>& v) const { constexpr bool operator==(const vec2<T1>& v) const {
return x == (T)v.x && y == (T)v.y; return x == (T)v.x && y == (T)v.y;
} }
template <typename T1> template <typename T1>
bool operator!=(const vec2<T1>& v) const { constexpr bool operator!=(const vec2<T1>& v) const {
return !(*this == v); return !(*this == v);
} }
// Functions // Functions
double Len() const { return std::sqrt(SqLen()); } double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y; } constexpr double SqLen() const { return x * x + y * y; }
template <typename T1> template <typename T1>
double Distance(const vec2<T1>& v) const { double Distance(const vec2<T1>& v) const {
@@ -180,12 +180,12 @@ class vec2 {
} }
template <typename T1> template <typename T1>
T Dot(const vec2<T1>& v) const { constexpr T Dot(const vec2<T1>& v) const {
return x * (T)v.x + y * (T)v.y; return x * (T)v.x + y * (T)v.y;
} }
// Swap Functions // Swap Functions
void SwapXY() { constexpr void SwapXY() {
T t = x; T t = x;
x = y; x = y;
y = t; y = t;
+26 -26
View File
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// This file is generated by lazyvec 2.0.0 // This file is generated by lazyvec 2.1.0
#include <pd/common.hpp> #include <pd/common.hpp>
// Extended includes (rename if you use other filenames/paths) // Extended includes (rename if you use other filenames/paths)
@@ -69,7 +69,7 @@ class vec3 {
// Operations // Operations
template <typename T1> template <typename T1>
vec3<T>& operator+=(T1 v) { constexpr vec3<T>& operator+=(T1 v) {
x += (T)v; x += (T)v;
y += (T)v; y += (T)v;
z += (T)v; z += (T)v;
@@ -77,7 +77,7 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T>& operator+=(const vec3<T1>& v) { constexpr vec3<T>& operator+=(const vec3<T1>& v) {
x += (T)v.x; x += (T)v.x;
y += (T)v.y; y += (T)v.y;
z += (T)v.z; z += (T)v.z;
@@ -85,17 +85,17 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T> operator+(T1 v) const { constexpr vec3<T> operator+(T1 v) const {
return vec3<T>(x + (T)v, y + (T)v, z + (T)v); return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
} }
template <typename T1> template <typename T1>
vec3<T> operator+(const vec3<T1>& v) const { constexpr vec3<T> operator+(const vec3<T1>& v) const {
return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z); return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z);
} }
template <typename T1> template <typename T1>
vec3<T>& operator-=(T1 v) { constexpr vec3<T>& operator-=(T1 v) {
x -= (T)v; x -= (T)v;
y -= (T)v; y -= (T)v;
z -= (T)v; z -= (T)v;
@@ -103,7 +103,7 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T>& operator-=(const vec3<T1>& v) { constexpr vec3<T>& operator-=(const vec3<T1>& v) {
x -= (T)v.x; x -= (T)v.x;
y -= (T)v.y; y -= (T)v.y;
z -= (T)v.z; z -= (T)v.z;
@@ -111,17 +111,17 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T> operator-(T1 v) const { constexpr vec3<T> operator-(T1 v) const {
return vec3<T>(x - (T)v, y - (T)v, z - (T)v); return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
} }
template <typename T1> template <typename T1>
vec3<T> operator-(const vec3<T1>& v) const { constexpr vec3<T> operator-(const vec3<T1>& v) const {
return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z); return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z);
} }
template <typename T1> template <typename T1>
vec3<T>& operator*=(T1 v) { constexpr vec3<T>& operator*=(T1 v) {
x *= (T)v; x *= (T)v;
y *= (T)v; y *= (T)v;
z *= (T)v; z *= (T)v;
@@ -129,7 +129,7 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T>& operator*=(const vec3<T1>& v) { constexpr vec3<T>& operator*=(const vec3<T1>& v) {
x *= (T)v.x; x *= (T)v.x;
y *= (T)v.y; y *= (T)v.y;
z *= (T)v.z; z *= (T)v.z;
@@ -137,17 +137,17 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T> operator*(T1 v) const { constexpr vec3<T> operator*(T1 v) const {
return vec3<T>(x * (T)v, y * (T)v, z * (T)v); return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
} }
template <typename T1> template <typename T1>
vec3<T> operator*(const vec3<T1>& v) const { constexpr vec3<T> operator*(const vec3<T1>& v) const {
return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z); return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z);
} }
template <typename T1> template <typename T1>
vec3<T>& operator/=(T1 v) { constexpr vec3<T>& operator/=(T1 v) {
x /= (T)v; x /= (T)v;
y /= (T)v; y /= (T)v;
z /= (T)v; z /= (T)v;
@@ -155,7 +155,7 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T>& operator/=(const vec3<T1>& v) { constexpr vec3<T>& operator/=(const vec3<T1>& v) {
x /= (T)v.x; x /= (T)v.x;
y /= (T)v.y; y /= (T)v.y;
z /= (T)v.z; z /= (T)v.z;
@@ -163,31 +163,31 @@ class vec3 {
} }
template <typename T1> template <typename T1>
vec3<T> operator/(T1 v) const { constexpr vec3<T> operator/(T1 v) const {
return vec3<T>(x / (T)v, y / (T)v, z / (T)v); return vec3<T>(x / (T)v, y / (T)v, z / (T)v);
} }
template <typename T1> template <typename T1>
vec3<T> operator/(const vec3<T1>& v) const { constexpr vec3<T> operator/(const vec3<T1>& v) const {
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z); return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
} }
// Generic Operations // Generic Operations
vec3 operator-() const { return vec3(-x, -y, -z); } constexpr vec3 operator-() const { return vec3(-x, -y, -z); }
template <typename T1> template <typename T1>
bool operator==(const vec3<T1>& v) const { constexpr bool operator==(const vec3<T1>& v) const {
return x == (T)v.x && y == (T)v.y && z == (T)v.z; return x == (T)v.x && y == (T)v.y && z == (T)v.z;
} }
template <typename T1> template <typename T1>
bool operator!=(const vec3<T1>& v) const { constexpr bool operator!=(const vec3<T1>& v) const {
return !(*this == v); return !(*this == v);
} }
// Functions // Functions
double Len() const { return std::sqrt(SqLen()); } double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z; } constexpr double SqLen() const { return x * x + y * y + z * z; }
template <typename T1> template <typename T1>
double Distance(const vec3<T1>& v) const { double Distance(const vec3<T1>& v) const {
@@ -203,27 +203,27 @@ class vec3 {
} }
template <typename T1> template <typename T1>
T Dot(const vec3<T1>& v) const { constexpr T Dot(const vec3<T1>& v) const {
return x * (T)v.x + y * (T)v.y + z * (T)v.z; return x * (T)v.x + y * (T)v.y + z * (T)v.z;
} }
template <typename T1> template <typename T1>
vec3<T> Cross(const vec3<T1>& v) const { constexpr vec3<T> Cross(const vec3<T1>& v) const {
return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
} }
// Swap Functions // Swap Functions
void SwapXY() { constexpr void SwapXY() {
T t = x; T t = x;
x = y; x = y;
y = t; y = t;
} }
void SwapXZ() { constexpr void SwapXZ() {
T t = x; T t = x;
x = z; x = z;
z = t; z = t;
} }
void SwapYZ() { constexpr void SwapYZ() {
T t = y; T t = y;
y = z; y = z;
z = t; z = t;
+28 -28
View File
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// This file is generated by lazyvec 2.0.0 // This file is generated by lazyvec 2.1.0
#include <pd/common.hpp> #include <pd/common.hpp>
// Extended includes (rename if you use other filenames/paths) // Extended includes (rename if you use other filenames/paths)
@@ -84,7 +84,7 @@ class vec4 {
// Operations // Operations
template <typename T1> template <typename T1>
vec4<T>& operator+=(T1 v) { constexpr vec4<T>& operator+=(T1 v) {
x += (T)v; x += (T)v;
y += (T)v; y += (T)v;
z += (T)v; z += (T)v;
@@ -93,7 +93,7 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T>& operator+=(const vec4<T1>& v) { constexpr vec4<T>& operator+=(const vec4<T1>& v) {
x += (T)v.x; x += (T)v.x;
y += (T)v.y; y += (T)v.y;
z += (T)v.z; z += (T)v.z;
@@ -102,17 +102,17 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T> operator+(T1 v) const { constexpr vec4<T> operator+(T1 v) const {
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v); return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
} }
template <typename T1> template <typename T1>
vec4<T> operator+(const vec4<T1>& v) const { constexpr vec4<T> operator+(const vec4<T1>& v) const {
return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w); return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w);
} }
template <typename T1> template <typename T1>
vec4<T>& operator-=(T1 v) { constexpr vec4<T>& operator-=(T1 v) {
x -= (T)v; x -= (T)v;
y -= (T)v; y -= (T)v;
z -= (T)v; z -= (T)v;
@@ -121,7 +121,7 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T>& operator-=(const vec4<T1>& v) { constexpr vec4<T>& operator-=(const vec4<T1>& v) {
x -= (T)v.x; x -= (T)v.x;
y -= (T)v.y; y -= (T)v.y;
z -= (T)v.z; z -= (T)v.z;
@@ -130,17 +130,17 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T> operator-(T1 v) const { constexpr vec4<T> operator-(T1 v) const {
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v); return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
} }
template <typename T1> template <typename T1>
vec4<T> operator-(const vec4<T1>& v) const { constexpr vec4<T> operator-(const vec4<T1>& v) const {
return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w); return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w);
} }
template <typename T1> template <typename T1>
vec4<T>& operator*=(T1 v) { constexpr vec4<T>& operator*=(T1 v) {
x *= (T)v; x *= (T)v;
y *= (T)v; y *= (T)v;
z *= (T)v; z *= (T)v;
@@ -149,7 +149,7 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T>& operator*=(const vec4<T1>& v) { constexpr vec4<T>& operator*=(const vec4<T1>& v) {
x *= (T)v.x; x *= (T)v.x;
y *= (T)v.y; y *= (T)v.y;
z *= (T)v.z; z *= (T)v.z;
@@ -158,17 +158,17 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T> operator*(T1 v) const { constexpr vec4<T> operator*(T1 v) const {
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v); return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
} }
template <typename T1> template <typename T1>
vec4<T> operator*(const vec4<T1>& v) const { constexpr vec4<T> operator*(const vec4<T1>& v) const {
return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w); return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w);
} }
template <typename T1> template <typename T1>
vec4<T>& operator/=(T1 v) { constexpr vec4<T>& operator/=(T1 v) {
x /= (T)v; x /= (T)v;
y /= (T)v; y /= (T)v;
z /= (T)v; z /= (T)v;
@@ -177,7 +177,7 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T>& operator/=(const vec4<T1>& v) { constexpr vec4<T>& operator/=(const vec4<T1>& v) {
x /= (T)v.x; x /= (T)v.x;
y /= (T)v.y; y /= (T)v.y;
z /= (T)v.z; z /= (T)v.z;
@@ -186,31 +186,31 @@ class vec4 {
} }
template <typename T1> template <typename T1>
vec4<T> operator/(T1 v) const { constexpr vec4<T> operator/(T1 v) const {
return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v); return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v);
} }
template <typename T1> template <typename T1>
vec4<T> operator/(const vec4<T1>& v) const { constexpr vec4<T> operator/(const vec4<T1>& v) const {
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w); return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
} }
// Generic Operations // Generic Operations
vec4 operator-() const { return vec4(-x, -y, -z, -w); } constexpr vec4 operator-() const { return vec4(-x, -y, -z, -w); }
template <typename T1> template <typename T1>
bool operator==(const vec4<T1>& v) const { constexpr bool operator==(const vec4<T1>& v) const {
return x == (T)v.x && y == (T)v.y && z == (T)v.z && w == (T)v.w; return x == (T)v.x && y == (T)v.y && z == (T)v.z && w == (T)v.w;
} }
template <typename T1> template <typename T1>
bool operator!=(const vec4<T1>& v) const { constexpr bool operator!=(const vec4<T1>& v) const {
return !(*this == v); return !(*this == v);
} }
// Functions // Functions
double Len() const { return std::sqrt(SqLen()); } double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z + w * w; } constexpr double SqLen() const { return x * x + y * y + z * z + w * w; }
template <typename T1> template <typename T1>
double Distance(const vec4<T1>& v) const { double Distance(const vec4<T1>& v) const {
@@ -226,37 +226,37 @@ class vec4 {
} }
template <typename T1> template <typename T1>
T Dot(const vec4<T1>& v) const { constexpr T Dot(const vec4<T1>& v) const {
return x * (T)v.x + y * (T)v.y + z * (T)v.z + w * (T)v.w; return x * (T)v.x + y * (T)v.y + z * (T)v.z + w * (T)v.w;
} }
// Swap Functions // Swap Functions
void SwapXY() { constexpr void SwapXY() {
T t = x; T t = x;
x = y; x = y;
y = t; y = t;
} }
void SwapXZ() { constexpr void SwapXZ() {
T t = x; T t = x;
x = z; x = z;
z = t; z = t;
} }
void SwapXW() { constexpr void SwapXW() {
T t = x; T t = x;
x = w; x = w;
w = t; w = t;
} }
void SwapYZ() { constexpr void SwapYZ() {
T t = y; T t = y;
y = z; y = z;
z = t; z = t;
} }
void SwapYW() { constexpr void SwapYW() {
T t = y; T t = y;
y = w; y = w;
w = t; w = t;
} }
void SwapZW() { constexpr void SwapZW() {
T t = z; T t = z;
z = w; z = w;
w = t; w = t;
+17 -14
View File
@@ -29,14 +29,14 @@ namespace PD {
namespace Li { namespace Li {
class Rect { class Rect {
public: public:
Rect() : Top(0), Bot(0) {} constexpr Rect() : Top(0), Bot(0) {}
~Rect() = default; ~Rect() = default;
/** /**
* Constructor that initializes the rectangle using top and bottom positions. * Constructor that initializes the rectangle using top and bottom positions.
* @param t Top left and right corner positions. * @param t Top left and right corner positions.
* @param b Bottom left and right corner positions. * @param b Bottom left and right corner positions.
*/ */
Rect(const fvec4& t, const fvec4& b) { constexpr Rect(const fvec4& t, const fvec4& b) {
Top = t; Top = t;
Bot = b; Bot = b;
} }
@@ -48,7 +48,8 @@ class Rect {
* @param bl Bottom left corner position. * @param bl Bottom left corner position.
* @param br Bottom right corner position. * @param br Bottom right corner position.
*/ */
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) { constexpr Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl,
const fvec2& br) {
Top = fvec4(tl, tr); Top = fvec4(tl, tr);
Bot = fvec4(bl, br); Bot = fvec4(bl, br);
} }
@@ -61,7 +62,7 @@ class Rect {
* *
* @param uv Vec4 UV map. * @param uv Vec4 UV map.
*/ */
Rect(const fvec4& uv) { constexpr Rect(const fvec4& uv) {
Top = vec4(uv.x, uv.y, uv.z, uv.y); Top = vec4(uv.x, uv.y, uv.z, uv.y);
Bot = vec4(uv.x, uv.w, uv.z, uv.w); Bot = vec4(uv.x, uv.w, uv.z, uv.w);
} }
@@ -70,29 +71,29 @@ class Rect {
* Get the top-left corner position. * Get the top-left corner position.
* @return Top-left position as vec2. * @return Top-left position as vec2.
*/ */
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); } constexpr fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
/** /**
* Get the top-right corner position. * Get the top-right corner position.
* @return Top-right position as vec2. * @return Top-right position as vec2.
*/ */
fvec2 TopRight() const { return fvec2(Top.z, Top.w); } constexpr fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
/** /**
* Get the bottom-left corner position. * Get the bottom-left corner position.
* @return Bottom-left position as vec2. * @return Bottom-left position as vec2.
*/ */
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); } constexpr fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
/** /**
* Get the bottom-right corner position. * Get the bottom-right corner position.
* @return Bottom-right position as vec2. * @return Bottom-right position as vec2.
*/ */
fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); } constexpr fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); }
/** /**
* Set the top-left corner position. * Set the top-left corner position.
* @param v New top-left position. * @param v New top-left position.
* @return Reference to the updated Rect. * @return Reference to the updated Rect.
*/ */
Rect& TopLeft(const fvec2& v) { constexpr Rect& TopLeft(const fvec2& v) {
Top.x = v.x; Top.x = v.x;
Top.y = v.y; Top.y = v.y;
return *this; return *this;
@@ -103,7 +104,7 @@ class Rect {
* @param v New top-right position. * @param v New top-right position.
* @return Reference to the updated Rect. * @return Reference to the updated Rect.
*/ */
Rect& TopRight(const fvec2& v) { constexpr Rect& TopRight(const fvec2& v) {
Top.z = v.x; Top.z = v.x;
Top.w = v.y; Top.w = v.y;
return *this; return *this;
@@ -114,7 +115,7 @@ class Rect {
* @param v New bottom-left position. * @param v New bottom-left position.
* @return Reference to the updated Rect. * @return Reference to the updated Rect.
*/ */
Rect& BotLeft(const fvec2& v) { constexpr Rect& BotLeft(const fvec2& v) {
Bot.x = v.x; Bot.x = v.x;
Bot.y = v.y; Bot.y = v.y;
return *this; return *this;
@@ -125,15 +126,17 @@ class Rect {
* @param v New bottom-right position. * @param v New bottom-right position.
* @return Reference to the updated Rect. * @return Reference to the updated Rect.
*/ */
Rect& BotRight(const fvec2& v) { constexpr Rect& BotRight(const fvec2& v) {
Bot.z = v.x; Bot.z = v.x;
Bot.w = v.y; Bot.w = v.y;
return *this; return *this;
} }
bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; } constexpr bool operator==(const Rect& r) const {
return Top == r.Top && Bot == r.Bot;
}
void SwapVec2XY() { constexpr void SwapVec2XY() {
Top.SwapXY(); Top.SwapXY();
Top.SwapZW(); Top.SwapZW();
Bot.SwapXY(); Bot.SwapXY();
+1 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
project(lazyvec LANGUAGES CXX VERSION 2.0.0) project(lazyvec LANGUAGES CXX VERSION 2.1.0)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true) set(CMAKE_CXX_STANDARD_REQUIRED true)
+3 -3
View File
@@ -25,7 +25,7 @@ SOFTWARE.
constexpr std::string_view _funcs = R"text( constexpr std::string_view _funcs = R"text(
double Len() const {{ return std::sqrt(SqLen()); }} double Len() const {{ return std::sqrt(SqLen()); }}
double SqLen() const {{ return {1}; }} constexpr double SqLen() const {{ return {1}; }}
template <typename T1> template <typename T1>
double Distance(const vec{0}<T1>& v) const {{ double Distance(const vec{0}<T1>& v) const {{
@@ -41,14 +41,14 @@ constexpr std::string_view _funcs = R"text(
}} }}
template <typename T1> template <typename T1>
T Dot(const vec{0}<T1>&v) const {{ constexpr T Dot(const vec{0}<T1>&v) const {{
return {2}; return {2};
}} }}
)text"; )text";
constexpr std::string_view _cross = R"text( constexpr std::string_view _cross = R"text(
template <typename T1> template <typename T1>
vec3<T> Cross(const vec3<T1>& v) const { constexpr vec3<T> Cross(const vec3<T1>& v) const {
return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
} }
)text"; )text";
+4 -4
View File
@@ -25,24 +25,24 @@ SOFTWARE.
constexpr std::string_view _op_template = R"text( constexpr std::string_view _op_template = R"text(
template <typename T1> template <typename T1>
vec{0}<T>& operator{1}=(T1 v) {{ constexpr vec{0}<T>& operator{1}=(T1 v) {{
{2} {2}
return *this; return *this;
}} }}
template <typename T1> template <typename T1>
vec{0}<T>& operator{1}=(const vec{0}<T1>& v) {{ constexpr vec{0}<T>& operator{1}=(const vec{0}<T1>& v) {{
{3} {3}
return *this; return *this;
}} }}
template <typename T1> template <typename T1>
vec{0}<T> operator{1}(T1 v) const {{ constexpr vec{0}<T> operator{1}(T1 v) const {{
return vec{0}<T>({4}); return vec{0}<T>({4});
}} }}
template <typename T1> template <typename T1>
vec{0}<T> operator{1}(const vec{0}<T1>& v) const {{ constexpr vec{0}<T> operator{1}(const vec{0}<T1>& v) const {{
return vec{0}<T>({5}); return vec{0}<T>({5});
}} }}
)text"; )text";
+3 -3
View File
@@ -30,11 +30,11 @@ SOFTWARE.
*/ */
constexpr std::string_view _generic_ops = R"text( constexpr std::string_view _generic_ops = R"text(
vec{0} operator-() const {{ return vec{0}({1}); }} constexpr vec{0} operator-() const {{ return vec{0}({1}); }}
template <typename T1> template <typename T1>
bool operator==(const vec{0}<T1>& v) const {{ return {2}; }} constexpr bool operator==(const vec{0}<T1>& v) const {{ return {2}; }}
template <typename T1> template <typename T1>
bool operator!=(const vec{0}<T1>& v) const {{ return !(*this == v); }} constexpr bool operator!=(const vec{0}<T1>& v) const {{ return !(*this == v); }}
)text"; )text";
namespace LVec { namespace LVec {
+1 -1
View File
@@ -36,7 +36,7 @@ std::string MakeSwap(int n) {
if (a == b || done.count(b + a)) { if (a == b || done.count(b + a)) {
continue; continue;
} }
s << " void Swap" << (char)toupper(a[0]) << (char)toupper(b[0]) s << " constexpr void Swap" << (char)toupper(a[0]) << (char)toupper(b[0])
<< "() {\n"; << "() {\n";
s << " T t = " << a << ";\n " << a << " = " << b << ";\n"; s << " T t = " << a << ";\n " << a << " = " << b << ";\n";
s << " " << b << " = t;\n }\n"; s << " " << b << " = t;\n }\n";
+2 -2
View File
@@ -48,9 +48,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// This file is generated by lazyvec 2.0.0 // This file is generated by lazyvec 2.1.0
#include <pd/core/common.hpp> #include <pd/common.hpp>
{7} {7}
namespace PD {{ namespace PD {{