diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-10 21:47:58 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:06:00 +0200 |
| commit | 8bd2bc91cc7e97f233031a42ccfda92af5e8bb96 (patch) | |
| tree | b2e4b127580140f3cb025af4d4490e8434ad63a7 /src/util | |
| parent | 540bb00a64e4704a0c08459af2b158bdafd59a60 (diff) | |
Implement map zooming
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/tile-calculations.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util/tile-calculations.js b/src/util/tile-calculations.js index 71442941..260f28e6 100644 --- a/src/util/tile-calculations.js +++ b/src/util/tile-calculations.js @@ -208,3 +208,44 @@ export function findTileWithPosition(tiles, positionX, positionY) { return null; } + +export function calculateRoomListBounds(rooms) { + const min = {x: Number.MAX_VALUE, y: Number.MAX_VALUE}; + const max = {x: -1, y: -1}; + + rooms.forEach((room) => { + room.tiles.forEach((tile) => { + if (tile.positionX < min.x) { + min.x = tile.positionX; + } + if (tile.positionY < min.y) { + min.y = tile.positionY; + } + + if (tile.positionX > max.x) { + max.x = tile.positionX; + } + if (tile.positionY > max.y) { + max.y = tile.positionY; + } + }); + }); + + max.x++; + max.y++; + + const center = { + x: min.x + (max.x - min.x) / 2.0, + y: min.y + (max.y - min.y) / 2.0 + }; + + return { + min, + center, + max + }; +} + +export function calculateRoomBounds(room) { + return calculateRoomListBounds([room]); +} |
