wrapping for pointyXY
This commit is contained in:
@@ -6,8 +6,7 @@ import {rangeInclusive, invSqrt2} from './utils.js';
|
||||
import Point from './point.js';
|
||||
import Square from './square.js';
|
||||
|
||||
const makeASquare = ({x, y}) => new Square(x, y);
|
||||
const tilePointToSquare = ({tilePoint, pixelPoint}) => ({tilePoint: makeASquare(tilePoint), pixelPoint});
|
||||
const tilePointToSquare = ({tilePoint, pixelPoint}) => ({tilePoint: new Square(tilePoint), pixelPoint});
|
||||
|
||||
export default class CartographerFlatXY extends Cartographer {
|
||||
constructor(settings) {
|
||||
@@ -30,7 +29,7 @@ export default class CartographerFlatXY extends Cartographer {
|
||||
'calculateVerticalScale',
|
||||
|
||||
'tileToPixel',
|
||||
'pixelToTile',
|
||||
'_pixelToTile',
|
||||
|
||||
'teleport',
|
||||
'inBounds',
|
||||
@@ -88,7 +87,7 @@ export default class CartographerFlatXY extends Cartographer {
|
||||
return new Point(x + this.originX, this.originY - y);
|
||||
}
|
||||
|
||||
pixelToTile(point) {
|
||||
_pixelToTile (point) {
|
||||
point = point instanceof Point ? point : new Point(...arguments);
|
||||
|
||||
const pixelX = point.getX() - this.originX;
|
||||
@@ -101,16 +100,11 @@ export default class CartographerFlatXY extends Cartographer {
|
||||
}
|
||||
|
||||
teleport ({x, y}) {
|
||||
if (this.negativeTiles) {
|
||||
x = x % Math.ceil(this.width / 2);
|
||||
y = y % Math.ceil(this.height / 2);
|
||||
}
|
||||
else {
|
||||
x = x % this.width;
|
||||
y = y % this.height;
|
||||
x = x < 0 ? this.width + x : x;
|
||||
y = y < 0 ? this.height + y : y;
|
||||
}
|
||||
x = x % this.width;
|
||||
y = y % this.height;
|
||||
|
||||
x = x < 0 ? this.width + x : x;
|
||||
y = y < 0 ? this.height + y : y;
|
||||
|
||||
return new Point(x, y);
|
||||
}
|
||||
@@ -133,9 +127,9 @@ export default class CartographerFlatXY extends Cartographer {
|
||||
}
|
||||
|
||||
boundingBox(upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) {
|
||||
const upperLeftTile = this.pixelToTile(upperLeftPoint);
|
||||
const lowerRightTile = this.pixelToTile(lowerRightPoint);
|
||||
const upperRightTile = this.pixelToTile(upperRightPoint);
|
||||
const upperLeftTile = this._pixelToTile(upperLeftPoint);
|
||||
const lowerRightTile = this._pixelToTile(lowerRightPoint);
|
||||
const upperRightTile = this._pixelToTile(upperRightPoint);
|
||||
|
||||
const columns = rangeInclusive(upperLeftTile.getX(), upperRightTile.getX());
|
||||
const rows = rangeInclusive(lowerRightTile.getY(), upperLeftTile.getY());
|
||||
|
||||
Reference in New Issue
Block a user