Repository navigation
fix: simplify tolerance conversion using longitude instead of latitude #253
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -345,4 +345,35 @@ struct SimplifyTests { | |||||||||||||||||||||||
| #expect(result.projection == .epsg4326) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // MARK: - Tolerance conversion | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Validates that the metre-to-degree tolerance conversion depends on the | ||||||||||||||||||||||||
| // latitude, not on the longitude, of the geometry (regression test). | ||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||
| func toleranceConversionIsIndependentOfLongitude() throws { | ||||||||||||||||||||||||
| // A zigzag line with 100 points spread over a few kilometres. | ||||||||||||||||||||||||
| func zigzag(longitude: Double) throws -> LineString { | ||||||||||||||||||||||||
| let coordinates = (0 ..< 100).map { i in | ||||||||||||||||||||||||
| Coordinate3D( | ||||||||||||||||||||||||
| latitude: 40.0 + (Double(i) * 0.0005), | ||||||||||||||||||||||||
| longitude: longitude + (i.isMultiple(of: 2) ? 0.0 : 0.001)) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return try #require(LineString(coordinates)) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let atGreenwich = try zigzag(longitude: 0.0) | ||||||||||||||||||||||||
| let atMinus90 = try zigzag(longitude: -90.0) | ||||||||||||||||||||||||
| let atMinus111 = try zigzag(longitude: -111.0) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let simplifiedAtGreenwich = atGreenwich.simplified(tolerance: 10.0) | ||||||||||||||||||||||||
| let simplifiedAtMinus90 = atMinus90.simplified(tolerance: 10.0) | ||||||||||||||||||||||||
| let simplifiedAtMinus111 = atMinus111.simplified(tolerance: 10.0) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // The zigzag amplitude (~85m) is far above the tolerance, so most | ||||||||||||||||||||||||
| // vertices must survive regardless of the meridian. | ||||||||||||||||||||||||
| #expect(simplifiedAtGreenwich.coordinates.count > 50) | ||||||||||||||||||||||||
| #expect(simplifiedAtMinus90.coordinates.count == simplifiedAtGreenwich.coordinates.count) | ||||||||||||||||||||||||
| #expect(simplifiedAtMinus111.coordinates.count == simplifiedAtGreenwich.coordinates.count) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: bug fixes should include tests for all affected projections. The degree conversion only runs on the geographic branch, so one cheap planar assertion in the new test is enough (keeps the regression test self-contained; broader coverage already exists in
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
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.
Non-blocking, optional: this now duplicates the conversion that already exists as
Coordinate3D.degrees(fromMeters:)(Sources/GISTools/Algorithms/Conversions.swift). Suggested change below reuses it.Note that this also swaps the hardcoded
111.0km/degree forGISTool.earthCircumference / 360.0(~111.32 km/degree), i.e. it is slightly more accurate but does change results marginally. Entirely reasonable to defer this refactor to a follow-up if you want this PR strictly minimal.