U2 Task 5. A selected polygon gets its vertex, « + » and « − » handles (R-9, hidden « + » under two hit radii, R-18 zoom hint in the strip), the handle cap at 40 (R-7), vertex drag and keys, the move mode on the zone or the chosen vertex, « Redessiner » as a redraw mode kept in step with its tracing (R-12 guard, R-13 drop), close radius in CSS px (R-11). The numeric group leaves the properties panel (D1). Removed or rewritten assertions (numeric group -> replacement): - tab « shows its exact stored numbers » (Centre x field) -> the overlay selection circle's cx attribute, same exact value. - tab « a numeric edit » x3 -> « an edit on the drawing »: Enter on the handle without a step commits nothing, a step + Enter commits once; a refused handle drag keeps the stored shape then a drag inside the frame repairs it (issues gone); Escape drops a pending series. - tab C26 « Centre x 15 » -> overlay cx 15. - tab C32 unmeasured « Centre x as text » -> no handle, no field. - tab « adds and removes a vertex as part of the whole group » -> « + » then « − » on the drawing; « never offers to remove below three » -> « − » aria-disabled at 3. - tab H8 « refused Remplacer drops the tracing » -> keeps it open with « Fermeture refusée » (board 33 A); « refused vertex add/remove stay non appliqué » -> a refused vertex drag restores the shape exactly. - tab Désélectionner and D6b (typed Centre x committed, refused, undone) x6 and strip « a new commit replaces the message » -> the same with the Nom (FR) field (a blank name is the refused value). - focus-request « Centre x 20 » -> overlay cx 20. - escape « strip commands keep their Escape » -> a redraw: Escape on the strip or the box cancels it (R-12 row 4); kept for a new zone tracing. - keep-alive « Remplacer tracing kept across Aller à » -> ended by a tab when empty, asked once a vertex is placed (R-12). - e2e annotations: numeric cx edit + undo/redo -> handle keys + undo/ redo; jitter/drag and Task 4 point reads -> overlay attributes (the stored place during the mode -> overlay-old-place); keyboard-only cy and vertex x typed -> handle and vertex keys. - e2e deselect: Centre x typed/refused/committed -> Nom (FR). - e2e geometry, shell-crossing: Centre x/cy reads -> overlay attributes. - e2e journey: cx +3 and vertex x +4 typed -> 3 and 4 arrow steps + Enter; a far typed value + revert -> a far handle drag refused. - e2e equine latency: typed cx rounds -> handle arrow + Enter rounds.
121 lines
3.2 KiB
TypeScript
121 lines
3.2 KiB
TypeScript
/** U2 Task 5: the polygon arithmetic of the vertex handles (R-7, R-9). */
|
|
import { describe, expect, it } from 'vitest'
|
|
import type { Point } from '@faunosteo/core-wasm/types'
|
|
import {
|
|
HANDLE_CAP,
|
|
MIN_VERTICES,
|
|
insertMidpoint,
|
|
isNoOpMove,
|
|
moveVertex,
|
|
removeVertex,
|
|
showsInsert,
|
|
} from '@/editor/annotations/polygonEdit'
|
|
|
|
const square: Point[] = [
|
|
[0, 0],
|
|
[10, 0],
|
|
[10, 10],
|
|
[0, 10],
|
|
]
|
|
|
|
describe('the limits', () => {
|
|
it('caps the handles at 40 vertices and keeps 3 at least', () => {
|
|
expect(HANDLE_CAP).toBe(40)
|
|
expect(MIN_VERTICES).toBe(3)
|
|
})
|
|
})
|
|
|
|
describe('insertMidpoint', () => {
|
|
it.each([
|
|
[0, [5, 0], 1],
|
|
[2, [5, 10], 3],
|
|
// The last segment wraps to the first vertex.
|
|
[3, [0, 5], 4],
|
|
] as const)('after %i adds %j at %i', (after, middle, at) => {
|
|
const next = insertMidpoint(square, after)!
|
|
expect(next).toHaveLength(5)
|
|
expect(next[at]).toEqual(middle)
|
|
})
|
|
|
|
it('rounds the midpoint to the 0.01 grid', () => {
|
|
const odd: Point[] = [
|
|
[0, 0],
|
|
[0.015, 0.025],
|
|
[5, 5],
|
|
]
|
|
expect(insertMidpoint(odd, 0)![1]).toEqual([0.01, 0.01])
|
|
})
|
|
|
|
it.each([-1, 4, 1.5, Number.NaN])('gives null for index %s', (index) => {
|
|
expect(insertMidpoint(square, index)).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('removeVertex', () => {
|
|
it('removes the vertex at the index', () => {
|
|
expect(removeVertex(square, 1)).toEqual([
|
|
[0, 0],
|
|
[10, 10],
|
|
[0, 10],
|
|
])
|
|
})
|
|
|
|
it('gives null at 3 vertices and out of range', () => {
|
|
expect(removeVertex(square.slice(0, 3), 0)).toBeNull()
|
|
expect(removeVertex(square, 4)).toBeNull()
|
|
expect(removeVertex(square, -1)).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('moveVertex', () => {
|
|
it('moves one vertex, rounded to 0.01', () => {
|
|
const next = moveVertex(square, 2, { x: 12.345, y: 9.999 })!
|
|
expect(next[2]).toEqual([12.35, 10])
|
|
expect(next[0]).toBe(square[0])
|
|
})
|
|
|
|
it.each([
|
|
{ x: Number.NaN, y: 1 },
|
|
{ x: 1, y: Number.POSITIVE_INFINITY },
|
|
])('gives null for a non-finite place %j', (to) => {
|
|
expect(moveVertex(square, 0, to)).toBeNull()
|
|
})
|
|
|
|
it('gives null out of range', () => {
|
|
expect(moveVertex(square, 9, { x: 1, y: 1 })).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('isNoOpMove', () => {
|
|
const movedTo = (index: number, x: number, y: number) =>
|
|
moveVertex(square, index, { x, y })!
|
|
|
|
it.each([
|
|
['itself', 1, 10, 0],
|
|
['the next vertex', 1, 10, 10],
|
|
['the previous vertex', 1, 0, 0],
|
|
// Wrapping both ways.
|
|
['the previous one across the start', 0, 0, 10],
|
|
['the next one across the end', 3, 0, 0],
|
|
] as const)('a release on %s is no change', (_, index, x, y) => {
|
|
expect(isNoOpMove(square, index, movedTo(index, x, y))).toBe(true)
|
|
})
|
|
|
|
it('a release elsewhere is a change, even on a vertex that is not a neighbour', () => {
|
|
expect(isNoOpMove(square, 0, movedTo(0, 3, 3))).toBe(false)
|
|
expect(isNoOpMove(square, 0, movedTo(0, 10, 10))).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('showsInsert (R-9)', () => {
|
|
it.each([
|
|
[20, 10, true],
|
|
[19.99, 10, false],
|
|
[44, 22, true],
|
|
[43.9, 22, false],
|
|
[0, 10, false],
|
|
])('a %s px segment with a %s px hit radius: %s', (segment, hit, shown) => {
|
|
expect(showsInsert(segment, hit)).toBe(shown)
|
|
})
|
|
})
|