Commit 44a08ad62a

44a08ad62a213299c91fce8143155e6ff27efed1

parent: f96de825e7

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-23 02:17 UTC

Drag the UI tests through a step's turns

The UI drag helper stops at a fold-and-unfold's peak and at a non-rigid
step's phase boundaries wherever the path turns back there, carries the
drag 6 points past, and starts a drag whose point lies outside the paper
view at the view's centre, since the app reads only the translation. The
audit now walks every step of all four models.

Closes #7

Layout: unified · split

App/UITests/FoldGestureTests.swift +31 −29
@@ -31,10 +31,13 @@ func completeCurrentFold(_ app: XCUIApplication) {
31 31
32/// Drags the current step's moving faces along their path, read from `fold.path` (the app must be 32/// Drags the current step's moving faces along their path, read from `fold.path` (the app must be
33/// launched with `-UITesting`), to `fraction` of it, then lifts. Each drag is one straight 33/// launched with `-UITesting`), to `fraction` of it, then lifts. Each drag is one straight
34/// press-and-drag through every 32nd sample, and a fold-and-unfold's peak, with short ones merged 34/// press-and-drag through every 32nd sample and every turn, with short ones merged so each moves
35/// so each moves at least `minimumChord` points: a DragGesture does not begin under 10. A drag to 35/// at least `minimumChord` points: a DragGesture does not begin under 10. A turn is where the path
36/// the peak continues 8 points past it, and a drag to the end 30. Each holds before lifting, so its 36/// goes back the way it came, at a fold-and-unfold's peak or at a non-rigid step's phase
37/// last position arrives before the lift. 37/// boundaries (t = ⅓ and ⅔); a drag to a turn continues 6 points past it, since the drag after it
38/// starts back along the way it came, and a drag to the end continues 30 points past it. The app
39/// reads only a drag's translation, so a drag from a point outside the paper view starts at its
40/// centre instead. Each holds before lifting, so its last position arrives before the lift.
38func dragCurrentFold(_ app: XCUIApplication, to fraction: Double) { 41func dragCurrentFold(_ app: XCUIApplication, to fraction: Double) {
39 let paper = app.otherElements["fold.paper"] 42 let paper = app.otherElements["fold.paper"]
40 let marker = app.descendants(matching: .any)["fold.path"] 43 let marker = app.descendants(matching: .any)["fold.path"]
@@ -49,37 +52,36 @@ func dragCurrentFold(_ app: XCUIApplication, to fraction: Double) {
49 CGVector(dx: (samples[b].dx - samples[a].dx) * size.width, dy: (samples[b].dy - samples[a].dy) * size.height) 52 CGVector(dx: (samples[b].dx - samples[a].dx) * size.width, dy: (samples[b].dy - samples[a].dy) * size.height)
50 } 53 }
51 func length(_ v: CGVector) -> Double { (v.dx * v.dx + v.dy * v.dy).squareRoot() } 54 func length(_ v: CGVector) -> Double { (v.dx * v.dx + v.dy * v.dy).squareRoot() }
55 func dot(_ u: CGVector, _ v: CGVector) -> Double { u.dx * v.dx + u.dy * v.dy }
52 let last = Int((fraction * Double(samples.count - 1)).rounded()) 56 let last = Int((fraction * Double(samples.count - 1)).rounded())
53 // a fold-and-unfold turns back at its peak, the sample farthest from the start; the drag that 57
54 // reaches it carries on past it, since the drag after it starts back down the way it came 58 // a turn: the path arrives along one direction and leaves against it; its sample is the one
55 let peak = stepKind(app) == "foldAndUnfold" && last > 1 59 // furthest along the arrival within two of the boundary's
56 ? (1..<last).max { length(chord(0, $0)) < length(chord(0, $1)) } : nil 60 let boundaries = stepKind(app) == "foldAndUnfold" ? [64] : [43, 85]
61 var turns: [Int] = []
62 for c in boundaries where c + 2 < last {
63 let arriving = chord(c - 8, c), leaving = chord(c, min(c + 24, last))
64 guard length(arriving) > 2, length(leaving) > 2, dot(arriving, leaving) < 0 else { continue }
65 turns.append(((c - 2)...(c + 2)).max { dot(chord(0, $0), arriving) < dot(chord(0, $1), arriving) }!)
66 }
57 var stops = [0] 67 var stops = [0]
58 for i in (Array(stride(from: 32, through: last, by: 32)) + (peak.map { [$0] } ?? [])).sorted() 68 let regular = stride(from: 32, to: last, by: 32).filter { i in !turns.contains { abs($0 - i) < 8 } }
59 where i == peak || (length(chord(stops.last!, i)) >= minimumChord && abs(i - (peak ?? -99)) >= 8) { 69 for i in (regular + turns + [last]).sorted() {
60 if i == peak { 70 if !turns.contains(i) && i != last && length(chord(stops.last!, i)) < minimumChord { continue }
61 while stops.count > 1 && length(chord(stops.last!, i)) < minimumChord { stops.removeLast() } 71 while stops.count > 1 && !turns.contains(stops.last!) && length(chord(stops.last!, i)) < minimumChord {
72 stops.removeLast()
62 } 73 }
63 stops.append(i) 74 stops.append(i)
64 } 75 }
65 if stops.last != last { 76
66 if stops.count > 1 && length(chord(stops.last!, last)) < minimumChord {
67 stops[stops.count - 1] = last
68 } else {
69 stops.append(last)
70 }
71 }
72 for (a, b) in zip(stops, stops.dropFirst()) { 77 for (a, b) in zip(stops, stops.dropFirst()) {
73 var end = paper.coordinate(withNormalizedOffset: samples[b]) 78 var move = chord(a, b)
74 if b == samples.count - 1 { 79 let l = max(length(move), 1), past = b == samples.count - 1 ? 30.0 : turns.contains(b) ? 6.0 : 0.0
75 let d = chord(a, b), l = max(length(d), 1) 80 move = CGVector(dx: move.dx + move.dx / l * past, dy: move.dy + move.dy / l * past)
76 end = end.withOffset(CGVector(dx: d.dx / l * 30, dy: d.dy / l * 30)) 81 let inside = (0.02...0.98).contains(samples[a].dx) && (0.02...0.98).contains(samples[a].dy)
77 } else if b == peak { 82 let start = paper.coordinate(withNormalizedOffset: inside ? samples[a] : CGVector(dx: 0.5, dy: 0.5))
78 let d = chord(a, b), l = max(length(d), 1) 83 start.press(forDuration: 0.1, thenDragTo: start.withOffset(move), withVelocity: .default,
79 end = end.withOffset(CGVector(dx: d.dx / l * 8, dy: d.dy / l * 8)) 84 thenHoldForDuration: 0.3)
80 }
81 paper.coordinate(withNormalizedOffset: samples[a])
82 .press(forDuration: 0.1, thenDragTo: end, withVelocity: .default, thenHoldForDuration: 0.3)
83 } 85 }
84} 86}
85 87
docs/authoring/crane.md +2 −2
@@ -141,8 +141,8 @@ For the drag, at each step's authored viewpoint:
141 141
142- the neck's and the tail's pops move a covering axis's centroid at least 8 points on screen, 142- the neck's and the tail's pops move a covering axis's centroid at least 8 points on screen,
143 so the drag follows them; 143 so the drag follows them;
144- the head's pop moves less, so its segment is the straight line down, at most half the paper 144- the head's pop moves less, so its segment is the straight line down, 160 points per unit of t
145 view's height for the pop (R81). 145 or half the paper view's height if that is less (R81).
146 146
147## Layer-order overrides 147## Layer-order overrides
148 148