cell¶
Integer point/vector class defining the position of a cell.
The cell class behaves much as a normal 2D vector class, with the restriction that its components must be integer-valued. A subset of normal vector operations are available, namely a vector addition and subtraction, along with a vector equality check.
Along with the cell class definition, a number of distance measures
between cell positions are provided. Specifically, the Manhattan, Chebyshev
and Euclidean distances.
Fields¶
| Name | Type | Description |
|---|---|---|
x |
integer |
x-coordinate |
y |
integer |
y-coordinate |
cell.new¶
Initialise a new forma.cell.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
integer |
first coordinate |
y |
integer |
second coordinate |
Returns:
forma.cell— new forma.cell
cell.clone¶
Perform a copy of a cell.
Parameters:
| Name | Type | Description |
|---|---|---|
icell |
forma.cell |
cell to be copied |
Returns:
forma.cell— copy oficell
cell.__add¶
Add two cell positions.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
forma.cell— c = a + b
cell.__sub¶
Subtract two cell positions.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
forma.cell— c = a - b
cell.__eq¶
Test for equality of two cell vectors.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
boolean— a == b
cell.__tostring¶
Render a cell as a string.
Parameters:
| Name | Type | Description |
|---|---|---|
icell |
forma.cell |
the cell being rendered as a string |
Returns:
string— string of the form(icell.x, icell.y)
cell.manhattan¶
Manhattan distance between cells.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
integer— L1(a,b) = |a.x-b.x| + |a.y-b.y|
cell.chebyshev¶
Chebyshev distance between cells.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
integer— L_inf(a,b) = max(|a.x-b.x|, |a.y-b.y|)
cell.euclidean¶
Euclidean distance between cells.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
number— L_2(a,b) = sqrt((a-b)^2)
cell.euclidean2¶
Squared Euclidean distance between cells.
A little faster than cell.euclidean as it avoids the sqrt.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
forma.cell |
first cell |
b |
forma.cell |
second cell |
Returns:
number— L_2(a,b)^2 = (a-b)^2