mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 12:31:24 +01:00
submap mirror transformation, applicative style
This commit is contained in:
parent
38e708c0ed
commit
d0b7c3aa9a
3 changed files with 40 additions and 17 deletions
22
index.html
22
index.html
|
|
@ -4456,13 +4456,20 @@
|
||||||
type="range"
|
type="range"
|
||||||
min="1"
|
min="1"
|
||||||
max="13"
|
max="13"
|
||||||
value="8"
|
value="4"
|
||||||
data-cells="50000"
|
data-cells="10000"
|
||||||
oninput="document.getElementById('submapPointsOutput').value=cellsDensityConstants[+this.value]/1000 + 'K'; event.stopPropagation()"
|
oninput="document.getElementById('submapPointsOutput').value=cellsDensityConstants[+this.value]/1000 + 'K'; event.stopPropagation()"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<output id="submapPointsOutput" style="color: #053305">50K</output>
|
<output id="submapPointsOutput" style="color: #053305">10K</output>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Shift</td>
|
||||||
|
<td colspan="2">
|
||||||
|
X: <input id="submapShiftX" autocomplete="off" min="0" size="4" value="0"/>
|
||||||
|
Y: <input id="submapShiftY" autocomplete="off" min="0" size="4" value="0"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -4483,10 +4490,13 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Shift</td>
|
<td>Mirror</td>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
X: <input id="submapShiftX" autocomplete="off" min="0" size="4" value="0"/>
|
<input type="checkbox" class="checkbox" id="submapMirrorH" />
|
||||||
Y: <input id="submapShiftY" autocomplete="off" min="0" size="4" value="0"/>
|
<label for="submapMirrorH" class="checkbox-label" >Horizontally</label>
|
||||||
|
|
||||||
|
<input type="checkbox" class="checkbox" id="submapMirrorV" />
|
||||||
|
<label for="submapMirrorV" class="checkbox-label">Vertically</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
1
main.js
1
main.js
|
|
@ -1413,6 +1413,7 @@ function reMarkFeatures() {
|
||||||
cells.harbor[i] = water.length;
|
cells.harbor[i] = water.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!cells.i.length) return; // no cells -> there is nothing to do
|
||||||
for (let i = 1, queue = [0]; queue[0] !== -1; i++) {
|
for (let i = 1, queue = [0]; queue[0] !== -1; i++) {
|
||||||
const start = queue[0]; // first cell
|
const start = queue[0]; // first cell
|
||||||
cells.f[start] = i; // assign feature number
|
cells.f[start] = i; // assign feature number
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,12 @@ window.UISubmap = (function () {
|
||||||
|
|
||||||
function openRemapOptions() {
|
function openRemapOptions() {
|
||||||
resetZoom(0);
|
resetZoom(0);
|
||||||
|
document.getElementById("submapRotationAngle").value = 0;
|
||||||
|
document.getElementById("submapRotationAngleOutput").value = "0°";
|
||||||
|
document.getElementById("submapShiftX").value = 0;
|
||||||
|
document.getElementById("submapShiftY").value = 0;
|
||||||
|
document.getElementById("submapMirrorH").checked = false;
|
||||||
|
document.getElementById("submapMirrorV").checked = false;
|
||||||
$("#remapOptionsDialog").dialog({
|
$("#remapOptionsDialog").dialog({
|
||||||
title: "Resampler options",
|
title: "Resampler options",
|
||||||
resizable: false,
|
resizable: false,
|
||||||
|
|
@ -50,26 +56,32 @@ window.UISubmap = (function () {
|
||||||
const angle = Number(document.getElementById("submapRotationAngle").value) / 180 * Math.PI;
|
const angle = Number(document.getElementById("submapRotationAngle").value) / 180 * Math.PI;
|
||||||
const shiftX = Number(document.getElementById("submapShiftX").value);
|
const shiftX = Number(document.getElementById("submapShiftX").value);
|
||||||
const shiftY = Number(document.getElementById("submapShiftY").value);
|
const shiftY = Number(document.getElementById("submapShiftY").value);
|
||||||
|
const mirrorH = document.getElementById("submapMirrorH").checked;
|
||||||
|
const mirrorV = document.getElementById("submapMirrorV").checked;
|
||||||
|
if (!cellsDensityConstants[cellNumId]) {
|
||||||
|
console.error("Unknown cell number!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const [cx, cy] = [graphWidth / 2, graphHeight / 2];
|
const [cx, cy] = [graphWidth / 2, graphHeight / 2];
|
||||||
const rot = alfa => (x, y) => [
|
const rot = alfa => (x, y) => [
|
||||||
(x - cx) * Math.cos(alfa) - (y - cy) * Math.sin(alfa) + cx,
|
(x - cx) * Math.cos(alfa) - (y - cy) * Math.sin(alfa) + cx,
|
||||||
(y - cy) * Math.cos(alfa) + (x - cx) * Math.sin(alfa) + cy
|
(y - cy) * Math.cos(alfa) + (x - cx) * Math.sin(alfa) + cy
|
||||||
];
|
];
|
||||||
const shift = (dx, dy) => (x, y) => [x + dx, y + dy];
|
const shift = (dx, dy) => (x, y) => [x + dx, y + dy];
|
||||||
|
const flipH = (x, y) => [-x + 2 * cx, y];
|
||||||
|
const flipV = (x, y) => [x, -y + 2 * cy];
|
||||||
const app = (f, g) => (x, y) => f(...g(x, y));
|
const app = (f, g) => (x, y) => f(...g(x, y));
|
||||||
if (!cellsDensityConstants[cellNumId]) {
|
const id = (x, y) => [x, y];
|
||||||
console.error("Unknown cell number!");
|
let projection = id, inverse = id;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let projection, inverse;
|
if (angle) [projection, inverse] = [rot(angle), rot(-angle)];
|
||||||
if (angle || shiftX || shiftY) {
|
if (shiftX || shiftY) {
|
||||||
projection = app(shift(shiftX, shiftY), rot(angle));
|
projection = app(shift(shiftX, shiftY), projection);
|
||||||
inverse = app(rot(-angle), shift(-shiftX, -shiftY));
|
inverse = app(inverse, shift(-shiftX, -shiftY));
|
||||||
} else {
|
|
||||||
projection = (x, y) => [x, y];
|
|
||||||
inverse = (x, y) => [x, y];
|
|
||||||
}
|
}
|
||||||
|
if (mirrorH) [projection, inverse] = [app(flipH, projection), app(inverse, flipH)];
|
||||||
|
if (mirrorV) [projection, inverse] = [app(flipV, projection), app(inverse, flipV)];
|
||||||
|
|
||||||
changeCellsDensity(cellNumId);
|
changeCellsDensity(cellNumId);
|
||||||
WARN && console.warn("Resampling current map");
|
WARN && console.warn("Resampling current map");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue