feat(editor): new points take the view's most used size (A5, R-10)
proposePoint, correctedCircle and centreCircle take the wanted radius, fitted to the frame; pendingForClick, keyboardPending and the C26 test (correctionFor) use it. The size comes from newPointSize: the strip's choice, else the most used radius of the view, else defaultRadius. pointSize.ts (stops, snap, range) and escape.ts (board 32 order) land with their tests; the repair dialog keeps defaultRadius (D1). Rewritten assertions: editor-frame.test.ts calls now pass defaultRadius(frame) explicitly, same expected values.
This commit is contained in:
1 parent
9d03e0675c
commit
8cd1bda6c2
13 files changed
+513
-100
No files matched your search
@@ -52,12 +52,20 @@ export function parseFrame(viewBox: string | null): Frame | null {
|
||||
return w > 0 && h > 0 ? { x, y, w, h } : null
|
||||
}
|
||||
|
||||
/** r0 = min(12 + 0.03 × max(w, h), min(w, h) / 2), floored to 0.01. */
|
||||
/**
|
||||
* The fallback size of a new point in a view without any point (A5):
|
||||
* r0 = min(12 + 0.03 × max(w, h), min(w, h) / 2), floored to 0.01.
|
||||
*/
|
||||
export function defaultRadius(frame: Frame): number {
|
||||
const wanted = 12 + 0.03 * Math.max(frame.w, frame.h)
|
||||
return floor2(Math.min(wanted, Math.min(frame.w, frame.h) / 2))
|
||||
}
|
||||
|
||||
/** The size a new point asks for, capped so that it fits F at all: min(radius, min(w, h) / 2). */
|
||||
export function fittedRadius(frame: Frame, radius: number): number {
|
||||
return floor2(Math.min(radius, Math.min(frame.w, frame.h) / 2))
|
||||
}
|
||||
|
||||
function distanceToEdge(frame: Frame, at: XY): number {
|
||||
return Math.min(
|
||||
at.x - frame.x,
|
||||
@@ -78,13 +86,17 @@ function clampAxis(value: number, low: number, high: number): number {
|
||||
}
|
||||
|
||||
/**
|
||||
* Candidate C: radius r0, the centre clamped per axis into [x + r0, x + w − r0] and
|
||||
* [y + r0, y + h − r0], rounded inward to 0.01. When that rounding leaves an empty
|
||||
* Candidate C: radius r0 (the wanted `radius`, fitted to F), the centre clamped per axis
|
||||
* into [x + r0, x + w − r0] and [y + r0, y + h − r0], rounded inward to 0.01. When that rounding leaves an empty
|
||||
* interval (r0 = min(w, h) / 2 with an origin off the grid) the exact clamped value is
|
||||
* used: the core accepts any decimals.
|
||||
*/
|
||||
export function correctedCircle(frame: Frame, at: XY): CircleShape {
|
||||
const r = defaultRadius(frame)
|
||||
export function correctedCircle(
|
||||
frame: Frame,
|
||||
at: XY,
|
||||
radius: number,
|
||||
): CircleShape {
|
||||
const r = fittedRadius(frame, radius)
|
||||
return {
|
||||
cx: clampAxis(round2(at.x), frame.x + r, frame.x + frame.w - r),
|
||||
cy: clampAxis(round2(at.y), frame.y + r, frame.y + frame.h - r),
|
||||
@@ -93,16 +105,21 @@ export function correctedCircle(frame: Frame, at: XY): CircleShape {
|
||||
}
|
||||
|
||||
/**
|
||||
* The proposal at a click (c rounded to 0.01, d its distance to the nearest edge of F):
|
||||
* The proposal at a click (c rounded to 0.01, d its distance to the nearest edge of F,
|
||||
* r0 the wanted `radius` fitted to F):
|
||||
* A (c, r0) when d ≥ r0; B (c, floor₀.₀₁(d)) when that radius is at least 0.01, else C
|
||||
* at once; nothing outside F (the edge is inclusive).
|
||||
*/
|
||||
export function proposePoint(frame: Frame, click: XY): PointProposal {
|
||||
export function proposePoint(
|
||||
frame: Frame,
|
||||
click: XY,
|
||||
radius: number,
|
||||
): PointProposal {
|
||||
if (distanceToEdge(frame, click) < 0) return { kind: 'outside' }
|
||||
const at = { x: round2(click.x), y: round2(click.y) }
|
||||
// A click inside F whose rounding lands outside it has no room: straight to C.
|
||||
const distance = Math.max(distanceToEdge(frame, at), 0)
|
||||
const r0 = defaultRadius(frame)
|
||||
const r0 = fittedRadius(frame, radius)
|
||||
if (distance >= r0) {
|
||||
return {
|
||||
kind: 'circle',
|
||||
@@ -112,7 +129,7 @@ export function proposePoint(frame: Frame, click: XY): PointProposal {
|
||||
}
|
||||
const smaller = floor2(distance)
|
||||
if (smaller < 0.01) {
|
||||
return { kind: 'corrected', circle: correctedCircle(frame, at) }
|
||||
return { kind: 'corrected', circle: correctedCircle(frame, at, radius) }
|
||||
}
|
||||
return {
|
||||
kind: 'circle',
|
||||
@@ -138,11 +155,15 @@ export function centreTriangle(frame: Frame): [number, number][] {
|
||||
* Where a keyboard-created point sits: the centre of F with r0. Clamped as candidate C is,
|
||||
* so it fits even with an origin off the 0.01 grid and r0 = min(w, h) / 2.
|
||||
*/
|
||||
export function centreCircle(frame: Frame): CircleShape {
|
||||
return correctedCircle(frame, {
|
||||
x: frame.x + frame.w / 2,
|
||||
y: frame.y + frame.h / 2,
|
||||
})
|
||||
export function centreCircle(frame: Frame, radius: number): CircleShape {
|
||||
const centre = { x: frame.x + frame.w / 2, y: frame.y + frame.h / 2 }
|
||||
return correctedCircle(frame, centre, radius)
|
||||
}
|
||||
|
||||
/** R-11: one arrow = 0.5 % of the frame's longer side (0.01 at least); Shift ×10 on keys. */
|
||||
export function moveStep(frame: Frame, big: boolean): number {
|
||||
const step = Math.max(0.01, round2(Math.max(frame.w, frame.h) * 0.005))
|
||||
return big ? round2(step * 10) : step
|
||||
}
|
||||
|
||||
export const sameCircle = (a: CircleShape, b: CircleShape): boolean =>
|
||||
|
||||
Reference in new issue
Block a user