struct vec { union { struct { float x, y, z; }; float v[3]; }; vec() {}; vec(float a, float b, float c) : x(a), y(b), z(c) {}; vec(float *v) : x(v[0]), y(v[1]), z(v[2]) {}; float &operator[](int i) { return v[i]; }; float operator[](int i) const { return v[i]; }; bool operator==(const vec &o) const { return x == o.x && y == o.y && z == o.z; } bool operator!=(const vec &o) const { return x != o.x || y != o.y || z != o.z; } vec &mul(float f) { x *= f; y *= f; z *= f; return *this; }; vec &div(float f) { x /= f; y /= f; z /= f; return *this; }; vec &add(float f) { x += f; y += f; z += f; return *this; }; vec &sub(float f) { x -= f; y -= f; z -= f; return *this; }; vec &add(const vec &o) { x += o.x; y += o.y; z += o.z; return *this; }; vec &sub(const vec &o) { x -= o.x; y -= o.y; z -= o.z; return *this; }; float squaredlen() const { return x*x + y*y + z*z; }; float dot(const vec &o) const { return x*o.x + y*o.y + z*o.z; }; float magnitude() const { return sqrtf(squaredlen()); }; vec &normalize() { div(magnitude()); return *this; }; float dist(const vec &e) const { vec t; return dist(e, t); }; float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); }; bool reject(const vec &o, float max) { return x>o.x+max || xo.y+max || y