-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.h
62 lines (51 loc) · 1.35 KB
/
line.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _LINE_H_
#define _LINE_H_
#include <vector>
#include <string>
#include "enums.h"
#include <math.h>
#define SLOPE_VERTICAL 999999
enum direction {
NORTH = 0,
NORTHEAST,
EAST,
SOUTHEAST,
SOUTH,
SOUTHWEST,
WEST,
NORTHWEST
};
// The "t" value decides WHICH Bresenham line is used.
std::vector <point> line_to(int x1, int y1, int x2, int y2, int t);
// sqrt(dX^2 + dY^2)
int trig_dist(int x1, int y1, int x2, int y2);
// Roguelike distance; minimum of dX and dY
int rl_dist(int x1, int y1, int x2, int y2);
int rl_dist(point a, point b);
double slope_of(std::vector<point> line);
std::vector<point> continue_line(std::vector<point> line, int distance);
direction direction_from(int x1, int y1, int x2, int y2);
std::string direction_name(direction dir);
std::string direction_name_short(direction dir);
// weird class for 2d vectors where dist is derived from rl_dist
struct rl_vec2d {
float x;
float y;
// vec2d(){}
rl_vec2d(float X = 0, float Y = 0) : x (X), y (Y) {}
rl_vec2d(const rl_vec2d &v) : x (v.x), y (v.y) {}
~rl_vec2d(){}
float norm();
rl_vec2d normalized();
float dot_product (rl_vec2d &v);
bool is_null();
// scale.
rl_vec2d operator* (const float rhs);
rl_vec2d operator/ (const float rhs);
// subtract
rl_vec2d operator- (const rl_vec2d &rhs);
// unary negation
rl_vec2d operator- ();
rl_vec2d operator+ (const rl_vec2d &rhs);
};
#endif