[*] limit tiles in bounds based on width/height/radius
This commit is contained in:
@@ -27,6 +27,8 @@ export default class CartographerPointyXY extends Cartographer {
|
||||
|
||||
'tileToPixel',
|
||||
'pixelToTile',
|
||||
|
||||
'inBounds',
|
||||
'boundingBox',
|
||||
].map(method => this[method] = this[method].bind(this));
|
||||
}
|
||||
@@ -97,6 +99,17 @@ export default class CartographerPointyXY extends Cartographer {
|
||||
return new Square(x, y);
|
||||
}
|
||||
|
||||
inBounds (x, y) {
|
||||
if (this.negativeTiles) {
|
||||
return (!this.width || Math.abs(x) <= Math.floor(this.width / 2))
|
||||
&& (!this.height || Math.abs(y) <= Math.floor(this.height / 2));
|
||||
}
|
||||
else {
|
||||
return (!this.width || (x >= 0 && x < this.width))
|
||||
&& (!this.height || (y >= 0 && y < this.height));
|
||||
}
|
||||
}
|
||||
|
||||
boundingBox(upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) {
|
||||
const upperLeftTile = this.pixelToTile(upperLeftPoint);
|
||||
const lowerRightTile = this.pixelToTile(lowerRightPoint);
|
||||
@@ -125,7 +138,10 @@ export default class CartographerPointyXY extends Cartographer {
|
||||
// push out by 1 on either end to account for interlocking tiles
|
||||
const rows = rangeInclusive(bottom - 1, top + 1);
|
||||
|
||||
return rows.map(y => new Square(x, y));
|
||||
return rows.map(y => ({x, y}))
|
||||
.reduce((flat, list) => flat.concat(list), [])
|
||||
.filter(({x, y}) => this.inBounds(x, y))
|
||||
.map(({x, y}) => new Square(x, y));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user