Difference between revisions of "Modding:Coord"

From DoomRL Wiki

Jump to: navigation, search
(Created page)
 
m (removed 0994 warning)
Line 1: Line 1:
{{994 modding}}
 
 
 
Coords (short for coordinates) are used to describe positions on the map. They are also occassionally used to indicate relative positions.
 
Coords (short for coordinates) are used to describe positions on the map. They are also occassionally used to indicate relative positions.
  

Revision as of 01:52, 5 September 2011

Coords (short for coordinates) are used to describe positions on the map. They are also occassionally used to indicate relative positions.

Properties

Although coords are technically userdata, they can be indexed like normal tables.

Coord
Integer x This is the x-coordinate of the coord. In DoomRL, x increases going from left to right, starting at 1 on the left edge of the map.
Integer y This is the y-coordinate of the coord. In DoomRL, y increases going from top to bottom, starting at 1 on the upper edge of the map.

API

Coord Interface
Coord coord.new(integer x, integer y)
Coord coord.unm(Coord c)
Coord coord.add(Coord lhs, Coord rhs)
Coord coord.sub(Coord lhs, Coord rhs)
Coord coord.mul(Coord or integer lhs, Coord or integer rhs)
boolean coord.eq(Coord lhs, Coord, rhs)
Coord coord.abs(Coord c)
Coord coord.sign(Coord c)
integer coord.distance(Coord c1, Coord c2)
number coord.real_distance(Coord c1, Coord c2)
Coord coord.random(Coord c1, Coord c2)
integer, integer Coord:get()
string Coord:tostring()
Coord Coord:clone()
void Coord:random_shift(integer value)
Coord Coord:random_shifted(integer value)

coord.new(integer x, integer y) → Coord
This creates a new coord with the given x and y.

coord.unm(Coord c) → Coord
-Coord c → Coord
This creates a new coord whose coordinates are the inverse (negative) of the original coordinates.

coord.add(Coord lhs, Coord rhs) → Coord
Coord lhs + Coord rhs → Coord
This creates a new coord whose coordinates are the sums of the corresponding coordinates of lhs and rhs.

coord.sub(Coord lhs, Coord rhs) → Coord
Coord lhs - Coord rhs → Coord
This creates a new coord whose coordinates are the differences of the corresponding coordinates of lhs and rhs.

coord.mul(Coord or integer lhs, Coord or integer rhs) → Coord
Coord or integer lhs * Coord or integer rhs → Coord
With two coords, this creates a new coord whose coordinates are the products of the corresponding coordinates of lhs and rhs. With an integer, a new coord is returned with the coordinates of the original coord scaled by the integer. (This doesn't apply to two integers.)

coord.eq(Coord lhs, Coord, rhs) → boolean
Coord lhs == Coord rhs → boolean
This determines if the given coords are coordinate-wise equal. (They might still be different objects! Beware using coords as table keys.)

coord.abs(Coord c) → Coord
This creates a new coord with coordinates that are the absolute value of the corresponding original coordinates.

coord.sign(Coord c) → Coord
This creates a new coord by applying the sign function (1 for positive, 0 for zero, -1 for negative) to each coordinate of the original coord.

coord.distance(Coord c1, Coord c2) → integer
Calculates the distance between the given coords.

coord.real_distance(Coord c1, Coord c2) → number
Calculates the (approximate) Euclidean distance between the biven coords.

coord.random(Coord c1, Coord c2) → Coord
Returns a new coord uniformly at random whose x is between the x coordinates of c1 and c2 (inclusive) and whose y is between the y coordinates of c1 and c2. The coordinates of c1 should be less than or equal to the corresponding coordinates of c2.

Coord:get() → integer, integer
Returns the x and y coordinates of the coord (in order).

Coord:tostring() → string
Returns a string containing the x and y coordinates separated by a comma.

Coord:clone() → Coord
Returns a copy of the coord.

Coord:random_shift(integer value)
Changes the coord uniformly at random to a different coord (or possibly the same coord) whose x and y are within value of the originals. value is optional; it defaults to 1.

Coord:random_shifted(integer value) → Coord
As random_shift, except instead of changing the existing coord, a new coord is returned.

Constants

Constant Coords
null coord.UNIT This is a coord with 1 in both coordinates. Be careful not to change it.
null coord.ZERO This is a coord with 0 in both coordinates. Be careful not to change it.
Personal tools