imp forth.f \ fold: store a vector on stack to a memory address : vec3:fld ( z y x adr -- adr ) here >r dup >r here! , , , r> r> here! ; \ unfold: put a memory stored vector on the stack : vec3:unf ( adr -- z y x ) in swap in! \ old_in 2 in[] 1 in[] in @ \ old_in z y x rot4 in! ; \ dot product of two stack stored vectors : vec3:dot ( z1 y1 x1 z2 y2 x2 -- f ) swap rot 2swap *f 2swap *f 2swap *f +f +f ; \ calculate the euclidian absolutum of a stack stored vector : vec3:abs ( z y x -- f ) 3 mdup vec3:dot sqrtf ; \ scale a stack stored vector by a scalar : vec3:mul ( z y x s -- z y x ) dup rot over *f 2swap *f 2swap *f swap rot ; \ normize a stack stored vector : vec3:nrm ( z y x -- z y x ) 3 mdup vec3:abs 1.0 swap /f vec3:mul ; \ add two stack stored vectors : vec3:add ( z1 y1 x1 z2 y2 x2 -- z y x ) swap rot 2swap +f 2swap +f 2swap +f swap rot ; \ negate a stack stored vector : vec3:neg ( z y x -- z y x ) negf rot negf rot negf rot ; \ subtract to stack stored vectors : vec3:sub ( z1 y1 x1 z2 y2 x2 -- z y x ) vec3:neg vec3:add ; \ nonuniform scale \ scale the components of a stack stored vector with the ones of another : vec3:csc swap rot 2swap *f 2swap *f 2swap *f swap rot ; \ cross product of two stack stored vectors : vec3:xpd ( z1 y1 x1 z2 y2 x2 -- z y x ) rot 2swap 6 mdup *f 2swap *f -f 2swap *f >r dig *f >r >r rot *f r> swap 2swap *f r> -f swap r> -f ;