64 lines
1 KiB
JavaScript
64 lines
1 KiB
JavaScript
return {
|
|
make: make,
|
|
getRow: getRow,
|
|
getColumn: getColumn,
|
|
vertical: vertical,
|
|
horizontal: horizontal,
|
|
diagonal: diagonal,
|
|
zero: zero,
|
|
plus: plus,
|
|
opposite: opposite,
|
|
isSmaller: isSmaller,
|
|
toKey: toKey,
|
|
ofKey: ofKey,
|
|
};
|
|
|
|
function make(row, column) {
|
|
return {row: parseInt(row), column: parseInt(column)};
|
|
}
|
|
|
|
function getRow(v) {
|
|
return v.row;
|
|
}
|
|
|
|
function getColumn(v) {
|
|
return v.column;
|
|
}
|
|
|
|
function zero() {
|
|
return make(0, 0);
|
|
}
|
|
|
|
function vertical(length) {
|
|
return make(length, 0);
|
|
}
|
|
|
|
function horizontal(length) {
|
|
return make(0, length);
|
|
}
|
|
|
|
function diagonal(length) {
|
|
return make(length, length);
|
|
}
|
|
|
|
function plus(v0, v1) {
|
|
return make(v0.row + v1.row, v0.column + v1.column);
|
|
}
|
|
|
|
function opposite(v) {
|
|
return make(-v.row, -v.column);
|
|
}
|
|
|
|
function isSmaller(v0, v1) {
|
|
return v0.row <= v1.row && v0.column <= v1.column;
|
|
}
|
|
|
|
function toKey(v) {
|
|
return v.row + ':' + v.column;
|
|
//return 8*v.row + v.column;
|
|
}
|
|
|
|
function ofKey(k) {
|
|
return make.apply(null, k.split(':'));
|
|
//return make.call(null, Math.floor(k / 8), k % 8);
|
|
}
|