Skip to content

Commit 97f9de1

Browse files
refactor: Expands Coord property names
1 parent c8d09f2 commit 97f9de1

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

Sources/Haystack/Coord.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import Foundation
88
public struct Coord: Val {
99
public static var valType: ValType { .Coord }
1010

11-
public let lat: Double
12-
public let lng: Double
11+
public let latitude: Double
12+
public let longitude: Double
1313

14-
public init(lat: Double, lng: Double) throws {
15-
guard -90 <= lat, lat <= 90, -180 <= lng, lng <= 180 else {
16-
throw CoordError.invalidCoordinates(lat: lat, lng: lng)
14+
public init(latitude: Double, longitude: Double) throws {
15+
guard -90 <= latitude, latitude <= 90, -180 <= longitude, longitude <= 180 else {
16+
throw CoordError.invalidCoordinates(lat: latitude, lng: longitude)
1717
}
18-
self.lat = lat
19-
self.lng = lng
18+
self.latitude = latitude
19+
self.longitude = longitude
2020
}
2121

2222
public func toZinc() -> String {
23-
return "C(\(lat),\(lng))"
23+
return "C(\(latitude),\(longitude))"
2424
}
2525
}
2626

@@ -47,8 +47,8 @@ extension Coord: Codable {
4747
}
4848

4949
try self.init(
50-
lat: container.decode(Double.self, forKey: .lat),
51-
lng: container.decode(Double.self, forKey: .lng)
50+
latitude: container.decode(Double.self, forKey: .lat),
51+
longitude: container.decode(Double.self, forKey: .lng)
5252
)
5353
} else {
5454
throw DecodingError.typeMismatch(
@@ -64,8 +64,8 @@ extension Coord: Codable {
6464
public func encode(to encoder: Encoder) throws {
6565
var container = encoder.container(keyedBy: Self.CodingKeys)
6666
try container.encode(Self.kindValue, forKey: ._kind)
67-
try container.encode(lat, forKey: .lat)
68-
try container.encode(lng, forKey: .lng)
67+
try container.encode(latitude, forKey: .lat)
68+
try container.encode(longitude, forKey: .lng)
6969
}
7070
}
7171

Sources/Haystack/IO/ZincReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class ZincReader {
104104
try consume(.comma)
105105
let longitude = try consumeNumber()
106106
try consume(.rparen)
107-
return try Coord(lat: latitude.val, lng: longitude.val)
107+
return try Coord(latitude: latitude.val, longitude: longitude.val)
108108
}
109109

110110
private func parseXStr(_ id: String) throws -> XStr {

Tests/HaystackTests/CoordTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import Haystack
33

44
final class CoordTests: XCTestCase {
55
func testInit() throws {
6-
try XCTAssertThrowsError(Coord(lat: -91, lng: 0))
7-
try XCTAssertThrowsError(Coord(lat: 91, lng: 0))
8-
try XCTAssertThrowsError(Coord(lat: 0, lng: -181))
9-
try XCTAssertThrowsError(Coord(lat: 0, lng: 181))
6+
try XCTAssertThrowsError(Coord(latitude: -91, longitude: 0))
7+
try XCTAssertThrowsError(Coord(latitude: 91, longitude: 0))
8+
try XCTAssertThrowsError(Coord(latitude: 0, longitude: -181))
9+
try XCTAssertThrowsError(Coord(latitude: 0, longitude: 181))
1010
}
1111

1212
func testJsonCoding() throws {
13-
let value = try Coord(lat: 40, lng: -111.84)
13+
let value = try Coord(latitude: 40, longitude: -111.84)
1414
let jsonString = #"{"_kind":"coord","lat":40,"lng":-111.84}"#
1515

1616
let encodedData = try JSONEncoder().encode(value)
@@ -28,7 +28,7 @@ final class CoordTests: XCTestCase {
2828

2929
func testToZinc() throws {
3030
XCTAssertEqual(
31-
try Coord(lat: 40, lng: -111.84).toZinc(),
31+
try Coord(latitude: 40, longitude: -111.84).toZinc(),
3232
"C(40.0,-111.84)"
3333
)
3434
}

Tests/HaystackTests/IO/ZincReaderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class ZincReaderTests: XCTestCase {
108108
[marker, remove, null, null], // Bin not supported.
109109
[Date(year: 2009, month: 12, day: 31), Time(hour: 23, minute: 59, second: 1), Time(hour: 1, minute: 2, second: 3, millisecond: 123), DateTime(year: 2009, month: 2, day: 3, hour: 4, minute: 5, second: 6)],
110110
[Number.infinity, Number.negativeInfinity, "", Number.nan],
111-
[Coord(lat: 12, lng: -34), Coord(lat: 0.123, lng: -0.789), Coord(lat: 84.5, lng: -77.45), Coord(lat: -90, lng: 180)],
111+
[Coord(latitude: 12, longitude: -34), Coord(latitude: 0.123, longitude: -0.789), Coord(latitude: 84.5, longitude: -77.45), Coord(latitude: -90, longitude: 180)],
112112
]
113113
)
114114

0 commit comments

Comments
 (0)