wrapping for pointy hexagons

This commit is contained in:
Gavin McDonald
2019-01-05 16:51:52 -05:00
parent 87c2fd9885
commit 28f9647c3a
3 changed files with 149 additions and 73 deletions

View File

@@ -161,7 +161,7 @@ const positiveFarEast3x3 = [{
}];
export default class CartographerFlatXYZ extends Cartographer {
constructor(settings) {
constructor (settings) {
super(settings);
[
@@ -190,47 +190,47 @@ export default class CartographerFlatXYZ extends Cartographer {
].map(method => this[method] = this[method].bind(this));
}
tileHeight() {
tileHeight () {
return this.minWidth();
}
tileWidth() {
tileWidth () {
return this.maxWidth();
}
maxWidth() {
maxWidth () {
return this.scale * 2;
}
minWidth() {
minWidth () {
return this.scale * sqrt3;
}
horizontalOverhang() {
horizontalOverhang () {
return this.maxWidth() * 0.25;
}
verticalOverhang() {
verticalOverhang () {
return 0;
}
horizontalDistance() {
horizontalDistance () {
return this.maxWidth() * (3/4);
}
verticalDistance() {
verticalDistance () {
return this.minWidth();
}
calculateHorizontalScale(pixels, tiles) {
calculateHorizontalScale (pixels, tiles) {
return pixels / (tiles * 0.75 + 0.25) / 2;
}
calculateVerticalScale(pixels, tiles) {
calculateVerticalScale (pixels, tiles) {
return pixels / tiles / sqrt3;
}
tileToPixel(hex) {
tileToPixel (hex) {
hex = hex instanceof Hex ? hex : new Hex(...arguments);
const pixelX = this.scale * 3/2 * hex.getQ();
@@ -239,7 +239,7 @@ export default class CartographerFlatXYZ extends Cartographer {
return new Point(pixelX + this.originX, pixelY + this.originY);
}
_pixelToTile(point) {
_pixelToTile (point) {
point = point instanceof Point ? point : new Point(...arguments);
const pixelX = point.getX() - this.originX;
@@ -253,7 +253,7 @@ export default class CartographerFlatXYZ extends Cartographer {
teleport (hex) {
hex = hex instanceof Hex ? hex : new Hex(hex);
let {col, row} = hex.getOffsetHex();
let {col, row} = Hex.cubeToEvenQ(hex);
if (this.radius) {
}
@@ -289,11 +289,11 @@ export default class CartographerFlatXYZ extends Cartographer {
row -= halfHeight;
}
return Hex.offsetToCube(col, row);
return Hex.evenQToCube(col, row);
}
}
inBounds ({x, y, z = -x - y}) {
inBounds ({x, z, y = -x - z}) {
if (this.radius) {
if (this.negativeTiles) {
return Math.max(Math.abs(x), Math.abs(y), Math.abs(z)) <= Math.floor(this.radius);
@@ -320,7 +320,7 @@ export default class CartographerFlatXYZ extends Cartographer {
null;
}
boundingBox(upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) {
boundingBox (upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) {
const upperLeftTile = this._pixelToTile(upperLeftPoint);
const lowerLeftTile = this._pixelToTile(lowerLeftPoint);
const lowerRightTile = this._pixelToTile(lowerRightPoint);
@@ -337,7 +337,7 @@ export default class CartographerFlatXYZ extends Cartographer {
const bottom = top + height;
const rows = rangeInclusive(top, bottom + 1);
const makeAPoint = r => ({x: q, z: r, y: -q - r});
const makeAPoint = r => Hex.qrToCube(q, r);
return funky.chain(rows)
.map(makeAPoint)
@@ -348,21 +348,6 @@ export default class CartographerFlatXYZ extends Cartographer {
.value();
};
// if (debugged < 1) {
//
// [positive3x3, positiveEast3x3, positiveMiddleEast3x3, positiveFarEast3x3].forEach(set => {
// set.forEach((input, index) => {
// const result = this.teleport(input, true);
//
// if (result.x === positive3x3[index].x && result.y === positive3x3[index].y && result.z === positive3x3[index].z) console.log(input, '->', positive3x3[index]);
// else console.log(input, '><', positive3x3[index], result);
// console.log('---------------------------------------------------');
// });
//
// console.log('-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
// });
// }
return funky.chain(columns)
.map(processRow)
.flatten()