geom.js 728 B

1234567891011121314151617181920212223242526
  1. // Fonctions géométriques partagées pour le map editor
  2. (function(){
  3. function axialToPixel(tileSize, q, r) {
  4. // pointy-top axial coordinates
  5. const x = tileSize * Math.sqrt(3) * (q + r / 2);
  6. const y = tileSize * 1.5 * r;
  7. return { x, y };
  8. }
  9. function computeZoom(currentZoom, factor) {
  10. let z = currentZoom * factor;
  11. z = Math.max(0.1, Math.min(5, z));
  12. return z;
  13. }
  14. function computePanOffset(offset, dx, dy) {
  15. return { x: offset.x + dx, y: offset.y + dy };
  16. }
  17. window.MG = window.MG || {};
  18. window.MG.geom = {
  19. axialToPixel: axialToPixel,
  20. computeZoom: computeZoom,
  21. computePanOffset: computePanOffset
  22. };
  23. })();