more straightforward approach to providing location data for wrapped maps
This commit is contained in:
@@ -6,7 +6,11 @@ import {rangeInclusive, sqrt3} from './utils.js';
|
||||
import Hex from './hex.js';
|
||||
import Point from './point.js';
|
||||
|
||||
const tilePointToHex = ({tilePoint, pixelPoint}) => ({tilePoint: new Hex(tilePoint), pixelPoint});
|
||||
const tilePointToHex = ({tilePoint, mapPoint, pixelPoint}) => ({
|
||||
tilePoint: tilePoint instanceof Hex ? tilePoint : new Hex(tilePoint),
|
||||
mapPoint: mapPoint instanceof Hex ? mapPoint : new Hex(mapPoint),
|
||||
pixelPoint,
|
||||
});
|
||||
|
||||
const zeroZeroZero = new Hex({x: 0, y: 0, z: 0});
|
||||
|
||||
@@ -31,7 +35,7 @@ export default class CartographerFlatXYZ extends Cartographer {
|
||||
'calculateVerticalScale',
|
||||
|
||||
'tileToPixel',
|
||||
'_pixelToTile',
|
||||
'pixelToTile',
|
||||
'teleport',
|
||||
|
||||
'inBounds',
|
||||
@@ -118,13 +122,13 @@ export default class CartographerFlatXYZ extends Cartographer {
|
||||
tileToPixel (hex) {
|
||||
hex = hex instanceof Hex ? hex : new Hex(...arguments);
|
||||
|
||||
const pixelX = this.scale * 3/2 * hex.getQ();
|
||||
const pixelY = this.scale * sqrt3 * (hex.getR() + (hex.getQ() / 2));
|
||||
const pixelX = this.scale * 3/2 * hex.getQ() + this.originX;
|
||||
const pixelY = this.scale * sqrt3 * (hex.getR() + (hex.getQ() / 2)) + this.originY;
|
||||
|
||||
return new Point(pixelX + this.originX, pixelY + this.originY);
|
||||
return new Point(pixelX, pixelY);
|
||||
}
|
||||
|
||||
_pixelToTile (point) {
|
||||
pixelToTile (point) {
|
||||
point = point instanceof Point ? point : new Point(...arguments);
|
||||
|
||||
const pixelX = point.getX() - this.originX;
|
||||
@@ -137,6 +141,8 @@ export default class CartographerFlatXYZ extends Cartographer {
|
||||
}
|
||||
|
||||
teleport (hex) {
|
||||
if (!this.wrap) return hex;
|
||||
|
||||
hex = hex instanceof Hex ? hex : new Hex(hex);
|
||||
|
||||
if (this.radius) {
|
||||
@@ -207,16 +213,16 @@ export default class CartographerFlatXYZ extends Cartographer {
|
||||
}
|
||||
|
||||
enforceBoundries ({tilePoint, pixelPoint}) {
|
||||
return this.wrap ? ({tilePoint: this.teleport(tilePoint), pixelPoint}) :
|
||||
this.inBounds(tilePoint) ? ({tilePoint, pixelPoint}) :
|
||||
null;
|
||||
return this.wrap ? {tilePoint, mapPoint: this.teleport(tilePoint), pixelPoint} :
|
||||
this.inBounds(tilePoint) ? {tilePoint, mapPoint: tilePoint, pixelPoint} :
|
||||
{tilePoint, mapPoint: null, pixelPoint};
|
||||
}
|
||||
|
||||
boundingBox (upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) {
|
||||
const upperLeftTile = this._pixelToTile(upperLeftPoint);
|
||||
const lowerLeftTile = this._pixelToTile(lowerLeftPoint);
|
||||
const lowerRightTile = this._pixelToTile(lowerRightPoint);
|
||||
const upperRightTile = this._pixelToTile(upperRightPoint);
|
||||
const upperLeftTile = this.pixelToTile(upperLeftPoint);
|
||||
const lowerLeftTile = this.pixelToTile(lowerLeftPoint);
|
||||
const lowerRightTile = this.pixelToTile(lowerRightPoint);
|
||||
const upperRightTile = this.pixelToTile(upperRightPoint);
|
||||
|
||||
const columns = rangeInclusive(upperLeftTile.getQ() - 1, upperRightTile.getQ() + 1);
|
||||
|
||||
@@ -235,7 +241,6 @@ export default class CartographerFlatXYZ extends Cartographer {
|
||||
.map(makeAPoint)
|
||||
.map(makeAPointPair)
|
||||
.map(this.enforceBoundries)
|
||||
.compact()
|
||||
.map(tilePointToHex)
|
||||
.value();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user