Skip to content

Commit 78a3a1b

Browse files
committed
refactor: clean up code formatting and remove unnecessary whitespace
1 parent a78f332 commit 78a3a1b

3 files changed

Lines changed: 51 additions & 28 deletions

File tree

src/controllers/coastline-editor.ts

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
defaultCoastSettings,
66
fractalize,
77
makeRoughnessProfile,
8-
PROFILE_SIZE
8+
PROFILE_SIZE,
99
} from "../renderers/coastline-fractal";
1010
import { byId } from "../utils";
1111

@@ -27,7 +27,7 @@ const SLIDER_DEFS: SliderDef[] = [
2727
min: 1,
2828
max: 5,
2929
step: 1,
30-
key: "maxDepth"
30+
key: "maxDepth",
3131
},
3232
{
3333
id: "coastBaseAmplitude",
@@ -36,7 +36,7 @@ const SLIDER_DEFS: SliderDef[] = [
3636
min: 0.2,
3737
max: 4,
3838
step: 0.1,
39-
key: "baseAmplitude"
39+
key: "baseAmplitude",
4040
},
4141
{
4242
id: "coastAmplitudeDecay",
@@ -45,7 +45,7 @@ const SLIDER_DEFS: SliderDef[] = [
4545
min: 0.01,
4646
max: 0.99,
4747
step: 0.01,
48-
key: "amplitudeDecay"
48+
key: "amplitudeDecay",
4949
},
5050
{
5151
id: "coastMinEdge",
@@ -54,7 +54,7 @@ const SLIDER_DEFS: SliderDef[] = [
5454
min: 0.1,
5555
max: 10,
5656
step: 0.1,
57-
key: "minEdge"
57+
key: "minEdge",
5858
},
5959
{
6060
id: "coastSmoothThreshold",
@@ -63,7 +63,7 @@ const SLIDER_DEFS: SliderDef[] = [
6363
min: 0.01,
6464
max: 0.5,
6565
step: 0.01,
66-
key: "smoothThreshold"
66+
key: "smoothThreshold",
6767
},
6868
{
6969
id: "coastRoughnessContrast",
@@ -72,7 +72,7 @@ const SLIDER_DEFS: SliderDef[] = [
7272
min: 0.5,
7373
max: 10,
7474
step: 0.1,
75-
key: "roughnessContrast"
75+
key: "roughnessContrast",
7676
},
7777
{
7878
id: "coastProfileHarmonics",
@@ -81,7 +81,7 @@ const SLIDER_DEFS: SliderDef[] = [
8181
min: 1,
8282
max: 8,
8383
step: 1,
84-
key: "profileHarmonics"
84+
key: "profileHarmonics",
8585
},
8686
{
8787
id: "coastLakeSmoothThreshMult",
@@ -90,8 +90,8 @@ const SLIDER_DEFS: SliderDef[] = [
9090
min: 0.1,
9191
max: 5,
9292
step: 0.1,
93-
key: "lakeSmoothThreshMult"
94-
}
93+
key: "lakeSmoothThreshMult",
94+
},
9595
];
9696

9797
const COAST_PRESETS: Record<string, Omit<CoastlineSettings, "enabled">> = {
@@ -147,7 +147,7 @@ export function open(): void {
147147
document.body.insertAdjacentHTML("beforeend", buildDialogHTML());
148148
}
149149

150-
for (const {id, key} of SLIDER_DEFS) {
150+
for (const { id, key } of SLIDER_DEFS) {
151151
const slider = byId(id) as HTMLInputElement | null;
152152
const output = byId(`${id}Out`) as HTMLElement | null;
153153
const resetBtn = byId(`${id}Reset`) as HTMLElement | null;
@@ -185,7 +185,7 @@ export function open(): void {
185185
thumb.style.left = defaultCoastSettings.enabled ? "18px" : "2px";
186186
slidersDiv.style.opacity = defaultCoastSettings.enabled ? "" : "0.4";
187187
slidersDiv.style.pointerEvents = defaultCoastSettings.enabled ? "" : "none";
188-
Object.keys(COAST_PRESETS).forEach(name => {
188+
Object.keys(COAST_PRESETS).forEach((name) => {
189189
const btn = byId(`coastPreset_${name}`) as HTMLButtonElement | null;
190190
if (btn) btn.disabled = !defaultCoastSettings.enabled;
191191
});
@@ -205,7 +205,7 @@ export function open(): void {
205205
if (!btn) continue;
206206
btn.on("click", () => {
207207
const preset = COAST_PRESETS[name];
208-
for (const {id, key} of SLIDER_DEFS) {
208+
for (const { id, key } of SLIDER_DEFS) {
209209
if (!(key in preset)) continue;
210210
const val = preset[key as keyof typeof preset];
211211
defaultCoastSettings[key] = val;
@@ -225,19 +225,20 @@ export function open(): void {
225225
$("#coastlineSettingsDialog").dialog({
226226
title: "Coastline Settings Editor",
227227
resizable: false,
228-
width: 'auto',
229-
position: {my: "right top", at: "right-10 top+10", of: "svg"}
228+
width: "auto",
229+
position: { my: "right top", at: "right-10 top+10", of: "svg" },
230230
});
231231
}
232232

233233
function buildDialogHTML(): string {
234234
const presetButtons = Object.keys(COAST_PRESETS)
235235
.map(
236-
name => `<button id="coastPreset_${name}" style="font-size:.78em;padding:2px 8px">${name}</button>`
236+
(name) =>
237+
`<button id="coastPreset_${name}" style="font-size:.78em;padding:2px 8px">${name}</button>`,
237238
)
238239
.join("");
239240

240-
const rows = SLIDER_DEFS.map(({id, label, tip, min, max, step, key}) => {
241+
const rows = SLIDER_DEFS.map(({ id, label, tip, min, max, step, key }) => {
241242
const value = defaultCoastSettings[key];
242243
return /* html */ `
243244
<tr data-tip="${tip}">
@@ -303,7 +304,11 @@ function drawRoughnessGraph(canvas: HTMLCanvasElement): void {
303304
ctx.clearRect(0, 0, W, H);
304305

305306
const rand = Alea(PREVIEW_SEED);
306-
const profile = makeRoughnessProfile(rand, defaultCoastSettings.roughnessContrast, defaultCoastSettings.profileHarmonics);
307+
const profile = makeRoughnessProfile(
308+
rand,
309+
defaultCoastSettings.roughnessContrast,
310+
defaultCoastSettings.profileHarmonics,
311+
);
307312

308313
const thresh = Math.min(Math.max(defaultCoastSettings.smoothThreshold, 0), 1);
309314
const threshY = H * (1 - thresh);
@@ -337,7 +342,11 @@ function drawRoughnessGraph(canvas: HTMLCanvasElement): void {
337342
};
338343

339344
// Helper: stroke curve clipped to a horizontal band
340-
const strokeBand = (clipTop: number, clipBot: number, color: string): void => {
345+
const strokeBand = (
346+
clipTop: number,
347+
clipBot: number,
348+
color: string,
349+
): void => {
341350
const h = clipBot - clipTop;
342351
if (h <= 0) return;
343352
ctx.save();
@@ -407,23 +416,37 @@ function drawShapePreview(canvas: HTMLCanvasElement): void {
407416
[cx, cy - r], // top
408417
[cx + r, cy], // right
409418
[cx, cy + r], // bottom
410-
[cx - r, cy] // left
419+
[cx - r, cy], // left
411420
];
412421

413422
const shape = defaultCoastSettings.enabled
414423
? fractalize(basePts, Alea(PREVIEW_SEED), defaultCoastSettings)
415-
: {points: basePts, origIndices: [0, 1, 2, 3]};
424+
: { points: basePts, origIndices: [0, 1, 2, 3] };
416425
const path = new Path2D(`${buildCoastlinePath(shape)}Z`);
417426

418427
// Ocean background — radial gradient, lighter at centre
419-
const bgGrad = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(W, H) * 0.85);
428+
const bgGrad = ctx.createRadialGradient(
429+
cx,
430+
cy,
431+
0,
432+
cx,
433+
cy,
434+
Math.max(W, H) * 0.85,
435+
);
420436
bgGrad.addColorStop(0, "#cce5f5");
421437
bgGrad.addColorStop(1, "#6aa4cb");
422438
ctx.fillStyle = bgGrad;
423439
ctx.fillRect(0, 0, W, H);
424440

425441
// Land fill with drop shadow
426-
const landGrad = ctx.createRadialGradient(cx - r * 0.1, cy - r * 0.1, r * 0.05, cx, cy, r * 1.1);
442+
const landGrad = ctx.createRadialGradient(
443+
cx - r * 0.1,
444+
cy - r * 0.1,
445+
r * 0.05,
446+
cx,
447+
cy,
448+
r * 1.1,
449+
);
427450
landGrad.addColorStop(0, "#d8c87a");
428451
landGrad.addColorStop(0.5, "#9cbc60");
429452
landGrad.addColorStop(1, "#5c8e40");
@@ -443,7 +466,7 @@ function drawShapePreview(canvas: HTMLCanvasElement): void {
443466
ctx.stroke(path);
444467

445468
// Original polygon skeleton — shows the raw 4-vertex input before fractalization
446-
const origPts = shape.origIndices.map(i => shape.points[i]);
469+
const origPts = shape.origIndices.map((i) => shape.points[i]);
447470
ctx.beginPath();
448471
for (let j = 0; j < origPts.length; j++) {
449472
const [x, y] = origPts[j];
@@ -482,8 +505,8 @@ function drawShapePreview(canvas: HTMLCanvasElement): void {
482505

483506
declare global {
484507
interface Window {
485-
CoastlineEditor: {open: () => void};
508+
CoastlineEditor: { open: () => void };
486509
}
487510
}
488511

489-
window.CoastlineEditor = {open};
512+
window.CoastlineEditor = { open };

src/renderers/coastline-fractal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export function fractalizeCoastline(
154154
...defaultCoastSettings,
155155
smoothThreshold: Math.min(
156156
1,
157-
defaultCoastSettings.smoothThreshold * defaultCoastSettings.lakeSmoothThreshMult,
157+
defaultCoastSettings.smoothThreshold *
158+
defaultCoastSettings.lakeSmoothThreshMult,
158159
),
159160
}
160161
: defaultCoastSettings;

src/renderers/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ import "./draw-relief-icons";
1212
import "./draw-scalebar";
1313
import "./draw-state-labels";
1414
import "./draw-temperature";
15-

0 commit comments

Comments
 (0)