From 785daa23c2221fbfd2f449a6257b37c009741831 Mon Sep 17 00:00:00 2001 From: EwdErna Date: Fri, 23 Oct 2026 22:18:50 +0900 Subject: [PATCH] =?UTF-8?q?mock:=20=E3=82=B9=E3=82=BF=E3=83=93=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E3=81=AF=E3=80=81=E3=81=A9=E3=81=AE=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=82=BA=E3=82=82=E4=BD=95=E3=82=82=E9=81=B8=E3=81=B0=E3=81=AA?= =?UTF-8?q?=E3=81=84=E7=8A=B6=E6=85=8B=E3=81=8B=E3=82=89=E5=A7=8B=E3=82=81?= =?UTF-8?q?=E3=82=8B(T-30=20=E5=8D=98=E4=BD=8D8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 候補が1つのサイズも既定で選ばない。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017yoUu9Xd8dhwyQdCfKfaXG --- mock/src/domain/stabilizers.ts | 5 ----- mock/src/ui/phy/logic.ts | 12 +++--------- mock/tests/stabilizers.test.ts | 19 +++++-------------- provisional/decisions.md | 2 +- 4 files changed, 9 insertions(+), 29 deletions(-) diff --git a/mock/src/domain/stabilizers.ts b/mock/src/domain/stabilizers.ts index 7daefc1..8b136f1 100644 --- a/mock/src/domain/stabilizers.ts +++ b/mock/src/domain/stabilizers.ts @@ -44,11 +44,6 @@ export function stabilizerCandidates(size: Size): StabilizerCandidate[] { const length = Math.max(size.w, size.h); return TABLE.find((row) => row.lengths.some((l) => Math.abs(l - length) < EPS))?.candidates ?? []; } -/** A size with a single candidate shows it until chosen otherwise; several start unselected. */ -export function defaultStabilizerSelection(size: Size): string[] { - const candidates = stabilizerCandidates(size); - return candidates.length === 1 ? [candidates[0]!.id] : []; -} /** Mount points in key-local coordinates, around the (w, h) rectangle's center, not the switch. */ export function stabilizerPoints(size: Size, ids: string[]): Point[] { const cx = size.w / 2, diff --git a/mock/src/ui/phy/logic.ts b/mock/src/ui/phy/logic.ts index 13033a3..f7172d3 100644 --- a/mock/src/ui/phy/logic.ts +++ b/mock/src/ui/phy/logic.ts @@ -1,11 +1,6 @@ import type { KeyNode, Node, PhyFile, Transform } from "../../domain/phy"; import type { ProjectFile } from "../../domain/project"; -import { - defaultStabilizerSelection, - stabilizerCandidates, - stabilizerPoints, - switchPoint, -} from "../../domain/stabilizers"; +import { stabilizerCandidates, stabilizerPoints, switchPoint } from "../../domain/stabilizers"; import { apply, compose, inverse, matrix, type Affine } from "../../domain/geometry"; export function normalizeSelection(file: PhyFile, ids: string[]): string[] { @@ -337,10 +332,9 @@ export function stabilizerSelections(project: ProjectFile): StabilizerSelections const ui = project.ui as { phy?: { stabilizers?: StabilizerSelections } } | undefined; return ui?.phy?.stabilizers ?? {}; } -/** 記録がなければサイズの既定。サイズが変わって候補にない記録は捨てて読む。 */ +/** 記録がなければ何も選ばない。サイズが変わって候補にない記録は捨てて読む。 */ export function selectedStabilizers(selections: StabilizerSelections, key: KeyNode): string[] { - const ids = selections[key.id]; - if (!ids) return defaultStabilizerSelection(key.size); + const ids = selections[key.id] ?? []; const known = new Set(stabilizerCandidates(key.size).map((c) => c.id)); return ids.filter((id) => known.has(id)); } diff --git a/mock/tests/stabilizers.test.ts b/mock/tests/stabilizers.test.ts index 6483f1a..e3f2a8b 100644 --- a/mock/tests/stabilizers.test.ts +++ b/mock/tests/stabilizers.test.ts @@ -1,10 +1,5 @@ import { describe, expect, it } from "vitest"; -import { - defaultStabilizerSelection, - stabilizerCandidates, - stabilizerPoints, - switchPoint, -} from "../src/domain/stabilizers"; +import { stabilizerCandidates, stabilizerPoints, switchPoint } from "../src/domain/stabilizers"; import { mountMarks, selectedStabilizers, stabilizerSelections, withStabilizers } from "../src/ui/phy/logic"; import type { KeyNode } from "../src/domain/phy"; import type { ProjectFile } from "../src/domain/project"; @@ -34,10 +29,6 @@ describe("stabilizer candidates", () => { expect(stabilizerCandidates({ w: 1.25, h: 2, w2: 1.5, h2: 1, x2: -0.25 })).toEqual([]); expect(stabilizerCandidates({ w: 2, h: 1, w2: 2.25 })).toEqual([]); }); - it("selects a lone candidate by default and nothing when there are several", () => { - expect(defaultStabilizerSelection({ w: 2, h: 1 })).toEqual(["11.938mm"]); - expect(defaultStabilizerSelection({ w: 6.25, h: 1 })).toEqual([]); - }); it("places mounts around the rectangle center along the long axis", () => { expect(stabilizerPoints({ w: 7, h: 1 }, ["3u"])).toEqual([ { x: 0.5, y: 0.5 }, @@ -57,9 +48,9 @@ describe("stabilizer candidates", () => { describe("stabilizer selections in ProjectFile.ui", () => { const project = { ui: { other: 1 } } as unknown as ProjectFile; - it("falls back to the size default and drops ids the size no longer offers", () => { - expect(selectedStabilizers({}, key("a", 2))).toEqual(["11.938mm"]); - expect(selectedStabilizers({ a: [] }, key("a", 2))).toEqual([]); + it("selects nothing by default and drops ids the size no longer offers", () => { + expect(selectedStabilizers({}, key("a", 2))).toEqual([]); + expect(selectedStabilizers({ a: ["11.938mm"] }, key("a", 2))).toEqual(["11.938mm"]); expect(selectedStabilizers({ a: ["2.5u", "3u"] }, key("a", 6))).toEqual(["2.5u"]); }); it("writes per key without touching other ui state", () => { @@ -86,7 +77,7 @@ describe("stabilizer selections in ProjectFile.ui", () => { }, ], { g: "v2" }, - {}, + { a: ["11.938mm"] }, ); expect(marks.map((m) => m.id)).toEqual(["a", "c"]); expect(marks[1]!.transform.f).toBe(1); diff --git a/provisional/decisions.md b/provisional/decisions.md index e634f2e..ca48bf0 100644 --- a/provisional/decisions.md +++ b/provisional/decisions.md @@ -96,7 +96,7 @@ T-29 のコードを作り直さず、[phy-editor-feedback.md](phy-editor-feedba スタビ位置はキーのサイズで候補を引き、キーごとに候補を複数選べる。何も選ばなくてもよい。 選んだ候補はプロジェクトファイルの `ui` にキーIDごとに持ち、PHYには入れない(いずれPHYへ移す)。 -候補が1つのサイズは、その候補を選んだ状態で表示する。候補が複数のサイズは、何も選ばない状態から始める。 +どのサイズも、何も選ばない状態から始める。 候補を選んでも `switchOffset` は変えない。`switchOffset` は手で入れる。 候補は、キーの (w,h) 矩形の中心から±の位置に置く2点で表す(1U = 19.05mm)。縦長のキーは長辺の向きに置く。