Constellations/js/Geometry/Vector.js

53 lines
829 B
JavaScript
Raw Permalink Normal View History

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