Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#define streq(a, b) (!strcmp((a), (b)))
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#define tag(x) ((ptrdiff_t)&Tag##x)
#define is(x, T) ((x)->tag == tag(T))
#define as(x, T) ((struct T *)variant_cast((void *)(x), tag(T)))
static inline void*
struct quat
quat_from_two_vectors(vec3 u, vec3 v)
{
float m = sqrt(2.f + 2.f * dot(u, v));
vec3 w = (1.f / m) * cross(u, v);
return quat(0.5f * m, w.x, w.y, w.z);
}
static void
Quat_FromEulerXYZ(float *euler_quat, float x, float y, float z)
{
float sx = (float)sin((double)(x * 0.5f));
float sy = (float)sin((double)(y * 0.5f));
float sz = (float)sin((double)(z * 0.5f));
float cx = (float)cos((double)(x * 0.5f));
float cy = (float)cos((double)(y * 0.5f));
float cz = (float)cos((double)(z * 0.5f));
@vurtun
vurtun / compr.c
Last active April 17, 2018 23:28
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#define LIB_DEBUG 2
#if defined(LIB_DEBUG) && (LIB_DEBUG >= 2)
#include <stdio.h>
#define DEBUG_LOG(l, ...) \
if (l <= LIB_DEBUG) { \
fprintf(stderr, "%s(L:%d):, __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, " \n"); \
}
#else
@vurtun
vurtun / arg.h
Last active July 24, 2018 08:21
#if 0
static void
usage(const char *app)
{
panic("\n"
"usage: %s [options]\n"
"\n"
" options:\n"
"\n"
struct path_iter {
const char *begin;
const char *end;
/* internal */
const char *next;
const char *eof;
};
static void
path_begin(struct path_iter *it, const char *str, const char *end)
{
@vurtun
vurtun / paq.c
Last active December 22, 2018 17:27
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
/* ---------------------------------------------------------------------------
* ARG