Difference between revisions of "Modding:Coord"

From DoomRL Wiki

Jump to: navigation, search
m (removed 0994 warning)
m (so you don't have to use huge <font-decoration> tags for it)
Line 2: Line 2:
  
 
== Properties ==
 
== Properties ==
 
 
Although coords are technically userdata, they can be indexed like normal tables.
 
Although coords are technically userdata, they can be indexed like normal tables.
{|style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
+
 
|colspan=3 style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Coord'''
+
{|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
|-
+
! colspan="3" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Coord'''
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''Integer'''
+
{{Table3Col
|style="vertical-align:top; padding-right: 2ex;"|x
+
  |es=background: #333;
|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.
+
  |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 3px;
|-style="background: #333;"
+
  |c2=vertical-align:top; padding:0px 2px;
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''Integer'''
+
  |c3=padding:0px 2px;
|style="vertical-align:top; padding-right: 2ex;"|y
+
  |'''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.
|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.
+
  |'''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 ==
 
  
 +
== API ==
  
{|style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
+
{|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
|colspan=2 style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Coord Interface'''
+
! colspan="2" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Coord Interface'''
|-
+
{{Table2Col
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
  |es=background: #333;
|coord.[[#coord_new|new]]('''integer''' x, '''integer''' y)  
+
  |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px;
|-style="background: #333;"
+
  |c2=padding:0px 2px;
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_new|new]]('''integer''' x, '''integer''' y)  
|coord.[[#coord_unm|unm]]([[Modding:Coord|Coord]] c)  
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_unm|unm]]([[Modding:Coord|Coord]] c)  
|-
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_add|add]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs)  
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_sub|sub]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs)  
|coord.[[#coord_add|add]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs)  
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_mul|mul]]([[Modding:Coord|Coord]] or '''integer''' lhs, [[Modding:Coord|Coord]] or '''integer''' rhs)  
|-style="background: #333;"
+
  |'''boolean'''|coord.[[#coord_eq|eq]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]], rhs)  
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_abs|abs]]([[Modding:Coord|Coord]] c)  
|coord.[[#coord_sub|sub]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs)  
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_sign|sign]]([[Modding:Coord|Coord]] c)  
|-
+
  |'''integer'''|coord.[[#coord_distance|distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2)  
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
  |'''number'''|coord.[[#coord_real_distance|real_distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2)  
|coord.[[#coord_mul|mul]]([[Modding:Coord|Coord]] or '''integer''' lhs, [[Modding:Coord|Coord]] or '''integer''' rhs)  
+
  |[[Modding:Coord|Coord]]|coord.[[#coord_random|random]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2)  
|-style="background: #333;"
+
  |'''integer''', '''integer'''|[[Modding:Coord|Coord]]&#058;[[#coord_get|get]]()  
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''boolean'''
+
  |'''string'''|[[Modding:Coord|Coord]]&#058;[[#coord_tostring|tostring]]()  
|coord.[[#coord_eq|eq]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]], rhs)  
+
  |[[Modding:Coord|Coord]]|[[Modding:Coord|Coord]]&#058;[[#coord_clone|clone]]()  
|-
+
  |'''void'''|[[Modding:Coord|Coord]]&#058;[[#coord_random_shift|random_shift]]('''integer''' value)  
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
  |[[Modding:Coord|Coord]]|[[Modding:Coord|Coord]]&#058;[[#coord_random_shifted|random_shifted]]('''integer''' value)
|coord.[[#coord_abs|abs]]([[Modding:Coord|Coord]] c)  
+
  |}}
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
|coord.[[#coord_sign|sign]]([[Modding:Coord|Coord]] c)  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''integer'''
+
|coord.[[#coord_distance|distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2)  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''number'''
+
|coord.[[#coord_real_distance|real_distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2)  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
|coord.[[#coord_random|random]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2)  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''integer''', '''integer'''
+
|[[Modding:Coord|Coord]]&#058;[[#coord_get|get]]()  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''string'''
+
|[[Modding:Coord|Coord]]&#058;[[#coord_tostring|tostring]]()  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
|[[Modding:Coord|Coord]]&#058;[[#coord_clone|clone]]()  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
|[[Modding:Coord|Coord]]&#058;[[#coord_random_shift|random_shift]]('''integer''' value)  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
|[[Modding:Coord|Coord]]&#058;[[#coord_random_shifted|random_shifted]]('''integer''' value)  
+
 
|}
 
|}
  

Revision as of 20:39, 19 October 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