// Fixed-point format for expressing world-space coordinates, with 4 bits of // fractional resolution. typedef int subpixel_t; 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; 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)); } T to_screen() const { return v >> 4; } }; template struct SPPointBase { T x, y; void set(float screen_x, float 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;