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
@@ -67,33 +67,51 @@ describe('proposePoint', () => {
|
||||
const frame = f(0, 0, 40, 30)
|
||||
|
||||
it('keeps the click with r0 when it is r0 or more from every edge (A)', () => {
|
||||
expect(proposePoint(frame, { x: 20.004, y: 15.006 })).toEqual({
|
||||
expect(
|
||||
proposePoint(frame, { x: 20.004, y: 15.006 }, defaultRadius(frame)),
|
||||
).toEqual({
|
||||
kind: 'circle',
|
||||
circle: { cx: 20, cy: 15.01, r: 13.2 },
|
||||
shrunk: false,
|
||||
})
|
||||
expect(proposePoint(frame, { x: 13.2, y: 15 })).toMatchObject({
|
||||
expect(
|
||||
proposePoint(frame, { x: 13.2, y: 15 }, defaultRadius(frame)),
|
||||
).toMatchObject({
|
||||
shrunk: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the click with a smaller radius when it is nearer an edge (B)', () => {
|
||||
expect(proposePoint(frame, { x: 13.19, y: 15 })).toEqual({
|
||||
expect(
|
||||
proposePoint(frame, { x: 13.19, y: 15 }, defaultRadius(frame)),
|
||||
).toEqual({
|
||||
kind: 'circle',
|
||||
circle: { cx: 13.19, cy: 15, r: 13.19 },
|
||||
shrunk: true,
|
||||
})
|
||||
expect(proposePoint(frame, { x: 5.555, y: 15 })).toMatchObject({
|
||||
expect(
|
||||
proposePoint(frame, { x: 5.555, y: 15 }, defaultRadius(frame)),
|
||||
).toMatchObject({
|
||||
circle: { cx: 5.56, r: 5.56 },
|
||||
})
|
||||
})
|
||||
|
||||
it('goes straight to C when B would be under 0.01, and nothing outside F', () => {
|
||||
expect(proposePoint(frame, { x: 0, y: 0 }).kind).toBe('corrected')
|
||||
expect(proposePoint(frame, { x: 40, y: 15 }).kind).toBe('corrected')
|
||||
expect(proposePoint(frame, { x: 0.004, y: 15 }).kind).toBe('corrected')
|
||||
expect(proposePoint(frame, { x: -0.1, y: 15 })).toEqual({ kind: 'outside' })
|
||||
expect(proposePoint(frame, { x: 20, y: 30.01 })).toEqual({
|
||||
expect(proposePoint(frame, { x: 0, y: 0 }, defaultRadius(frame)).kind).toBe(
|
||||
'corrected',
|
||||
)
|
||||
expect(
|
||||
proposePoint(frame, { x: 40, y: 15 }, defaultRadius(frame)).kind,
|
||||
).toBe('corrected')
|
||||
expect(
|
||||
proposePoint(frame, { x: 0.004, y: 15 }, defaultRadius(frame)).kind,
|
||||
).toBe('corrected')
|
||||
expect(
|
||||
proposePoint(frame, { x: -0.1, y: 15 }, defaultRadius(frame)),
|
||||
).toEqual({ kind: 'outside' })
|
||||
expect(
|
||||
proposePoint(frame, { x: 20, y: 30.01 }, defaultRadius(frame)),
|
||||
).toEqual({
|
||||
kind: 'outside',
|
||||
})
|
||||
})
|
||||
@@ -101,24 +119,42 @@ describe('proposePoint', () => {
|
||||
|
||||
describe('correctedCircle (C)', () => {
|
||||
it('clamps per axis with r0, inward on the hundredth grid', () => {
|
||||
expect(correctedCircle(f(0, 0, 40, 30), { x: 0, y: 0 })).toEqual({
|
||||
expect(
|
||||
correctedCircle(
|
||||
f(0, 0, 40, 30),
|
||||
{ x: 0, y: 0 },
|
||||
defaultRadius(f(0, 0, 40, 30)),
|
||||
),
|
||||
).toEqual({
|
||||
cx: 13.2,
|
||||
cy: 13.2,
|
||||
r: 13.2,
|
||||
})
|
||||
expect(correctedCircle(f(0, 0, 40, 30), { x: 40, y: 30 })).toEqual({
|
||||
expect(
|
||||
correctedCircle(
|
||||
f(0, 0, 40, 30),
|
||||
{ x: 40, y: 30 },
|
||||
defaultRadius(f(0, 0, 40, 30)),
|
||||
),
|
||||
).toEqual({
|
||||
cx: 26.8,
|
||||
cy: 16.8,
|
||||
r: 13.2,
|
||||
})
|
||||
expect(correctedCircle(f(0.003, 0, 40, 30), { x: 0.003, y: 15 }).cx).toBe(
|
||||
13.21,
|
||||
)
|
||||
expect(
|
||||
correctedCircle(
|
||||
f(0.003, 0, 40, 30),
|
||||
{ x: 0.003, y: 15 },
|
||||
defaultRadius(f(0.003, 0, 40, 30)),
|
||||
).cx,
|
||||
).toBe(13.21)
|
||||
})
|
||||
|
||||
it('uses the exact clamped value when the grid leaves an empty interval', () => {
|
||||
const frame = f(0.003, 0.004, 20, 20)
|
||||
expect(correctedCircle(frame, { x: 0.003, y: 0.004 })).toEqual({
|
||||
expect(
|
||||
correctedCircle(frame, { x: 0.003, y: 0.004 }, defaultRadius(frame)),
|
||||
).toEqual({
|
||||
cx: 10.003,
|
||||
cy: 10.004,
|
||||
r: 10,
|
||||
@@ -128,7 +164,9 @@ describe('correctedCircle (C)', () => {
|
||||
|
||||
describe('keyboard proposals', () => {
|
||||
it('holds a point at the centre of F with r0 and a triangle of 10 % of the smaller side', () => {
|
||||
expect(centreCircle(f(-50, 20, 40, 30))).toEqual({
|
||||
expect(
|
||||
centreCircle(f(-50, 20, 40, 30), defaultRadius(f(-50, 20, 40, 30))),
|
||||
).toEqual({
|
||||
cx: -30,
|
||||
cy: 35,
|
||||
r: 13.2,
|
||||
@@ -147,12 +185,23 @@ describe('correctionFor', () => {
|
||||
it('offers C for a refused B or an A refused out_of_frame, never for A too_small', () => {
|
||||
const reduced = { cx: 13.19, cy: 15, r: 13.19 }
|
||||
expect(
|
||||
correctionFor(frame, reduced, ['annotation.geometry.too_small'], 13.19),
|
||||
correctionFor(
|
||||
frame,
|
||||
reduced,
|
||||
['annotation.geometry.too_small'],
|
||||
13.19,
|
||||
defaultRadius(frame),
|
||||
),
|
||||
).not.toBeNull()
|
||||
const edge = { cx: 5, cy: 15, r: 13.2 }
|
||||
expect(
|
||||
correctionFor(frame, edge, ['annotation.geometry.out_of_frame'], 13.2)
|
||||
?.circle.cx,
|
||||
correctionFor(
|
||||
frame,
|
||||
edge,
|
||||
['annotation.geometry.out_of_frame'],
|
||||
13.2,
|
||||
defaultRadius(frame),
|
||||
)?.circle.cx,
|
||||
).toBe(13.2)
|
||||
expect(
|
||||
correctionFor(
|
||||
@@ -160,6 +209,7 @@ describe('correctionFor', () => {
|
||||
{ cx: 20, cy: 15, r: 13.2 },
|
||||
['annotation.geometry.too_small'],
|
||||
13.2,
|
||||
defaultRadius(frame),
|
||||
),
|
||||
).toBeNull()
|
||||
})
|
||||
@@ -167,7 +217,13 @@ describe('correctionFor', () => {
|
||||
it('offers nothing when C is the circle that was just refused', () => {
|
||||
const circle = { cx: 13.2, cy: 13.2, r: 13.2 }
|
||||
expect(
|
||||
correctionFor(frame, circle, ['annotation.geometry.out_of_frame'], 13.2),
|
||||
correctionFor(
|
||||
frame,
|
||||
circle,
|
||||
['annotation.geometry.out_of_frame'],
|
||||
13.2,
|
||||
defaultRadius(frame),
|
||||
),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -210,16 +266,14 @@ describe.each(FRAMES)('a point placed in the frame %s', (viewBox) => {
|
||||
const frame = frameOf(bed(viewBox))!
|
||||
for (const click of clicksOf(frame)) {
|
||||
const b = bed(viewBox)
|
||||
const proposal = proposePoint(frame, click)
|
||||
const proposal = proposePoint(frame, click, defaultRadius(frame))
|
||||
expect(proposal.kind).not.toBe('outside')
|
||||
if (proposal.kind === 'outside') continue
|
||||
const insert = circleInserter(b)
|
||||
const attempt = attemptPoint(
|
||||
frame,
|
||||
proposal.circle,
|
||||
insert,
|
||||
proposal.circle.r,
|
||||
)
|
||||
const attempt = attemptPoint(frame, proposal.circle, insert, {
|
||||
proposed: proposal.circle.r,
|
||||
wanted: defaultRadius(frame),
|
||||
})
|
||||
expect(attempt).toMatchObject({ status: 'created' })
|
||||
expect(currentErrors(b).size).toBe(0)
|
||||
}
|
||||
@@ -227,7 +281,11 @@ describe.each(FRAMES)('a point placed in the frame %s', (viewBox) => {
|
||||
|
||||
it('a corrected proposal is inserted only through the confirmation', () => {
|
||||
const frame = frameOf(bed(viewBox))!
|
||||
const proposal = proposePoint(frame, { x: frame.x, y: frame.y })
|
||||
const proposal = proposePoint(
|
||||
frame,
|
||||
{ x: frame.x, y: frame.y },
|
||||
defaultRadius(frame),
|
||||
)
|
||||
if (proposal.kind !== 'corrected')
|
||||
throw new Error('corner must be corrected')
|
||||
const b = bed(viewBox)
|
||||
@@ -253,14 +311,16 @@ describe('a very elongated frame', () => {
|
||||
it('refuses 1000 × 30 on too_small with the core message and creates nothing', () => {
|
||||
const b = bed('0 0 1000 30')
|
||||
const frame = frameOf(b)!
|
||||
const proposal = proposePoint(frame, { x: 500, y: 15 })
|
||||
if (proposal.kind !== 'circle') throw new Error('proposal')
|
||||
const attempt = attemptPoint(
|
||||
const proposal = proposePoint(
|
||||
frame,
|
||||
proposal.circle,
|
||||
circleInserter(b),
|
||||
proposal.circle.r,
|
||||
{ x: 500, y: 15 },
|
||||
defaultRadius(frame),
|
||||
)
|
||||
if (proposal.kind !== 'circle') throw new Error('proposal')
|
||||
const attempt = attemptPoint(frame, proposal.circle, circleInserter(b), {
|
||||
proposed: proposal.circle.r,
|
||||
wanted: defaultRadius(frame),
|
||||
})
|
||||
expect(attempt.status).toBe('refused')
|
||||
expect(b.preview.document).toBe(b.text)
|
||||
})
|
||||
@@ -277,16 +337,21 @@ describe('a detail crop', () => {
|
||||
it('places a point inside the crop and corrects one on its edge, never outside it', () => {
|
||||
const b = cropBed()
|
||||
const frame = frameOf(b, 'view-det')!
|
||||
const inside = proposePoint(frame, { x: 150, y: 350 })
|
||||
const inside = proposePoint(frame, { x: 150, y: 350 }, defaultRadius(frame))
|
||||
if (inside.kind !== 'circle') throw new Error('proposal')
|
||||
const insert = circleInserter(b, 'view-det')
|
||||
expect(
|
||||
attemptPoint(frame, inside.circle, insert, inside.circle.r),
|
||||
attemptPoint(frame, inside.circle, insert, {
|
||||
proposed: inside.circle.r,
|
||||
wanted: defaultRadius(frame),
|
||||
}),
|
||||
).toMatchObject({
|
||||
status: 'created',
|
||||
})
|
||||
expect(proposePoint(frame, { x: 99, y: 350 })).toEqual({ kind: 'outside' })
|
||||
const edge = proposePoint(frame, { x: 100, y: 200 })
|
||||
expect(
|
||||
proposePoint(frame, { x: 99, y: 350 }, defaultRadius(frame)),
|
||||
).toEqual({ kind: 'outside' })
|
||||
const edge = proposePoint(frame, { x: 100, y: 200 }, defaultRadius(frame))
|
||||
expect(edge.kind).toBe('corrected')
|
||||
expect(currentErrors(b).size).toBe(0)
|
||||
})
|
||||
@@ -298,8 +363,12 @@ describe('a radius the user typed (H5)', () => {
|
||||
it('is never replaced by a corrected position: the core issue is shown', () => {
|
||||
const typed = { cx: 20, cy: 15, r: 1 }
|
||||
const codes = ['annotation.geometry.too_small']
|
||||
expect(correctionFor(frame, typed, codes, 13.2)).toBeNull()
|
||||
expect(correctionFor(frame, typed, codes, undefined)).toBeNull()
|
||||
expect(
|
||||
correctionFor(frame, typed, codes, 13.2, defaultRadius(frame)),
|
||||
).toBeNull()
|
||||
expect(
|
||||
correctionFor(frame, typed, codes, undefined, defaultRadius(frame)),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('on the core: a typed too-small radius creates nothing and keeps the message', () => {
|
||||
@@ -309,7 +378,7 @@ describe('a radius the user typed (H5)', () => {
|
||||
big,
|
||||
{ cx: 2500, cy: 2500, r: 1 },
|
||||
circleInserter(b),
|
||||
defaultRadius(big),
|
||||
{ proposed: defaultRadius(big), wanted: defaultRadius(big) },
|
||||
)
|
||||
expect(attempt).toMatchObject({ status: 'refused' })
|
||||
expect(b.preview.document).toBe(b.text)
|
||||
@@ -325,13 +394,16 @@ describe('the keyboard point (H4)', () => {
|
||||
])('fits the frame %s by construction, with no correction', (viewBox) => {
|
||||
const b = bed(viewBox)
|
||||
const frame = frameOf(b)!
|
||||
const circle = centreCircle(frame)
|
||||
const circle = centreCircle(frame, defaultRadius(frame))
|
||||
const slack = 1e-9 // float noise of x + w / 2 − r only; the core decides below
|
||||
expect(circle.cx - circle.r).toBeGreaterThanOrEqual(frame.x - slack)
|
||||
expect(circle.cy - circle.r).toBeGreaterThanOrEqual(frame.y - slack)
|
||||
expect(circle.cx + circle.r).toBeLessThanOrEqual(frame.x + frame.w + slack)
|
||||
expect(circle.cy + circle.r).toBeLessThanOrEqual(frame.y + frame.h + slack)
|
||||
const attempt = attemptPoint(frame, circle, circleInserter(b), circle.r)
|
||||
const attempt = attemptPoint(frame, circle, circleInserter(b), {
|
||||
proposed: circle.r,
|
||||
wanted: defaultRadius(frame),
|
||||
})
|
||||
expect(attempt.status).not.toBe('correction')
|
||||
if (viewBox.endsWith('1000 30')) return
|
||||
expect(attempt).toMatchObject({ status: 'created' })
|
||||
@@ -345,13 +417,13 @@ describe.each(['0 0 1000 30', '0 0 4000 200'])(
|
||||
const frame = frameOf(bed(viewBox))!
|
||||
for (const click of clicksOf(frame)) {
|
||||
const b = bed(viewBox)
|
||||
const proposal = proposePoint(frame, click)
|
||||
const proposal = proposePoint(frame, click, defaultRadius(frame))
|
||||
if (proposal.kind === 'outside') continue
|
||||
const attempt = attemptPoint(
|
||||
frame,
|
||||
proposal.circle,
|
||||
circleInserter(b),
|
||||
proposal.circle.r,
|
||||
{ proposed: proposal.circle.r, wanted: defaultRadius(frame) },
|
||||
)
|
||||
expect(['created', 'refused', 'correction']).toContain(attempt.status)
|
||||
expect(currentErrors(b).size).toBe(0)
|
||||
|
||||
Reference in new issue
Block a user