mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 11:25:45 +01:00
add integer vector types
This commit is contained in:
51
src/util/vec/int2.h
Normal file
51
src/util/vec/int2.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include "../atrb.h"
|
||||
|
||||
// stores a 2D point using a floating-point number
|
||||
struct int2 {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
typedef struct int2 int2;
|
||||
|
||||
// adds one int2 to another
|
||||
atrb_const static inline int2 int2_add(int2 v1, int2 v2) {
|
||||
return (int2){v1.x + v2.x, v1.y + v2.y};
|
||||
}
|
||||
|
||||
// subtracts one int2 from another
|
||||
atrb_const static inline int2 int2_sub(int2 v1, int2 v2) {
|
||||
return (int2){v1.x - v2.x, v1.y - v2.y};
|
||||
}
|
||||
|
||||
// multiplies one int2 by another
|
||||
atrb_const static inline int2 int2_mul(int2 v1, int2 v2) {
|
||||
return (int2){v1.x * v2.x, v1.y * v2.y};
|
||||
}
|
||||
|
||||
// divides one int2 by another
|
||||
atrb_const static inline int2 int2_div(int2 v1, int2 v2) {
|
||||
return (int2){v1.x / v2.x, v1.y / v2.y};
|
||||
}
|
||||
|
||||
// preforms a scalar multiplication upon the int2 (multiplies the int2 by some value)
|
||||
atrb_const static inline int2 int2_mul_s(int2 v, float n) {
|
||||
return (int2){v.x * n, v.y * n};
|
||||
}
|
||||
|
||||
// preforms a scalar division upon the int2 (divides the int2 by some value)
|
||||
atrb_const static inline int2 int2_div_s(int2 v, float n) {
|
||||
return (int2){v.x / n, v.y / n};
|
||||
}
|
||||
|
||||
atrb_const static inline int2 int2_neg(int2 v) {
|
||||
return (int2){-v.x, -v.y};
|
||||
}
|
||||
|
||||
// gets the dot product of two int2s
|
||||
atrb_const static inline int int2_dot(int2 v1, int2 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
53
src/util/vec/int4.h
Normal file
53
src/util/vec/int4.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include "../atrb.h"
|
||||
|
||||
// stores a 2D point using a floating-point number
|
||||
struct int4 {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int w;
|
||||
};
|
||||
typedef struct int4 int4;
|
||||
|
||||
// adds one int4 to another
|
||||
atrb_const static inline int4 int4_add(int4 v1, int4 v2) {
|
||||
return (int4){v1.x + v2.x, v1.y + v2.y, v1.z - v2.z, v1.w - v2.w};
|
||||
}
|
||||
|
||||
// subtracts one int4 from another
|
||||
atrb_const static inline int4 int4_sub(int4 v1, int4 v2) {
|
||||
return (int4){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w};
|
||||
}
|
||||
|
||||
// multiplies one int4 by another
|
||||
atrb_const static inline int4 int4_mul(int4 v1, int4 v2) {
|
||||
return (int4){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w};
|
||||
}
|
||||
|
||||
// divides one int4 by another
|
||||
atrb_const static inline int4 int4_div(int4 v1, int4 v2) {
|
||||
return (int4){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w};
|
||||
}
|
||||
|
||||
// preforms a scalar multiplication upon the int4 (multiplies the int4 by some value)
|
||||
atrb_const static inline int4 int4_mul_s(int4 v, float n) {
|
||||
return (int4){v.x * n, v.y * n, v.z * n, v.w * n};
|
||||
}
|
||||
|
||||
// preforms a scalar division upon the int4 (divides the int4 by some value)
|
||||
atrb_const static inline int4 int4_div_s(int4 v, float n) {
|
||||
return (int4){v.x / n, v.y / n, v.z / n, v.w / n};
|
||||
}
|
||||
|
||||
atrb_const static inline int4 int4_neg(int4 v) {
|
||||
return (int4){-v.x, -v.y, -v.z, v.w};
|
||||
}
|
||||
|
||||
// gets the dot product of two int2s
|
||||
atrb_const static inline int int4_dot(int4 v1, int4 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||
}
|
||||
Reference in New Issue
Block a user