// Fixed-point format for expressing world-space coordinates, with 4 bits of // fractional resolution. #define PIXEL_NONE (-999) typedef int subpixel_t; #define TO_SP(v) \ (v << 4) inline subpixel_t to_sp(float screen_v) { return static_cast(screen_v * 16.0f); } template class SubpixelBase { public: // Code generation will require direct access to v, if performing // arithmetic with a local variable... T v; subpixel_t operator -(const SubpixelBase &other) { return (this->v - other.v); } void operator +=(float screen_v) { this->v += static_cast(to_sp(screen_v)); } void operator -=(float screen_v) { this->v -= static_cast(to_sp(screen_v)); } void operator =(float screen_v) { v = static_cast(to_sp(screen_v)); } void operator =(const T &screen_v) { v = TO_SP(screen_v); } T to_screen() const { return v >> 4; } static T None() { return to_sp(PIXEL_NONE); } }; template struct SPPointBase { T x, y; void set(float screen_x, float screen_y) { x = screen_x; y = screen_y; } void set(const T &screen_x, const T &screen_y) { x = screen_x; y = screen_y; } }; // 16-bit (Q12.4) typedef SubpixelBase Subpixel; typedef SPPointBase SPPoint; // 8-bit (Q4.4) typedef SubpixelBase SubpixelLength8; typedef SubpixelBase Subpixel8; typedef SPPointBase SPPoint8;