forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcod.c
More file actions
22 lines (19 loc) · 639 Bytes
/
Copy pathtcod.c
File metadata and controls
22 lines (19 loc) · 639 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "tcod.h"
#include "../libtcod/src/libtcod/bresenham.h"
/**
* Write a Bresenham line to the `x_out` and `y_out` arrays.
*
* `x_out` and `y_out` must be large enough to contain the entire line that
* this will output. Typically `max(abs(x1 - x2), abs(y1 - y2)) + 1`.
*
* This function includes both endpoints.
*/
int LineWhere(int x1, int y1, int x2, int y2, int *x_out, int *y_out) {
TCOD_bresenham_data_t bresenham;
*x_out = x1;
*y_out = y1;
if (x1 == x2 && y1 == y2) { return 0; }
TCOD_line_init_mt(x1, y1, x2, y2, &bresenham);
while (!TCOD_line_step_mt(++x_out, ++y_out, &bresenham)) {}
return 0;
}