-
Notifications
You must be signed in to change notification settings - Fork 31
Clean up some compiler warnings #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,7 +136,7 @@ extension Array where Element == CLLocation { | |
| extension CLLocationCoordinate2D { | ||
|
|
||
| var isValidLocationCoordinate: Bool { | ||
| return CLLocationCoordinate2DIsValid(self) && self != CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0) | ||
| return CLLocationCoordinate2DIsValid(self) && !self.isNear(to: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)) | ||
| } | ||
|
|
||
| func distance(from coordinate: CLLocationCoordinate2D) -> CLLocationDistance { | ||
|
|
@@ -165,7 +165,7 @@ extension CLLocationCoordinate2D { | |
| } | ||
|
|
||
| // Check if the coordinates are the same | ||
| guard self != coordinate else { | ||
| guard !self .isNear(to: coordinate )else { | ||
|
||
| return 0 | ||
| } | ||
|
|
||
|
|
@@ -221,14 +221,18 @@ extension CLLocationCoordinate2D { | |
|
|
||
| } | ||
|
|
||
| extension CLLocationCoordinate2D: Equatable { | ||
| public static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool { | ||
| return lhs.equalTo(coordinate: rhs, threshold: 0.0000009) | ||
| } | ||
| extension CLLocationCoordinate2D { | ||
|
|
||
| private func equalTo(coordinate: CLLocationCoordinate2D, threshold: CLLocationDegrees) -> Bool { | ||
| public func isNear(to coordinate: CLLocationCoordinate2D, threshold: CLLocationDegrees = 0.0000009) -> Bool { | ||
| return fabs(self.latitude - coordinate.latitude) <= threshold && fabs(self.longitude - coordinate.longitude) <= threshold | ||
| } | ||
|
|
||
| public func isNear(to coordinate: CLLocationCoordinate2D?, threshold: CLLocationDegrees = 0.0000009) -> Bool { | ||
| guard let coordinate = coordinate else { | ||
| return false | ||
| } | ||
| return isNear(to: coordinate, threshold: threshold) | ||
| } | ||
| } | ||
|
|
||
| extension CLLocationCoordinate2D: CustomStringConvertible { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ extension MKMapView { | |
| } | ||
|
|
||
| private func showAnnotationAndCenter(_ annotation: MKAnnotation) { | ||
| guard centerCoordinate != annotation.coordinate else { | ||
| guard !centerCoordinate.isNear(to: annotation.coordinate )else { | ||
|
||
| // no-op | ||
| return | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,7 @@ struct IntersectionFinder { | |||||||||||||||||||||
| road: Road, | ||||||||||||||||||||||
| preferMainIntersections: Bool = false, | ||||||||||||||||||||||
| secondaryRoadsContext: SecondaryRoadsContext = .standard) { | ||||||||||||||||||||||
| guard let roadCoordinates = road.coordinates, roadCoordinates.contains(rootCoordinate) else { | ||||||||||||||||||||||
| guard let roadCoordinates = road.coordinates, roadCoordinates.contains(where: {rootCoordinate.isNear(to: $0)}) else { | ||||||||||||||||||||||
| return nil | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -195,10 +195,10 @@ struct IntersectionFinder { | |||||||||||||||||||||
| coordinatesFromRoot : | ||||||||||||||||||||||
| (trailingCoordinates + coordinatesFromRoot.dropFirst()) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| guard let endpointIntersection = intersections.first(where: { $0.coordinate == lastCoordinate }) else { | ||||||||||||||||||||||
| guard let endpointIntersection = intersections.first(where: { $0.coordinate.isNear(to: lastCoordinate) }) else { | ||||||||||||||||||||||
| // Reached the end of the road | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if road.intersections.contains(where: { $0.coordinate == lastCoordinate }) { | ||||||||||||||||||||||
| if road.intersections.contains(where: { $0.coordinate.isNear(to: lastCoordinate) }) { | ||||||||||||||||||||||
| // Don't synthesize an intersection here since we already filtered this intersection out | ||||||||||||||||||||||
| return nil | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -300,7 +300,7 @@ struct IntersectionFinder { | |||||||||||||||||||||
| // If so, reverse the direction of calculation | ||||||||||||||||||||||
| // note: We want the first adjacent road coordinate to be the same as the last coordinate of the root road | ||||||||||||||||||||||
| guard let lastAdjacentRoadCoordinate = nextRoadSegmentCoordinates.last else { return nil } | ||||||||||||||||||||||
| let reversedDirection = (rootCoordinate == lastAdjacentRoadCoordinate) | ||||||||||||||||||||||
| let reversedDirection = rootCoordinate.isNear(to: lastAdjacentRoadCoordinate) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if let adjacentRoadClosestIntersection = closestIntersection(fromCoordinate: rootCoordinate, | ||||||||||||||||||||||
| onRoad: nextRoadSegment, | ||||||||||||||||||||||
|
|
@@ -336,7 +336,7 @@ struct IntersectionFinder { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for (i, coordinate) in roadCoordinates.enumerated() { | ||||||||||||||||||||||
| if let intersection = intersections.first(where: { $0.coordinate == coordinate }) { | ||||||||||||||||||||||
| if let intersection = intersections.first(where: { $0.coordinate.isNear(to: coordinate) }) { | ||||||||||||||||||||||
| let similarIntersectionWithMaxRoads = Intersection.similarIntersectionWithMaxRoads(intersection: intersection, intersections: intersections) | ||||||||||||||||||||||
| return (similarIntersectionWithMaxRoads, i) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -395,7 +395,7 @@ struct IntersectionFinder { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if IntersectionFinder.roadContainsCycle(road: nextRoadSegment, to: trailingCoordinates) { | ||||||||||||||||||||||
| if intersection.coordinate == self.rootCoordinate { | ||||||||||||||||||||||
| if intersection.coordinate.isNear(to: self.rootCoordinate) { | ||||||||||||||||||||||
| // If the road loops back to the root coordinate, no need to return an intersection. | ||||||||||||||||||||||
| return nil | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
|
|
@@ -412,7 +412,7 @@ struct IntersectionFinder { | |||||||||||||||||||||
| // If so, reverse the direction of calculation | ||||||||||||||||||||||
| // note: We want the first adjacent road coordinate to be the same as the last coordinate of the root road | ||||||||||||||||||||||
| guard let lastAdjacentRoadCoordinate = nextRoadSegmentCoordinates.last else { return nil } | ||||||||||||||||||||||
| let reversedDirection = (lastCoordinate == lastAdjacentRoadCoordinate) | ||||||||||||||||||||||
| let reversedDirection = lastCoordinate .isNear(to: lastAdjacentRoadCoordinate) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return lastIntersection(fromCoordinate: lastCoordinate, | ||||||||||||||||||||||
| onRoad: nextRoadSegment, | ||||||||||||||||||||||
|
|
@@ -429,7 +429,8 @@ struct IntersectionFinder { | |||||||||||||||||||||
| guard let roadCoordinates = road.coordinates else { return false } | ||||||||||||||||||||||
| guard let lastCoordinate = coordinates.last else { return false } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if roadCoordinates.first == lastCoordinate && roadCoordinates.last == lastCoordinate { | ||||||||||||||||||||||
| if lastCoordinate.isNear(to: roadCoordinates.first) && | ||||||||||||||||||||||
| lastCoordinate.isNear(to: roadCoordinates.last) { | ||||||||||||||||||||||
| // The road starts and ends at the same coordinate (loops back) | ||||||||||||||||||||||
| return true | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -439,15 +440,17 @@ struct IntersectionFinder { | |||||||||||||||||||||
| var coordinatesExcludingRoot: [CLLocationCoordinate2D] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Because of road segments direction, we check if the root coordinate is the first or last. | ||||||||||||||||||||||
| if roadCoordinates.first == lastCoordinate { | ||||||||||||||||||||||
| if lastCoordinate.isNear(to: roadCoordinates.first) { | ||||||||||||||||||||||
| coordinatesExcludingRoot = Array(roadCoordinates.dropFirst()) | ||||||||||||||||||||||
| } else if roadCoordinates.last == lastCoordinate { | ||||||||||||||||||||||
| } else if lastCoordinate.isNear(to: roadCoordinates.last) { | ||||||||||||||||||||||
| coordinatesExcludingRoot = roadCoordinates.dropLast() | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| return false | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if coordinatesExcludingRoot.contains(where: { coordinates.contains($0) }) { | ||||||||||||||||||||||
| if coordinatesExcludingRoot.contains(where: {coordinate in | ||||||||||||||||||||||
| coordinates.contains(where: {coordinate.isNear(to: $0)}) | ||||||||||||||||||||||
| }) { | ||||||||||||||||||||||
| return true | ||||||||||||||||||||||
|
Comment on lines
+451
to
454
|
||||||||||||||||||||||
| if coordinatesExcludingRoot.contains(where: {coordinate in | |
| coordinates.contains(where: {coordinate.isNear(to: $0)}) | |
| }) { | |
| return true | |
| for roadCoordinate in coordinatesExcludingRoot { | |
| for trailCoordinate in coordinates { | |
| if roadCoordinate.isNear(to: trailCoordinate) { | |
| return true | |
| } | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ class BeaconTitleViewController: UIViewController { | |
|
|
||
| // If the selected location on the underlying entity has changed, reconfigure the view | ||
| // to show the new distance | ||
| let beaconCoordinateDidChange = newValue?.locationDetail.location.coordinate != oldValue?.locationDetail.location.coordinate | ||
| let beaconCoordinateDidChange = !(newValue?.locationDetail.location.coordinate.isNear(to: oldValue?.locationDetail.location.coordinate) ?? false) | ||
|
||
|
|
||
| // If the underlying entity has changed, reconfigure the view and the view's accessibility | ||
| // actions | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid shipping a dummy enum case; make it debug‑only or remove via explicit allCases.
Keeping
placeholderin a CaseIterable enum risks showing a bogus “experiment” in any UI/logic that iteratesKnownExperiment.allCases. Also the// TODOtrips SwiftLint. Prefer either: (A) gate the placeholder behind#if DEBUGand give it a stable UUID; or (B) remove the placeholder and implementallCasesas[]until real experiments exist.Option A (debug‑only placeholder, stable UUID, no TODO):
enum KnownExperiment: CaseIterable { @@ - case placeholder // TODO: Replace with real experiments + #if DEBUG + /// Debug-only placeholder to keep CaseIterable non-empty during development. + case placeholder + #endif @@ - var uuid: UUID { - /* - switch self { - case someExperiment: return "Experiment UUID" - } - */ - - // Return a UUID for each known experiment - return UUID() - } + var uuid: UUID { + switch self { + #if DEBUG + case .placeholder: + // Stable value to avoid churn in persisted state or lookups. + return UUID(uuidString: "00000000-0000-0000-0000-000000000000")! + #endif + } + }Option B (no placeholder; explicit empty cases):
📝 Committable suggestion
🧰 Tools
🪛 SwiftLint (0.57.0)
[Warning] 17-17: TODOs should be resolved (Replace with real experiments)
(todo)
🤖 Prompt for AI Agents