Files
CgeMath/Vec2i.c
Mikhail Romanko b6481a26bc
All checks were successful
CI / build-and-analyze (push) Successful in 41s
Add more functions, add example, fix ray collision detection
2026-07-03 23:28:17 +03:00

53 lines
1.4 KiB
C

#include "CgeMath.h"
void CgeVec2iAdd(const int a[2], const int b[2], int out[2]) {
out[0] = a[0] + b[0];
out[1] = a[1] + b[1];
}
void CgeVec2iSub(const int a[2], const int b[2], int out[2]) {
out[0] = a[0] - b[0];
out[1] = a[1] - b[1];
}
void CgeVec2iMul(const int a[2], const int b[2], int out[2]) {
out[0] = a[0] * b[0];
out[1] = a[1] * b[1];
}
void CgeVec2iScale(const int a[2], int b, int out[2]) {
out[0] = a[0] * b;
out[1] = a[1] * b;
}
void CgeVec2iMulAdd(const int a[2], const int b[2], const int c[2],
int out[2]) {
out[0] = a[0] * b[0] + c[0];
out[1] = a[1] * b[1] + c[1];
}
void CgeVec2iNegate(const int in[2], int out[2]) {
out[0] = -in[0];
out[1] = -in[1];
}
void CgeVec2iMin(const int a[2], const int b[2], int out[2]) {
if (a[0] < b[0]) out[0] = a[0]; else out[0] = b[0];
if (a[1] < b[1]) out[1] = a[1]; else out[1] = b[1];
}
void CgeVec2iMax(const int a[2], const int b[2], int out[2]) {
if (a[0] > b[0]) out[0] = a[0]; else out[0] = b[0];
if (a[1] > b[1]) out[1] = a[1]; else out[1] = b[1];
}
void CgeVec2iClamp(const int in[2], int minVal, int maxVal, int out[2]) {
out[0] = in[0] < minVal ? minVal : (in[0] > maxVal ? maxVal : in[0]);
out[1] = in[1] < minVal ? minVal : (in[1] > maxVal ? maxVal : in[1]);
}
void CgeVec2iAbs(const int in[2], int out[2]) {
out[0] = in[0] < 0 ? -in[0] : in[0];
out[1] = in[1] < 0 ? -in[1] : in[1];
}