Constellations/js/Geometry/Vector.js

65 lines
1 KiB
JavaScript
Raw Permalink Normal View History

2022-08-10 21:12:39 +02:00
return {
make: make,
getRow: getRow,
getColumn: getColumn,
2022-08-10 21:12:39 +02:00
vertical: vertical,
horizontal: horizontal,
diagonal: diagonal,
zero: zero,
plus: plus,
opposite: opposite,
isSmaller: isSmaller,
toKey: toKey,
ofKey: ofKey,
2022-08-10 21:12:39 +02:00
};
function make(row, column) {
return {row: parseInt(row), column: parseInt(column)};
}
function getRow(v) {
return v.row;
}
function getColumn(v) {
return v.column;
2022-08-10 21:12:39 +02:00
}
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);
2022-08-10 21:12:39 +02:00
}
function opposite(v) {
return make(-v.row, -v.column);
2022-08-10 21:12:39 +02:00
}
function isSmaller(v0, v1) {
return v0.row <= v1.row && v0.column <= v1.column;
}
function toKey(v) {
2022-08-10 21:12:39 +02:00
return v.row + ':' + v.column;
//return 8*v.row + v.column;
2022-08-10 21:12:39 +02:00
}
function ofKey(k) {
return make.apply(null, k.split(':'));
//return make.call(null, Math.floor(k / 8), k % 8);
2022-08-10 21:12:39 +02:00
}