@turf/square
Version:
Takes a bounding box and calculates the minimum square bounding box that would contain the input.
33 lines (30 loc) • 982 B
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});// index.ts
var _distance = require('@turf/distance');
function square(bbox) {
var west = bbox[0];
var south = bbox[1];
var east = bbox[2];
var north = bbox[3];
var horizontalDistance = _distance.distance.call(void 0, bbox.slice(0, 2), [east, south]);
var verticalDistance = _distance.distance.call(void 0, bbox.slice(0, 2), [west, north]);
if (horizontalDistance >= verticalDistance) {
var verticalMidpoint = (south + north) / 2;
return [
west,
verticalMidpoint - (east - west) / 2,
east,
verticalMidpoint + (east - west) / 2
];
} else {
var horizontalMidpoint = (west + east) / 2;
return [
horizontalMidpoint - (north - south) / 2,
south,
horizontalMidpoint + (north - south) / 2,
north
];
}
}
var index_default = square;
exports.default = index_default; exports.square = square;
//# sourceMappingURL=index.cjs.map