#include <stdio.h>
#include <math.h>
#include <stdlib.h>
const int max_iterations = 128;
const float stop_threshold = 0.01f;
const float grad_step = 0.01f;
const float clip_far = 10.0f;
const float PI = 3.14159265359f;
const float PI2 = 6.28318530718f;
const float DEG_TO_RAD = PI / 180.0f;
typedef struct { float x, y; } vec2;
typedef struct { float x, y, z; } vec3;
typedef struct { float m[9]; } mat3;
const vec3 light_pos = { 20.0f, 50.0f, 20.0f };
float min(float a, float b) { return a < b ? a : b; }
float max(float a, float b) { return a > b ? a : b; }
float clamp(float f, float a, float b) { return max(min(f, b), a); }
vec2 make2(float x, float y) { vec2 r = { x, y }; return r; }
vec2 add2(vec2 a, vec2 b) { vec2 r = { a.x + b.x, a.y + b.y }; return r; }
vec2 sub2(vec2 a, vec2 b) { vec2 r = { a.x - b.x, a.y - b.y }; return r; }
float dot2(vec2 a, vec2 b) { return a.x * b.x + a.y * b.y; }
float length2(vec2 v) { return sqrt(dot2(v, v)); }
vec3 make3(float x, float y, float z) { vec3 r = { x, y, z }; return r; }
vec3 add3(vec3 a, vec3 b)