math + constants

This commit is contained in:
Tenari
2026-07-07 07:59:17 -05:00
parent 13158f8362
commit 8ba557ec63
2 changed files with 27 additions and 0 deletions
+22
View File
@@ -648,9 +648,30 @@ global const u8 MAX_u8 = 0xff;
#ifndef MICROSECONDS_PER_SECOND
# define MICROSECONDS_PER_SECOND ONE_MILLION
#endif
#ifndef SECONDS_PER_MICROSECOND
# define SECONDS_PER_MICROSECOND (1.0/MICROSECONDS_PER_SECOND)
#endif
#ifndef NANOSECONDS_PER_MICROSECOND
# define NANOSECONDS_PER_MICROSECOND ONE_THOUSAND
#endif
#ifndef DAYS_PER_HOUR
# define DAYS_PER_HOUR (1.0/24.0)
#endif
#ifndef HOURS_PER_DAY
# define HOURS_PER_DAY (24.0)
#endif
#ifndef HOURS_PER_MINUTE
# define HOURS_PER_MINUTE (1.0/60.0)
#endif
#ifndef MINUTES_PER_HOUR
# define MINUTES_PER_HOUR (60.0)
#endif
#ifndef MINUTES_PER_SECOND
# define MINUTES_PER_SECOND (1.0/60.0)
#endif
#ifndef SECONDS_PER_MINUTE
# define SECONDS_PER_MINUTE (60.0)
#endif
///// CUSTOM ENTRY POINT
@@ -671,6 +692,7 @@ fn void u32ReverseArray(u32 arr[], u32 size);
fn bool vec2Eq(Vec2 a, Vec2 b);
fn Vec2f32 vec2Add(Vec2 a, Vec2 b);
fn Vec2f32 vec2Subtract(Vec2 a, Vec2 b);
fn f32 vec2Distance(Vec2 a, Vec2 b);
fn Vec2f32 vec2FromHexCube(Vec2 map_center, XYZ cube, f32 size, f32 border_thickness);
fn i32 i32Middle(i32 x, i32 y);
fn u32 u32Middle(u32 x, u32 y);
+5
View File
@@ -1,4 +1,5 @@
#include "all.h"
#include <math.h>
fn bool xyzEq(XYZ a, XYZ b) {
return a.x == b.x &&
@@ -90,6 +91,10 @@ fn Vec2f32 vec2Subtract(Vec2 a, Vec2 b) {
return result;
}
fn f32 vec2Distance(Vec2 a, Vec2 b) {
return sqrtf((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
fn Vec2f32 vec2FromHexCube(Vec2 map_center, XYZ cube, f32 size, f32 border_thickness) {
f32 hex_height = SQRT_3 * size;
f32 hex_width = 2.0 * size;