[Maintenance] Move the Subpixel class to a separate header, under TH03

Part of P0061, funded by Touhou Patch Center.
This commit is contained in:
nmlgc 2019-12-01 16:41:14 +01:00
parent 04d24ccf1c
commit bb6b0f1cc3
2 changed files with 37 additions and 33 deletions

36
th03/math/subpixel.hpp Normal file
View File

@ -0,0 +1,36 @@
// 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<subpixel_t>(screen_v * 16.0f);
}
class Subpixel {
public:
// Code generation will require direct access to v, if performing
// arithmetic with a local variable...
subpixel_t v;
void operator +=(float screen_v) {
this->v += to_sp(screen_v);
}
void operator -=(float screen_v) {
this->v -= to_sp(screen_v);
}
void operator =(float screen_v) {
v = to_sp(screen_v);
}
};
struct SPPoint {
Subpixel x, y;
void set(float screen_x, float screen_y) {
x = screen_x;
y = screen_y;
}
};

View File

@ -7,39 +7,7 @@
/// Math
/// ----
typedef int subpixel_t;
inline subpixel_t to_sp(float screen_v) {
return static_cast<subpixel_t>(screen_v * 16.0f);
}
class Subpixel {
public:
// Code generation will require direct access to v, if performing
// arithmetic with a local variable...
subpixel_t v;
void operator +=(float screen_v) {
this->v += to_sp(screen_v);
}
void operator -=(float screen_v) {
this->v -= to_sp(screen_v);
}
void operator =(float screen_v) {
v = to_sp(screen_v);
}
};
struct SPPoint {
Subpixel x, y;
void set(float screen_x, float screen_y) {
x = screen_x;
y = screen_y;
}
};
#include "th03/math/subpixel.hpp"
typedef struct {
SPPoint cur;