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