Skip to content

Commit

Permalink
Some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed Mar 19, 2024
1 parent bf1d5a0 commit 1cb8776
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,13 @@ func projected(to newProjection: Projection) -> GeometryCollection
A `Feature` is sort of a container for exactly one GeoJSON geometry (`Point`, `MultiPoint`, `LineString`, `MultiLineString`, `Polygon`, `MultiPolygon`, `GeometryCollection`) together with some `properties` and an optional `id`:
```swift
/// A GeoJSON identifier that can either be a string or number.
/// Any parsed integer value `Int64.min ⪬ i ⪬ Int64.max` will be cast to `Int`
/// (or `Int64` on 32-bit platforms), values above `Int64.max` will be cast to `UInt`
/// (or `UInt64` on 32-bit platforms).
enum Identifier: Equatable, Hashable, CustomStringConvertible {
case string(String)
case int(Int)
case uint(UInt)
case double(Double)
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/GISTools/GeoJson/Feature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import Foundation
public struct Feature: GeoJson {

/// A GeoJSON identifier that can either be a string or number.
///
/// Any parsed integer value `Int64.min ⪬ i ⪬ Int64.max` will be cast to `Int`
/// (or `Int64` on 32-bit platforms), values above `Int64.max` will be cast to `UInt`
/// (or `UInt64` on 32-bit platforms).
public enum Identifier: Equatable, Hashable, CustomStringConvertible, Sendable {

#if _pointerBitWidth(_32)
Expand Down
10 changes: 7 additions & 3 deletions Tests/GISToolsTests/GeoJson/FeatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,23 @@ final class FeatureTests: XCTestCase {
}

func testFeatureIds() throws {
XCTAssertEqual(Feature.Identifier(value: 1234), .int(1234))
XCTAssertEqual(Feature.Identifier(value: Int8(32)), .int(32))
XCTAssertEqual(Feature.Identifier(value: Int8(32))?.int64Value, 32)
XCTAssertEqual(Feature.Identifier(value: Int8(32))?.uint64Value, 32)

// UInt -> Int
XCTAssertEqual(Feature.Identifier(value: UInt64(32)), .int(32))

XCTAssertEqual(Feature.Identifier(value: -1234), .int(-1234))
XCTAssertEqual(Feature.Identifier(value: Int8(-32)), .int(-32))
XCTAssertEqual(Feature.Identifier(value: Int8(-32))?.int64Value, -32)
XCTAssertNil(Feature.Identifier(value: Int8(-32))?.uint64Value)

// UInt -> Int
XCTAssertEqual(Feature.Identifier(value: UInt64(32)), .int(32))

XCTAssertEqual(Feature.Identifier(value: Int64.max), .int(9223372036854775807))
XCTAssertEqual(Feature.Identifier(value: Int64.max)?.int64Value, 9223372036854775807)
XCTAssertEqual(Feature.Identifier(value: Int64.min), .int(-9223372036854775808))
XCTAssertEqual(Feature.Identifier(value: Int64.min)?.int64Value, -9223372036854775808)

// 9223372036854775808 is Int64.max+1
XCTAssertEqual(Feature.Identifier(value: UInt64(9223372036854775808)), .uint(9223372036854775808))
Expand Down

0 comments on commit 1cb8776

Please sign in to comment.