void vsphereSort( const mat* m, u32* inds, const triple* vs, const f32* radiuss, u32 sz ){ static u32 vlshmap = 0; static u32 vlshmasz = 0; u32 i; for( i = 0; i < sz; ++i ) inds[ i ] = i; if( vlshma == NULL ){ vlshmasz = sz; vlshmap = vmalloc( sz * sizeof( f32 ) ); vlshma = vmem( vlshmap ); }else if( vlshmasz < sz ){ vgrow( vlshmap, ( sz - vlshmasz ) ); vlshma = vmem( vlshmap ); } for( i = 0; i < sz; ++i ){ f32 d2, n, r2, d; triple v = vs[ i ]; vmult( &v, m ); r2 = radiuss[ i ] * radiuss[ i ]; d2 = vdot( &v, &v ); d = vsqrt( d2 ); if( d2 > r2 ) n = ( r2 * 0.5f ) / vsqrt( d2 - r2 ); else n = ( r2 * 0.5f ) / vsqrt( r2 - d2 ); vlshma[ i ] = d - n; } vqsort( (u8*)inds, sz, sizeof( u32 ), vsphereSortHelper ); }
f32 vlength( const triple* x ){ return (f32)vsqrt( x->x * x->x + x->y * x->y + x->z * x->z ); }
void shr_vmath_fwrap_vsqrt_(double *X, double *Y, int *n) { vsqrt(X, Y, *n, 1, 1); }