tessellating flat top squares properly

This commit is contained in:
Gavin McDonald
2016-02-22 20:56:02 -05:00
parent d24e14af32
commit 42e0d7c8d2
4 changed files with 51 additions and 28 deletions

View File

@@ -9,14 +9,14 @@ function computeY(x, z) {
// round off coords
// throw out whichever one changed the most
// re-establish "x + y + z = 0"
function roundOff(x, y, z) {
let rX = Math.round(x);
let rY = Math.round(y);
let rZ = Math.round(z);
function roundOff(hex) {
let rX = Math.round(hex.x);
let rY = Math.round(hex.y);
let rZ = Math.round(hex.z);
let xDiff = Math.abs(rX - x);
let yDiff = Math.abs(rY - y);
let zDiff = Math.abs(rZ - z);
let xDiff = Math.abs(rX - hex.x);
let yDiff = Math.abs(rY - hex.y);
let zDiff = Math.abs(rZ - hex.z);
if ((xDiff > yDiff) && (xDiff > zDiff)) {
rX = -rY-rZ;
@@ -28,11 +28,11 @@ function roundOff(x, y, z) {
rZ = -rX-rY;
}
x = rX === -0 ? 0 : rX;
y = rY === -0 ? 0 : rY;
z = rZ === -0 ? 0 : rZ;
hex.x = rX === -0 ? 0 : rX;
hex.y = rY === -0 ? 0 : rY;
hex.z = rZ === -0 ? 0 : rZ;
return {x, y, z};
return hex;
}
export default class Hex extends Point {
@@ -51,7 +51,7 @@ export default class Hex extends Point {
this.z = arguments[2];
}
roundOff(this.x, this.y, this.z);
roundOff(this);
}
getX() {return this.x;}