libtcod
Loading...
Searching...
No Matches
Bresenham lines

Classes

struct  TCOD_bresenham_data_t
 A struct used for computing a bresenham line. More...
 
class  TCODLineListener
 
class  TCODLine
 

Typedefs

typedef bool(* TCOD_line_listener_t) (int x, int y)
 A callback to be passed to TCOD_line.
 

Functions

void TCOD_line_init (int xFrom, int yFrom, int xTo, int yTo)
 Initialize a line using a global state.
 
bool TCOD_line_step (int *xCur, int *yCur)
 Advance to the next point in a line, returns true once the line has ended.
 
bool TCOD_line (int xFrom, int yFrom, int xTo, int yTo, TCOD_line_listener_t listener)
 Iterate over a line using a callback.
 
void TCOD_line_init_mt (int xFrom, int yFrom, int xTo, int yTo, TCOD_bresenham_data_t *data)
 Initialize a TCOD_bresenham_data_t struct.
 
bool TCOD_line_step_mt (int *xCur, int *yCur, TCOD_bresenham_data_t *data)
 Get the next point on a line, returns true once the line has ended.
 
bool TCOD_line_mt (int xFrom, int yFrom, int xTo, int yTo, TCOD_line_listener_t listener, TCOD_bresenham_data_t *data)
 Iterate over a line using a callback.
 

Detailed Description

Typedef Documentation

◆ TCOD_line_listener_t

typedef bool(* TCOD_line_listener_t) (int x, int y)

A callback to be passed to TCOD_line.

The points given to the callback include both the starting and ending positions.

Parameters
x
y
Returns
As long as this callback returns true it will be called with the next x,y point on the line.

Function Documentation

◆ TCOD_line()

bool TCOD_line ( int xFrom,
int yFrom,
int xTo,
int yTo,
TCOD_line_listener_t listener )

Iterate over a line using a callback.

Parameters
xoThe origin x position.
yoThe origin y position.
xdThe destination x position.
ydThe destination y position.
listenerA TCOD_line_listener_t callback. Iteration stops early if this callback returns false.
Returns
true if the line was completely exhausted by the callback.
embed:rst:leading-asterisk
*  .. versionchanged:: 1.6.6
*    This function is now reentrant.
*  

◆ TCOD_line_init()

void TCOD_line_init ( int xFrom,
int yFrom,
int xTo,
int yTo )

Initialize a line using a global state.

Parameters
xFromThe starting x position.
yFromThe starting y position.
xToThe ending x position.
yToThe ending y position.
embed:rst:leading-asterisk
*  .. deprecated:: 1.6.6
*    This function is not reentrant and will fail if a new line is started
*    before the last is finished processing.
*
*    Use TCOD_line_init_mt instead.
*  

◆ TCOD_line_init_mt()

void TCOD_line_init_mt ( int xFrom,
int yFrom,
int xTo,
int yTo,
TCOD_bresenham_data_t * data )

Initialize a TCOD_bresenham_data_t struct.

Parameters
xFromThe starting x position.
yFromThe starting y position.
xToThe ending x position.
yToThe ending y position.
dataPointer to a TCOD_bresenham_data_t struct.

After calling this function you use TCOD_line_step_mt to iterate over the individual points on the line.

◆ TCOD_line_mt()

bool TCOD_line_mt ( int xFrom,
int yFrom,
int xTo,
int yTo,
TCOD_line_listener_t listener,
TCOD_bresenham_data_t * data )

Iterate over a line using a callback.

Parameters
xoThe origin x position.
yoThe origin y position.
xdThe destination x position.
ydThe destination y position.
listenerA TCOD_line_listener_t callback.
dataPointer to a TCOD_bresenham_data_t struct.
Returns
true if the line was completely exhausted by the callback.
embed:rst:leading-asterisk
*  .. deprecated:: 1.6.6
*    The `data` parameter for this call is redundant, you should call
*    TCOD_line instead.
*  

◆ TCOD_line_step()

bool TCOD_line_step ( int * xCur,
int * yCur )

Advance to the next point in a line, returns true once the line has ended.

Parameters
xCurAn int pointer to fill with the next x position.
yCurAn int pointer to fill with the next y position.
Returns
true once the ending point has been reached.

The starting point is excluded by this function. After the ending point is reached, the next call will return true.

embed:rst:leading-asterisk
*  .. deprecated:: 1.6.6
*    This function is not reentrant and will fail if a new line is started
*    before the last is finished processing.
*
*    Use TCOD_line_step_mt instead.
*  

◆ TCOD_line_step_mt()

bool TCOD_line_step_mt ( int * xCur,
int * yCur,
TCOD_bresenham_data_t * data )

Get the next point on a line, returns true once the line has ended.

Parameters
xCurAn int pointer to fill with the next x position.
yCurAn int pointer to fill with the next y position.
dataPointer to a initialized TCOD_bresenham_data_t struct.
Returns
true after the ending point has been reached.

The starting point is excluded by this function. After the ending point is reached, the next call will return true.