168 lines
7.7 KiB
HTML
168 lines
7.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<title>Grids</title>
|
|
<link href="style.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body background="images/back.gif">
|
|
<!--START-->
|
|
|
|
|
|
<h3>Grids</h3>
|
|
|
|
A grid is simply a two-dimensional array. A grid has an integer width and
|
|
height. The structure allows you to set and retrieve the value of cells in
|
|
the grid by giving the index of it (which starts with 0 in both the x- and the
|
|
y-direction). But you can also set the value in regions, add values, and retrieve
|
|
the sum, max, min, and mean value over a region. The structure is useful to
|
|
represent e.g. a playing field. Even though all functionality can also be
|
|
achieved using two-dimensional arrays, the operations on regions are a
|
|
lot faster. The following functions exist:
|
|
|
|
<p>
|
|
<blockquote>
|
|
<tt><b>ds_grid_create(w,h)</b></tt>
|
|
Creates a new grid with the indicated width and height. The function returns an integer as
|
|
an id that must be used in all other functions to access the particular
|
|
grid.<br>
|
|
<tt><b>ds_grid_destroy(id)</b></tt>
|
|
Destroys the grid with the given id, freeing the memory used.
|
|
Don't forget to call this function when you are ready with the structure.<br>
|
|
<tt><b>ds_grid_copy(id,source)</b></tt>
|
|
Copies the grid source into the grid with the given id.<br>
|
|
<tt><b>ds_grid_resize(id,w,h)</b></tt>
|
|
Resizes the grid to the new width and height. Existing cells
|
|
keep their original value.<br>
|
|
<tt><b>ds_grid_width(id)</b></tt>
|
|
Returns the width of the grid with the indicated id.<br>
|
|
<tt><b>ds_grid_height(id)</b></tt>
|
|
Returns the height of the grid with the indicated id.<br>
|
|
<tt><b>ds_grid_clear(id,val)</b></tt>
|
|
Clears the grid with the given id, to the indicated value (can both be
|
|
a number or a string).<br>
|
|
<tt><b>ds_grid_set(id,x,y,val)</b></tt>
|
|
Sets the indicated cell in the grid with the given id, to the indicated value (can both be
|
|
a number or a string).<br>
|
|
<tt><b>ds_grid_add(id,x,y,val)</b></tt>
|
|
Add the value to the indicated cell in the grid with the given id. For
|
|
strings this corresponds to concatenation.<br>
|
|
<tt><b>ds_grid_multiply(id,x,y,val)</b></tt>
|
|
Multiplies the value to the indicated cell in the grid with the given id. Is only
|
|
valid for numbers.<br>
|
|
<tt><b>ds_grid_set_region(id,x1,y1,x2,y2,val)</b></tt>
|
|
Sets the all cells in the region in the grid with the given id, to the indicated value (can both be
|
|
a number or a string).<br>
|
|
<tt><b>ds_grid_add_region(id,x1,y1,x2,y2,val)</b></tt>
|
|
Add the value to the cell in the region in the grid with the given id. For
|
|
strings this corresponds to concatenation.<br>
|
|
<tt><b>ds_grid_multiply_region(id,x1,y1,x2,y2,val)</b></tt>
|
|
Multiplies the value to the cells in the region in the grid with the given id. Is only
|
|
valid for numbers.<br>
|
|
<tt><b>ds_grid_set_disk(id,xm,ym,r,val)</b></tt>
|
|
Sets all cells in the disk with center (xm,ym) and radius r.<br>
|
|
<tt><b>ds_grid_add_disk(id,xm,ym,r,val)</b></tt>
|
|
Add the value to all cells in the disk with center (xm,ym) and radius r.<br>
|
|
<tt><b>ds_grid_multiply_disk(id,xm,ym,r,val)</b></tt>
|
|
Multiply the value to all cells in the disk with center (xm,ym) and radius r.<br>
|
|
<tt><b>ds_grid_set_grid_region(id,source,x1,y1,x2,y2,xpos,ypos)</b></tt>
|
|
Copies the contents of the cells in the region
|
|
in grid source to grid id. xpos and ypos indicate the place where the region must be placed in the
|
|
grid. (Can also be used to copy values from one place in a grid to another.)<br>
|
|
<tt><b>ds_grid_add_grid_region(id,source,x1,y1,x2,y2,xpos,ypos)</b></tt>
|
|
Adds the contents of the cells in the region
|
|
in grid source to grid id. xpos and ypos indicate the place where the region must be added in the
|
|
grid. (id and source can be the same.)<br>
|
|
<tt><b>ds_grid_multiply_grid_region(id,source,x1,y1,x2,y2,xpos,ypos)</b></tt>
|
|
Multiplies the contents of the cells in the region
|
|
in grid source to grid id. xpos and ypos indicate the place where the region must be multiplied
|
|
in the grid. (id and source can be the same.) Only valid for numbers.<br>
|
|
<tt><b>ds_grid_get(id,x,y)</b></tt>
|
|
Returns the value of the indicated cell in the grid with the given id.<br>
|
|
<tt><b>ds_grid_get_sum(id,x1,y1,x2,y2)</b></tt>
|
|
Returns the sum of the values of the cells in the region in the grid with the given id.
|
|
Does only work when the cells contain numbers.<br>
|
|
<tt><b>ds_grid_get_max(id,x1,y1,x2,y2)</b></tt>
|
|
Returns the maximum of the values of the cells in the region in the grid with the given id.
|
|
Does only work when the cells contain numbers.<br>
|
|
<tt><b>ds_grid_get_min(id,x1,y1,x2,y2)</b></tt>
|
|
Returns the minimum of the values of the cells in the region in the grid with the given id.
|
|
Does only work when the cells contain numbers.<br>
|
|
<tt><b>ds_grid_get_mean(id,x1,y1,x2,y2)</b></tt>
|
|
Returns the mean of the values of the cells in the region in the grid with the given id.
|
|
Does only work when the cells contain numbers.<br>
|
|
<tt><b>ds_grid_get_disk_sum(id,xm,ym,r)</b></tt>
|
|
Returns the sum of the values of the cells in the disk.<br>
|
|
<tt><b>ds_grid_get_disk_min(id,xm,ym,r)</b></tt>
|
|
Returns the min of the values of the cells in the disk.<br>
|
|
<tt><b>ds_grid_get_disk_max(id,xm,ym,r)</b></tt>
|
|
Returns the max of the values of the cells in the disk.<br>
|
|
<tt><b>ds_grid_get_disk_mean(id,xm,ym,r)</b></tt>
|
|
Returns the mean of the values of the cells in the disk.<br>
|
|
<tt><b>ds_grid_value_exists(id,x1,y1,x2,y2,val)</b></tt>
|
|
Returns whether the value appears somewhere in the region.<br>
|
|
<tt><b>ds_grid_value_x(id,x1,y1,x2,y2,val)</b></tt>
|
|
Returns the x-coordinate of the cell in which the value appears in the region.<br>
|
|
<tt><b>ds_grid_value_y(id,x1,y1,x2,y2,val)</b></tt>
|
|
Returns the y-coordinate of the cell in which the value appears in the region.<br>
|
|
<tt><b>ds_grid_value_disk_exists(id,xm,ym,r,val)</b></tt>
|
|
Returns whether the value appears somewhere in the disk.<br>
|
|
<tt><b>ds_grid_value_disk_x(id,xm,ym,r,val)</b></tt>
|
|
Returns the x-coordinate of the cell in which the value appears in the disk.<br>
|
|
<tt><b>ds_grid_value_disk_y(id,xm,ym,r,val)</b></tt>
|
|
Returns the y-coordinate of the cell in which the value appears in the disk.<br>
|
|
<tt><b>ds_grid_shuffle(id)</b></tt>
|
|
Shuffles the values in the grid such that they end up in a random order.<br>
|
|
<tt><b>ds_grid_write(id)</b></tt>
|
|
Turns the data structure into a string and returns this string. The string can then
|
|
be used to e.g. save it to a file. This provides an easy mechanism for saving data
|
|
structures.<br>
|
|
<tt><b>ds_grid_read(id,str)</b></tt>
|
|
Reads the data structure from the given string (as created by the previous call).<br>
|
|
</blockquote>
|
|
|
|
<!--END-->
|
|
</body>
|
|
</html>
|
|
|
|
<!-- KEYWORDS
|
|
grids
|
|
|
|
ds_grid_create()
|
|
ds_grid_destroy()
|
|
ds_grid_copy()
|
|
ds_grid_resize()
|
|
ds_grid_width()
|
|
ds_grid_height()
|
|
ds_grid_clear()
|
|
ds_grid_set()
|
|
ds_grid_add()
|
|
ds_grid_multiply()
|
|
ds_grid_set_region()
|
|
ds_grid_add_region()
|
|
ds_grid_multiply_region()
|
|
ds_grid_set_disk()
|
|
ds_grid_add_disk()
|
|
ds_grid_multiply_disk()
|
|
ds_grid_set_grid_region()
|
|
ds_grid_add_grid_region()
|
|
ds_grid_multiply_grid_region()
|
|
ds_grid_get()
|
|
ds_grid_get_sum()
|
|
ds_grid_get_max()
|
|
ds_grid_get_min()
|
|
ds_grid_get_mean()
|
|
ds_grid_get_disk_sum()
|
|
ds_grid_get_disk_min()
|
|
ds_grid_get_disk_max()
|
|
ds_grid_get_disk_mean()
|
|
ds_grid_value_exists()
|
|
ds_grid_value_x()
|
|
ds_grid_value_y()
|
|
ds_grid_value_disk_exists()
|
|
ds_grid_value_disk_x()
|
|
ds_grid_value_disk_y()
|
|
ds_grid_shuffle()
|
|
ds_grid_write()
|
|
ds_grid_read()
|
|
--> |