Avoid extra extent width calculation
This commit is contained in:
+16
-7
@@ -406,26 +406,35 @@ export function toStringXY(coordinate, opt_fractionDigits) {
|
|||||||
* exclusive.
|
* exclusive.
|
||||||
*
|
*
|
||||||
* @param {Coordinate} coordinate Coordinate.
|
* @param {Coordinate} coordinate Coordinate.
|
||||||
* @param {import("./proj/Projection.js").default} projection Projection
|
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||||
* @return {Coordinate} The coordinate within the real world extent.
|
* @return {Coordinate} The coordinate within the real world extent.
|
||||||
*/
|
*/
|
||||||
export function wrapX(coordinate, projection) {
|
export function wrapX(coordinate, projection) {
|
||||||
const worldsAway = getWorldsAway(coordinate, projection);
|
const worldWidth = getWidth(projection.getExtent());
|
||||||
|
const worldsAway = getWorldsAway(coordinate, projection, worldWidth);
|
||||||
if (worldsAway) {
|
if (worldsAway) {
|
||||||
coordinate[0] -= worldsAway * getWidth(projection.getExtent());
|
coordinate[0] -= worldsAway * worldWidth;
|
||||||
}
|
}
|
||||||
return coordinate;
|
return coordinate;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
export function getWorldsAway(coordinate, projection) {
|
* @param {Coordinate} coordinate Coordinate.
|
||||||
|
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||||
|
* @param {number=} opt_sourceExtentWidth Width of the source extent.
|
||||||
|
* @return {number} Offset in world widths.
|
||||||
|
*/
|
||||||
|
export function getWorldsAway(coordinate, projection, opt_sourceExtentWidth) {
|
||||||
const projectionExtent = projection.getExtent();
|
const projectionExtent = projection.getExtent();
|
||||||
let worldsAway = 0;
|
let worldsAway = 0;
|
||||||
if (
|
if (
|
||||||
projection.canWrapX() &&
|
projection.canWrapX() &&
|
||||||
(coordinate[0] < projectionExtent[0] || coordinate[0] > projectionExtent[2])
|
(coordinate[0] < projectionExtent[0] || coordinate[0] > projectionExtent[2])
|
||||||
) {
|
) {
|
||||||
const worldWidth = getWidth(projectionExtent);
|
const sourceExtentWidth =
|
||||||
worldsAway = Math.floor((coordinate[0] - projectionExtent[0]) / worldWidth);
|
opt_sourceExtentWidth || getWidth(projectionExtent);
|
||||||
|
worldsAway = Math.floor(
|
||||||
|
(coordinate[0] - projectionExtent[0]) / sourceExtentWidth
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return worldsAway;
|
return worldsAway;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user