21 #define _USE_MATH_DEFINES 34 if (len < 0.0000000001) {
46 int max_extent =
MAX(abs(x), abs(y));
47 if (max_extent > INT16_MAX)
48 factor = max_extent / INT16_MAX + 1;
55 static int sign(
int x) {
64 if (fwrite(&xcoord,
sizeof(xcoord), 1, fp) != 1)
return false;
65 if (fwrite(&ycoord,
sizeof(ycoord), 1, fp) != 1)
return false;
71 if (fread(&xcoord,
sizeof(xcoord), 1, fp) != 1)
return false;
72 if (fread(&ycoord,
sizeof(ycoord), 1, fp) != 1)
return false;
87 int* major,
int* minor)
const {
88 int abs_x = abs(xcoord);
89 int abs_y = abs(ycoord);
92 major_step->
xcoord = sign(xcoord);
95 minor_step->
ycoord = sign(ycoord);
101 major_step->
ycoord = sign(ycoord);
102 minor_step->
xcoord = sign(xcoord);
117 xcoord = cos(radians);
118 ycoord = sin(radians);
130 return direction * M_PI / 128.0 - M_PI;
137 const FCOORD& dir_vector)
const {
138 FCOORD point_vector(*
this - line_point);
143 double lambda = point_vector % dir_vector / dir_vector.
sqlength();
144 return line_point + (dir_vector * lambda);
float angle() const
find angle
uint8_t to_direction() const
void from_direction(uint8_t direction)
void setup_render(ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
static double angle_from_direction(uint8_t direction)
int direction(EDGEPT *point)
float length() const
find length
void ReverseN(void *ptr, int num_bytes)
ELISTIZE(ICOORDELT) bool FCOORD
bool DeSerialize(bool swap, FILE *fp)
bool normalise()
Convert to unit vec.
void set_with_shrink(int x, int y)
Set from the given x,y, shrinking the vector to fit if needed.
float sqlength() const
find sq length
int IntCastRounded(double x)
FCOORD nearest_pt_on_line(const FCOORD &line_point, const FCOORD &dir_vector) const
static uint8_t binary_angle_plus_pi(double angle)
bool Serialize(FILE *fp) const