Skip to content

Commit b7be9b4

Browse files
committed
refactor(ios): plot the quarter-turn test through the shared rect predicate
`SnapshotGeometrySpace.isPlottable` and `SnapshotGeometry.isPositiveFinite` were the same five comparisons, written twice in one package, which is how #2891 started: one question with two encodings that can drift apart. `.null`, an inverted box, and an infinite box are refused identically by both, so the coordinate-space table needs no new rows.
1 parent 28f7cb8 commit b7be9b4

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotCoordinateSpace.swift‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,16 @@ public enum SnapshotGeometrySpace: Equatable {
145145
}
146146

147147
private static func isQuarterTurned(_ frame: CGRect, relativeTo appFrame: CGRect) -> Bool {
148-
guard isPlottable(frame), isPlottable(appFrame),
148+
// The quarter-turn test asks the same question the `hittable` predicate asks before it computes a
149+
// center: is this a box that can be plotted at all. It is one predicate, not two that can drift.
150+
guard SnapshotGeometry.isPositiveFinite(frame), SnapshotGeometry.isPositiveFinite(appFrame),
149151
abs(appFrame.width - appFrame.height) > quarterTurnTolerance
150152
else {
151153
return false
152154
}
153155
return abs(frame.width - appFrame.height) <= quarterTurnTolerance
154156
&& abs(frame.height - appFrame.width) <= quarterTurnTolerance
155157
}
156-
157-
private static func isPlottable(_ frame: CGRect) -> Bool {
158-
frame.origin.x.isFinite && frame.origin.y.isFinite
159-
&& frame.width.isFinite && frame.height.isFinite
160-
&& frame.width > 0 && frame.height > 0
161-
}
162158
}
163159

164160
extension SnapshotGeometrySpace {
@@ -169,8 +165,8 @@ extension SnapshotGeometrySpace {
169165
) -> [RawAXNode] {
170166
let carriers = SnapshotVisibilityFold.visibilityExemptCarrierTypes
171167
// No viewport box means no app frame to be quarter-turned relative to either. `.null` is the box
172-
// `isPlottable` refuses, so this pass turns nothing — the outcome `CGRect.infinite` produced
173-
// before the fact carried the absence.
168+
// `SnapshotGeometry.isPositiveFinite` refuses, so this pass turns nothing — the outcome
169+
// `CGRect.infinite` produced before the fact carried the absence.
174170
let appFrame = viewport.rect ?? .null
175171
var spaces = [SnapshotGeometrySpace](repeating: .appOrientation, count: nodes.count)
176172
var result: [RawAXNode] = []

0 commit comments

Comments
 (0)