Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios-sdk-core
Submodule ios-sdk-core updated 41 files
+21 −0 Sources/MapConductorCore/MapCollectionItems.swift
+14 −0 Sources/MapConductorCore/MapViewContent.swift
+14 −2 Sources/MapConductorCore/circle/CircleController.swift
+22 −3 Sources/MapConductorCore/circle/CircleState.swift
+14 −2 Sources/MapConductorCore/groundimage/GroundImageController.swift
+27 −6 Sources/MapConductorCore/groundimage/GroundImageState.swift
+20 −3 Sources/MapConductorCore/marker/AbstractMarkerController.swift
+63 −1 Sources/MapConductorCore/marker/MarkerIngestionEngine.swift
+27 −5 Sources/MapConductorCore/marker/MarkerState.swift
+132 −0 Sources/MapConductorCore/overlay/OverlayAddedTracker.swift
+21 −2 Sources/MapConductorCore/overlay/OverlayStacking.swift
+23 −2 Sources/MapConductorCore/polygon/PolygonController.swift
+25 −3 Sources/MapConductorCore/polygon/PolygonState.swift
+6 −525 Sources/MapConductorCore/polygon/PolygonTileRenderer.swift
+28 −118 Sources/MapConductorCore/polygon/PolygonTileSet.swift
+25 −86 Sources/MapConductorCore/polygon/PolygonTiler.swift
+86 −8 Sources/MapConductorCore/polyline/PolylineController.swift
+54 −0 Sources/MapConductorCore/polyline/PolylineEntity.swift
+72 −10 Sources/MapConductorCore/polyline/PolylineManager.swift
+22 −3 Sources/MapConductorCore/polyline/PolylineState.swift
+119 −0 Sources/MapConductorCore/polyline/PolylineTileSet.swift
+125 −0 Sources/MapConductorCore/polyline/PolylineTiler.swift
+38 −0 Sources/MapConductorCore/polyline/PolylineTilingOptions.swift
+14 −2 Sources/MapConductorCore/raster/RasterLayerController.swift
+21 −3 Sources/MapConductorCore/raster/RasterLayerState.swift
+615 −0 Sources/MapConductorCore/shapetile/ShapeTileRenderer.swift
+184 −0 Sources/MapConductorCore/shapetile/ShapeTileSet.swift
+131 −0 Sources/MapConductorCore/shapetile/ShapeTiler.swift
+451 −0 Tests/MapConductorCoreTests/OverlayOnAddedTests.swift
+18 −0 Tests/MapConductorCoreTests/PolygonTilingInPlaceTests.swift
+146 −0 Tests/MapConductorCoreTests/PolylineHitToleranceTests.swift
+257 −0 Tests/MapConductorCoreTests/PolylineTileRendererTests.swift
+219 −0 Tests/MapConductorCoreTests/PolylineTilingInPlaceTests.swift
+193 −0 Tests/MapConductorCoreTests/PolylineTilingTests.swift
+45 −14 api/MapConductorCore.api.swift
+7 −1 docs/CircleState.swift.md
+9 −2 docs/GroundImageState.swift.md
+9 −2 docs/MarkerState.swift.md
+7 −1 docs/PolygonState.swift.md
+7 −1 docs/PolylineState.swift.md
+7 −1 docs/RasterLayerState.swift.md
117 changes: 117 additions & 0 deletions samples/MapConductorSampleApp/Benchmarks/BostonDataTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Foundation
import XCTest

@testable import MapConductorSampleApp

/// The Boston page's MCPG v2 decoding (BostonData.swift). The same fixture is
/// decoded by the React (bostonData.test.ts) and Android (BostonDataTest.kt) tests.
final class BostonDataTests: XCTestCase {
/// Two polygons with every field (fields = 15), written by the generator (the React
/// sample's tools/boston/fixture.py): the same polygons at 1e-6 and at 1e-5 degree.
private let fixture = hexData(
"4d43504702000000020000000f067c020109436166c3a920e298950204f4abb228a7b0e24300d00fd00f0000cf0f03db0bd804"
+ "d8040000a006000802000103ffea068ff40414142700"
)
private let fixture5 = hexData(
"4d43504702000000020000000f057c020109436166c3a920e298950204b284850483b8e30600c801c8010000c7010395013c3c"
+ "000050000802000103bf57e73e02020300"
)

private static func hexData(_ hex: String) -> Data {
var bytes: [UInt8] = []
var index = hex.startIndex
while index < hex.endIndex {
let next = hex.index(index, offsetBy: 2)
bytes.append(UInt8(hex[index..<next], radix: 16)!)
index = next
}
return Data(bytes)
}

private func assertRing(_ ring: [Double], _ expected: [Double], file: StaticString = #filePath, line: UInt = #line) {
XCTAssertEqual(ring.count, expected.count, file: file, line: line)
for (a, b) in zip(ring, expected) { XCTAssertEqual(a, b, accuracy: 1e-9, file: file, line: line) }
}

func testDecodesEveryFieldAndClosesEachRingAgain() throws {
try assertDecodesEveryField(fixture)
}

func testDecodesEveryFieldAt1e5Degree() throws {
try assertDecodesEveryField(fixture5)
}

private func assertDecodesEveryField(_ bytes: Data) throws {
let polygons = try BostonDataLoader.decode(bytes, idPrefix: "t")
XCTAssertEqual(polygons.count, 2)

let first = polygons[0]
XCTAssertEqual(first.id, "t-0")
XCTAssertEqual(first.height, 12.3)
XCTAssertEqual(first.use, .condo)
XCTAssertEqual(first.level, 1)
XCTAssertEqual(first.name, "Café ☕")
XCTAssertEqual(first.rings.count, 2)
assertRing(first.rings[0], [-71.0605, 42.35545, -71.0595, 42.35545, -71.0595, 42.35645, -71.0605, 42.35645, -71.0605, 42.35545])
assertRing(first.rings[1], [-71.0602, 42.3557, -71.0602, 42.356, -71.0598, 42.356, -71.0602, 42.3557])

let second = polygons[1]
XCTAssertEqual(second.id, "t-1")
XCTAssertNil(second.height)
XCTAssertEqual(second.use, .unknown)
XCTAssertEqual(second.level, 2)
XCTAssertNil(second.name)
assertRing(second.rings[0], [-71.1, 42.3, -71.09999, 42.30001, -71.09999, 42.29999, -71.1, 42.3])
}

func testRejectsAVersion1File() {
var v1 = fixture
v1[4] = 1
XCTAssertThrowsError(try BostonDataLoader.decode(v1, idPrefix: "t"))
}

func testTheBundledDowntownFileHasEveryBuildingOfTheThreeAreas() throws {
let url = try XCTUnwrap(Bundle.main.url(forResource: "boston-downtown", withExtension: "bin"))
let polygons = try BostonDataLoader.decode(Data(contentsOf: url), idPrefix: "downtown")
XCTAssertEqual(polygons.count, 9467)
XCTAssertEqual(polygons.reduce(0) { $0 + $1.vertexCount }, 73289)
XCTAssertEqual(polygons.reduce(0) { $0 + $1.rings.count }, 9504)
XCTAssertEqual(Dictionary(grouping: polygons, by: \.level).mapValues(\.count), [0: 605, 1: 2222, 2: 6640])
XCTAssertEqual(polygons.filter { $0.height == nil }.count, 362)
XCTAssertEqual(polygons.filter { $0.name != nil }.count, 762)
XCTAssertEqual(Set(polygons.map(\.id)).count, 9467)
let first = try XCTUnwrap(polygons.first)
XCTAssertEqual(first.height, 5.2)
XCTAssertEqual(first.level, 2)
assertRing(Array(first.rings[0][0..<2]), [-71.076105, 42.373684])
assertRing(Array(first.rings[0][16..<18]), [-71.076105, 42.373684])
}

func testTheBundledCityBuildingsFileHasEveryBuildingAt1e6Degree() throws {
let url = try XCTUnwrap(Bundle.main.url(forResource: "boston-city-buildings", withExtension: "bin"))
let bytes = try Data(contentsOf: url)
XCTAssertEqual(bytes[13], 6)
let polygons = try BostonDataLoader.decode(bytes, idPrefix: "buildings")
XCTAssertEqual(polygons.count, 105_599)
XCTAssertEqual(polygons.reduce(0) { $0 + $1.vertexCount }, 722_875)
}

func testTheBundledCityParcelsFileHasEveryParcelWithALandUseAt1e5Degree() throws {
let url = try XCTUnwrap(Bundle.main.url(forResource: "boston-city-parcels", withExtension: "bin"))
let bytes = try Data(contentsOf: url)
XCTAssertEqual(bytes[13], 5)
let polygons = try BostonDataLoader.decode(bytes, idPrefix: "parcels")
XCTAssertEqual(polygons.count, 98_815)
XCTAssertEqual(polygons.reduce(0) { $0 + $1.vertexCount }, 774_844)
XCTAssertTrue(polygons.allSatisfy { $0.use != nil && $0.rings.allSatisfy { $0.count >= 8 } })
}

func testAreaIsTheOutlineLessItsHoles() throws {
let polygon = try BostonDataLoader.decode(fixture, idPrefix: "t")[0]
let outline = BostonBuilding(id: "o", level: 0, height: nil, name: nil, use: nil, rings: [polygon.rings[0]])
let hole = BostonBuilding(id: "h", level: 0, height: nil, name: nil, use: nil, rings: [polygon.rings[1]])
XCTAssertEqual(polygon.areaSquareMetres, outline.areaSquareMetres - hole.areaSquareMetres, accuracy: 1e-6)
// About 82 m x 111 m.
XCTAssertEqual(outline.areaSquareMetres, 9100, accuracy: 100)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import Foundation
import XCTest

@testable import MapConductorSampleApp

/// The Boston roads page's decoding (MCPG v2 with the road class and lines bits,
/// BostonRoadsData.swift). The same fixture is decoded by the React and Android tests
/// (written by the React sample's tools/boston/fixture.py).
final class BostonRoadsDataTests: XCTestCase {
/// Two roads, fields = name | road class | lines, 1e-5 degree: a multi-byte name,
/// an open three-point path, and a nameless two-point path stepping back south-west.
private let fixture = hexData(
"4d4350470200000002000000380510436166c3a92053747265657420e29895010103b284850483b8e30614140a2800060102ef56973e1313"
)

private static func hexData(_ hex: String) -> Data {
var bytes: [UInt8] = []
var index = hex.startIndex
while index < hex.endIndex {
let next = hex.index(index, offsetBy: 2)
bytes.append(UInt8(hex[index..<next], radix: 16)!)
index = next
}
return Data(bytes)
}

private func assertPoints(_ points: [Double], _ expected: [Double], file: StaticString = #filePath, line: UInt = #line) {
XCTAssertEqual(points.count, expected.count, file: file, line: line)
for (a, b) in zip(points, expected) { XCTAssertEqual(a, b, accuracy: 1e-9, file: file, line: line) }
}

func testDecodesTheRoadsWithoutClosingThem() throws {
let roads = try BostonRoadsLoader.decode(fixture)
XCTAssertEqual(roads.count, 2)

let first = roads[0]
XCTAssertEqual(first.id, "roads-0")
XCTAssertEqual(first.name, "Café Street ☕")
XCTAssertEqual(first.road, .primary)
assertPoints(first.points, [-71.0605, 42.35545, -71.0604, 42.35555, -71.0602, 42.3556])

let second = roads[1]
XCTAssertEqual(second.id, "roads-1")
XCTAssertNil(second.name)
XCTAssertEqual(second.road, .path)
assertPoints(second.points, [-71.1, 42.3, -71.1001, 42.2999])
}

func testAPolygonFileIsNotRoads() {
var polygons = fixture
polygons[12] = 8 | 16 // the lines bit off
XCTAssertThrowsError(try BostonRoadsLoader.decode(polygons))
}

func testTheLengthIsTheGeodesicSumOfTheSegments() throws {
let road = try BostonRoadsLoader.decode(fixture)[0]
// About 13.7 m + 17.4 m.
XCTAssertEqual(road.lengthMetres, 31.1, accuracy: 0.5)
}

func testClassesAreStyledBiggerRoadsWiderAndHigher() {
XCTAssertEqual(RoadClass.allCases.map(\.width), [5, 4, 3.5, 3, 2, 1.5, 1])
XCTAssertEqual(RoadClass.allCases.map(\.zIndex), [6, 5, 4, 3, 2, 1, 0])
}

func testTheBundledFileHasEveryRoadOfTheCity() throws {
let url = try XCTUnwrap(Bundle.main.url(forResource: "boston-city-roads", withExtension: "bin"))
let bytes = try Data(contentsOf: url)
XCTAssertEqual(bytes.count, 1_019_811)
XCTAssertEqual(bytes[13], 5)
let roads = try BostonRoadsLoader.decode(bytes)
XCTAssertEqual(roads.count, 54_645)
XCTAssertEqual(roads.reduce(0) { $0 + $1.vertexCount }, 234_765)
XCTAssertEqual(roads.filter { $0.name != nil }.count, 18_838)
let byClass = Dictionary(grouping: roads, by: \.road).mapValues(\.count)
XCTAssertEqual(byClass, [
.highway: 911, .primary: 2_320, .secondary: 2_829, .tertiary: 1_229,
.local: 11_226, .service: 9_950, .path: 26_180,
])
XCTAssertEqual(roads[0].name, "Saint Vincent Section")
XCTAssertEqual(roads[0].road, .service)
XCTAssertEqual(roads[0].vertexCount, 9)
assertPoints(Array(roads[0].points[0..<2]), [-71.1858, 42.28788])
}
}
Loading