-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GISTool.convertToDegrees(fromMeters:atLatitude:) (#59)
Also added GISTool.convertToCoordinate(fromPixelX:pixelY:atZoom:tileSideLength:projection:) and GISTool.metersPerPixel(atZoom:latitude:tileSideLength:) (they were in MapTile before)
- Loading branch information
Showing
5 changed files
with
127 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@testable import GISTools | ||
import XCTest | ||
|
||
final class ConversionTests: XCTestCase { | ||
|
||
func testMetersPerPixelAtEquator() { | ||
var mppAtZoomLevels: [Double] = Array(repeating: 0.0, count: 21) | ||
mppAtZoomLevels[0] = 156_543.03392804096 | ||
|
||
for zoom in 1...20 { | ||
mppAtZoomLevels[zoom] = mppAtZoomLevels[zoom - 1] / 2.0 | ||
|
||
XCTAssertEqual(GISTool.metersPerPixel(atZoom: zoom), | ||
mppAtZoomLevels[zoom], | ||
accuracy: 0.00001) | ||
} | ||
} | ||
|
||
func testMetersPerPixelAt45() { | ||
var mppAtZoomLevels: [Double] = Array(repeating: 0.0, count: 21) | ||
mppAtZoomLevels[0] = 110_692.6408380335 | ||
|
||
for zoom in 1...20 { | ||
mppAtZoomLevels[zoom] = mppAtZoomLevels[zoom - 1] / 2.0 | ||
|
||
XCTAssertEqual(GISTool.metersPerPixel(atZoom: zoom, latitude: 45.0), | ||
mppAtZoomLevels[zoom], | ||
accuracy: 0.00001) | ||
} | ||
} | ||
|
||
func testMetersAtLatitude() throws { | ||
let meters = 10000.0 | ||
let degreesLatitude1 = try XCTUnwrap(GISTool.convert(length: meters, from: .meters, to: .degrees)) | ||
let degreesLatitude2 = GISTool.convertToDegrees(fromMeters: meters, atLatitude: 0.0).latitudeDegrees | ||
|
||
XCTAssertEqual(degreesLatitude1, degreesLatitude2, accuracy: 0.00000001) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters