Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
dvec3.h File Reference

Double-precision 3D vector helpers for physics simulation. More...

#include <math.h>
Include dependency graph for dvec3.h:

Go to the source code of this file.

Typedefs

typedef double dvec3[3]
 

Functions

static void dvec3_zero (dvec3 dest)
 
static void dvec3_copy (const dvec3 src, dvec3 dest)
 
static void dvec3_set (dvec3 dest, double x_val, double y_val, double z_val)
 
static void dvec3_add (const dvec3 a_vec, const dvec3 b_vec, dvec3 dest)
 
static void dvec3_addto (dvec3 dest, const dvec3 b_vec)
 
static void dvec3_sub (const dvec3 a_vec, const dvec3 b_vec, dvec3 dest)
 
static void dvec3_subfrom (dvec3 dest, const dvec3 b_vec)
 
static void dvec3_scale (const dvec3 v_vec, double scalar, dvec3 dest)
 
static void dvec3_muladds (dvec3 dest, const dvec3 v_vec, double scalar)
 
static double dvec3_dot (const dvec3 a_vec, const dvec3 b_vec)
 
static double dvec3_norm2 (const dvec3 v_vec)
 
static double dvec3_norm (const dvec3 v_vec)
 
static void dvec3_normalize (dvec3 v_vec)
 

Detailed Description

Double-precision 3D vector helpers for physics simulation.

cglm (v0.9.x) only provides float-precision vec3 operations — there is no dvec3 type and no SIMD acceleration for vec3 (SSE/NEON are only used for vec4 and mat4, where 4-wide lanes map naturally to 128-bit registers).

These inline helpers mirror the cglm vec3 API (glm_vec3_*) but operate on plain double[3] arrays, giving the n-body simulation the numerical precision it needs without sacrificing readability.

Performance note: on 14 bodies the overhead of double vs float is negligible. Should the body count grow to hundreds, consider migrating to AVX double SIMD (2-wide __m128d or 4-wide __m256d).

See also
docs/nbody_precision_fix.md for the full rationale.

Typedef Documentation

◆ dvec3

typedef double dvec3[3]

A double-precision 3D vector stored as a plain array.

Function Documentation

◆ dvec3_add()

static void dvec3_add ( const dvec3  a_vec,
const dvec3  b_vec,
dvec3  dest 
)
inlinestatic

dest = a + b

◆ dvec3_addto()

static void dvec3_addto ( dvec3  dest,
const dvec3  b_vec 
)
inlinestatic

dest += b (in-place accumulate).

◆ dvec3_copy()

static void dvec3_copy ( const dvec3  src,
dvec3  dest 
)
inlinestatic

Copy src into dest.

◆ dvec3_dot()

static double dvec3_dot ( const dvec3  a_vec,
const dvec3  b_vec 
)
inlinestatic

Dot product: a · b

◆ dvec3_muladds()

static void dvec3_muladds ( dvec3  dest,
const dvec3  v_vec,
double  scalar 
)
inlinestatic

dest += v * s (multiply-add, used in Verlet integration).

◆ dvec3_norm()

static double dvec3_norm ( const dvec3  v_vec)
inlinestatic

Length: |v|

Here is the call graph for this function:

◆ dvec3_norm2()

static double dvec3_norm2 ( const dvec3  v_vec)
inlinestatic

Squared length: |v|²

Here is the call graph for this function:

◆ dvec3_normalize()

static void dvec3_normalize ( dvec3  v_vec)
inlinestatic

Normalize v in-place. No-op if length is zero.

Here is the call graph for this function:

◆ dvec3_scale()

static void dvec3_scale ( const dvec3  v_vec,
double  scalar,
dvec3  dest 
)
inlinestatic

dest = v * s (uniform scale).

◆ dvec3_set()

static void dvec3_set ( dvec3  dest,
double  x_val,
double  y_val,
double  z_val 
)
inlinestatic

Set dest from three scalars.

◆ dvec3_sub()

static void dvec3_sub ( const dvec3  a_vec,
const dvec3  b_vec,
dvec3  dest 
)
inlinestatic

dest = a - b

◆ dvec3_subfrom()

static void dvec3_subfrom ( dvec3  dest,
const dvec3  b_vec 
)
inlinestatic

dest -= b (in-place subtract).

◆ dvec3_zero()

static void dvec3_zero ( dvec3  dest)
inlinestatic

Set all components to zero: dest = {0, 0, 0}.