Files
MineGeo/renderer/map-view.mjs

20 lines
708 B
JavaScript

// Keep one world block square in the image, including rectangular exports.
// Eight pixels per block preserves the vanilla textures in typical 128-block
// exports; large worlds are capped to a manageable image size.
export function mapDimensions(bounds) {
const spanX = bounds.maxX - bounds.minX;
const spanZ = bounds.maxZ - bounds.minZ;
if (
!Number.isInteger(spanX) ||
!Number.isInteger(spanZ) ||
spanX < 1 ||
spanZ < 1
)
throw new Error("Surface map bounds must have a positive integer size");
const scale = Math.min(8, 2048 / Math.max(spanX, spanZ));
return {
width: Math.max(1, Math.round(spanX * scale)),
height: Math.max(1, Math.round(spanZ * scale)),
};
}