Skip to content
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

Various bug fixes for LineString.simplify and Polygon.simplify #152

Merged
merged 5 commits into from
Sep 24, 2021

Conversation

nighthawk
Copy link
Contributor

This branch fixes these issues introduced in the port of turf-simplify from #138:

  • LineString.simplify with highestQuality = false was broken as it was using start.coordinate in one formula when it should have used coordinate
  • Polygon.simplify ignored highestQuality = false as it first assigned the self.coordinates to a local variable, then simplified the self.coordinates, but then passed the previous local variable to the Douglas-Peucker algorithm. That means it always returned results as if highestQuality = true was set.
  • Polygon.simplify forgot to square the tolerance to the Douglas-Peucker algorithm (LineString.simplify did it correctly)
  • Polygon.simplify didn't simplify if any of the exterior/interior polygons was a triangle; now it just skips simplification of the triangle but simplifies the others.

I've also refactored the code to remove the code duplication between LineString.swift and Polygon.swift, and ported the turf-simplify test suite using the in/out directory -- excluding the test cases for MultiLineString and MultiPolygon as they aren't supported yet.

Fixes these bugs, too:
- Polygon's simplify method didn't square the tolerance parameter when it should have
- Polygon's 'highestQuality = false' didn't work at all(!)
Also removes hard-coded test which had wrong values
Also fix compiling using .xcodeproj file
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Putting the test fixtures in JSON instead of inline feels a lot cleaner.

}
}

func XCTAssertEqual(_ expected: [[LocationCoordinate2D]], _ actual: [[LocationCoordinate2D]], accuracy: CLLocationDegrees, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the Bitrise builds are failing because #filePath requires Swift 5.3, which is in Xcode 12. The readme currently states a minimum requirement of Xcode 9, but this would be a good opportunity to increase the requirement to 12.

@@ -0,0 +1,109 @@
import Foundation

enum Simplifier {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting use of an enumeration as an effective namespace, rather than a struct that’s more commonly used for this purpose but comes with initializers. This pattern might be worth following elsewhere in the codebase.

@1ec5 1ec5 added this to the v2.0.0 (GA) milestone Sep 24, 2021
@1ec5 1ec5 added bug op-ex Refactoring, Tech Debt or any other operational excellence work. labels Sep 24, 2021
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are passing now that I’ve upgraded the tvOS Bitrise application to Xcode 12.5.

@1ec5 1ec5 merged commit 618899f into mapbox:main Sep 24, 2021
@1ec5
Copy link
Contributor

1ec5 commented Sep 24, 2021

6ecf55b updates the readme to require Xcode 12.0.

@1ec5
Copy link
Contributor

1ec5 commented Sep 28, 2021

c120ea5 adds the test fixtures to the Xcode project for Carthage-based builds.

@nighthawk nighthawk deleted the fix-simplify branch October 15, 2021 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug op-ex Refactoring, Tech Debt or any other operational excellence work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants