Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed May 23, 2024
1 parent d195d9d commit 8de58db
Show file tree
Hide file tree
Showing 26 changed files with 266 additions and 218 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Outdooractive/gis-tools",
"state" : {
"revision" : "3a72a667c557e84527be32e5fa7ff34953716868",
"version" : "1.4.0"
"revision" : "35554734fbe059660509ee9403ffa4fbfbc1051c",
"version" : "1.5.0"
}
},
{
Expand All @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ let package = Package(
targets: ["MVTTools"]),
],
dependencies: [
.package(url: "https://github.com/Outdooractive/gis-tools", from: "1.4.0"),
.package(url: "https://github.com/Outdooractive/gis-tools", from: "1.5.0"),
.package(url: "https://github.com/1024jp/GzipSwift.git", from: "5.2.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.1"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.4.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
.package(url: "https://github.com/apple/swift-protobuf", from: "1.26.0"),
],
Expand Down
12 changes: 6 additions & 6 deletions Sources/MVTCLI/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MVTTools
@main
struct CLI: AsyncParsableCommand {

static let logger: Logger = Logger(label: "mvttool")
static let logger = Logger(label: "mvttool")

static var configuration = CommandConfiguration(
commandName: "mvt",
Expand All @@ -20,7 +20,7 @@ struct CLI: AsyncParsableCommand {
struct Options: ParsableArguments {

@Flag(name: .shortAndLong, help: "Print some debug info")
var verbose: Bool = false
var verbose = false

@Option(name: .short, help: "Tile zoom level - if it can't be extracted from the path")
var z: Int?
Expand Down Expand Up @@ -90,16 +90,16 @@ struct Options: ParsableArguments {
}
}

guard let x = x,
let y = y,
let z = z
guard let x,
let y,
let z
else { throw "Need z, x and y" }

guard x >= 0 else { throw "x must be >= 0" }
guard y >= 0 else { throw "y must be >= 0" }
guard z >= 0 else { throw "z must be >= 0" }

let maximumTileCoordinate: Int = 1 << z
let maximumTileCoordinate = 1 << z
if x >= maximumTileCoordinate { throw "x at zoom \(z) must be smaller than \(maximumTileCoordinate)" }
if y >= maximumTileCoordinate { throw "y at zoom \(z) must be smaller than \(maximumTileCoordinate)" }

Expand Down
2 changes: 1 addition & 1 deletion Sources/MVTCLI/Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension CLI {
var layer: [String] = []

@Flag(name: .shortAndLong, help: "Format the output GeoJSON")
var prettyPrint: Bool = false
var prettyPrint = false

@OptionGroup
var options: Options
Expand Down
6 changes: 4 additions & 2 deletions Sources/MVTCLI/Extensions/ArrayExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import Foundation
extension Array {

var nonempty: Self? {
self.isEmpty ? nil : self
isEmpty ? nil : self
}

func get(at index: Int) -> Element? {
guard index >= -count && index < count else { return nil }
guard index >= -count,
index < count
else { return nil }

if index >= 0 {
return self[index]
Expand Down
2 changes: 1 addition & 1 deletion Sources/MVTCLI/Extensions/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension String {
options: NSRegularExpression.MatchingOptions(),
range: NSRange(startIndex..., in: self),
using: { (matchResult, flags, stop) in
guard let matchResult = matchResult else { return }
guard let matchResult else { return }

for i in 1 ..< matchResult.numberOfRanges {
if let range = Range(matchResult.range(at: i), in: self) {
Expand Down
8 changes: 4 additions & 4 deletions Sources/MVTCLI/Merge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Foundation
import MVTTools

extension CLI {

struct Merge: AsyncParsableCommand {

static var configuration = CommandConfiguration(abstract: "Merge two or more vector tiles")

@Option(name: .shortAndLong, help: "Output file")
var output: String

Expand Down Expand Up @@ -69,7 +69,7 @@ extension CLI {
simplifyFeatures: .no)
tile.write(to: outputUrl, options: exportOptions)
}

}

}
10 changes: 5 additions & 5 deletions Sources/MVTCLI/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ extension CLI {
if let partLatitude = Double(possibleCoordinateParts[0]),
let partLongitude = Double(possibleCoordinateParts[1]),
let partTolerance = Double(possibleCoordinateParts[2]),
(-90...90).contains(partLatitude),
(-180...180).contains(partLongitude),
(-90 ... 90).contains(partLatitude),
(-180 ... 180).contains(partLongitude),
partTolerance > 0.0
{
coordinate = Coordinate3D(latitude: partLatitude, longitude: partLongitude)
Expand All @@ -51,8 +51,8 @@ extension CLI {
}

var result: FeatureCollection?
if let coordinate = coordinate,
let tolerance = tolerance
if let coordinate,
let tolerance
{
if options.verbose {
print("Searching around \(coordinate), tolerance: \(tolerance)m ...")
Expand All @@ -66,7 +66,7 @@ extension CLI {
result = search(term: searchTerm, in: tile)
}

if let result = result,
if let result,
let output = result.asJsonString(prettyPrinted: true)
{
print(output, terminator: "")
Expand Down
11 changes: 7 additions & 4 deletions Sources/MVTTools/Extensions/ArrayExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ extension Array {

/// Adds a new element at the end of the array if it's not *nil*.
mutating func append(ifNotNil element: Element?) {
guard let element = element else { return }
guard let element else { return }

append(element)
}

Expand All @@ -14,9 +15,9 @@ extension Array {
func pairs() -> [(first: Element, second: Element)] {
guard !isEmpty else { return [] }

return (0 ..< (self.count / 2)).compactMap { (index) in
return (0 ..< (count / 2)).compactMap { (index) in
let i = index * 2
return (first: self[i], second: self[i+1])
return (first: self[i], second: self[i + 1])
}
}

Expand All @@ -26,7 +27,9 @@ extension Array {
///
/// - parameter index: The index in the array. May be negative. In this case, -1 will be the last element, -2 the second-to-last, and so on.
func get(at index: Int) -> Element? {
guard index >= -count && index < count else { return nil }
guard index >= -count,
index < count
else { return nil }

if index >= 0 {
return self[index]
Expand Down
2 changes: 1 addition & 1 deletion Sources/MVTTools/Extensions/DictionaryExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
extension Dictionary {

func hasKey(_ key: Key) -> Bool {
return self[key] != nil
self[key] != nil
}

}
6 changes: 3 additions & 3 deletions Sources/MVTTools/Extensions/RingExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if !os(Linux)
import CoreLocation
import CoreLocation
#endif
import GISTools

Expand All @@ -10,13 +10,13 @@ extension Ring {
/// Note: Vector tiles have a flipped y axis, so
/// clockwise/counterClockwise are reverted
var isUnprojectedClockwise: Bool {
return !isClockwise
!isClockwise
}

/// Note: Vector tiles have a flipped y axis, so
/// clockwise/counterClockwise are reverted
var isUnprojectedCounterClockwise: Bool {
return !isCounterClockwise
!isCounterClockwise
}

}
Loading

0 comments on commit 8de58db

Please sign in to comment.