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
32 changes: 18 additions & 14 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ name: Swift

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Test
run: swift test
- uses: actions/checkout@v3
- name: Build
run: swift build
- name: Test
run: swift test

linux:
runs-on: ubuntu-latest

strategy:
matrix:
swift: ["5.9.1", "5.7.3"]

container:
image: swift:5.4
image: swift:${{ matrix.swift }}
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Test
run: swift test

- uses: actions/checkout@v3
- name: Build
run: swift build
- name: Test
run: swift test
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "GeoJSONKitTurf",
platforms: [
.macOS(.v10_12), .iOS(.v10), .watchOS(.v3), .tvOS(.v12),
.macOS(.v12), .iOS(.v15), .watchOS(.v8), .tvOS(.v15),
.custom("xros", versionString: "1.0")
],
products: [
Expand All @@ -17,14 +17,16 @@ let package = Package(
targets: ["GeoKitten"]),
],
dependencies: [
.package(name: "GeoJSONKit", url: "https://github.com/maparoni/geojsonkit.git", from: "0.5.2"),
.package(url: "https://github.com/maparoni/geojsonkit.git", from: "0.5.2"),
// .package(name: "GeoJSONKit", path: "../GeoJSONKit"),
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMajor(from: "1.0.0")),
],
targets: [
.target(
name: "GeoJSONKitTurf",
dependencies: ["GeoJSONKit"]),
dependencies: [
.product(name: "GeoJSONKit", package: "geojsonkit"),
]),
.executableTarget(
name: "GeoKitten",
dependencies: [
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This package provides various geospatial extensions for [GeoJSONKit](https://git

## Requirements

GeoJSONKitTurf requires Xcode 12.x and supports the following minimum deployment targets:
GeoJSONKitTurf requires Xcode 14.x and supports the following minimum deployment targets:

* iOS 10.0 and above
* macOS 10.12 (Sierra) and above
* tvOS 10.0 and above
* watchOS 3.0 and above
- iOS 15 and above
- macOS 12 and above
- tvOS 15 and above
- watchOS 8.0 and above

It's also compatible with Linux (and possibly other platforms), as long as you have [Swift](https://swift.org/download/) 5.3 (or above) installed.
It's also compatible with Linux (and possibly other platforms), as long as you have [Swift](https://swift.org/download/) 5.7 (or above) installed.

## Installation

Expand All @@ -27,7 +27,7 @@ To install GeoJSONKitTurf using the [Swift Package Manager](https://swift.org/pa
.package(name: "GeoJSONKitTurf", url: "https://github.com/maparoni/geojsonkit-turf", from: "0.1.0")
```

Then use:
Then use:

```swift
import GeoJSONKitTurf
Expand Down Expand Up @@ -85,6 +85,7 @@ First clone or download the repository, then run this:
swift build -c release
sudo cp .build/release/geokitten /usr/local/bin/geokitten
```

</details>

<details>
Expand All @@ -95,4 +96,5 @@ mint install maparoni/GeoJSONKit-Turf@main
```

If you get a permissions error, check [this Mint issue](https://github.com/yonaskolb/Mint/issues/188).

</details>
12 changes: 6 additions & 6 deletions Sources/GeoJSONKitTurf/Turf+GeometryObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Foundation
import GeoJSONKit

extension GeoJSON.Geometry {
public func contains(_ coordinate: GeoJSON.Position, ignoreBoundary: Bool = false) -> Bool {
public func contains(_ coordinate: GeoJSON.Position, ignoreBoundary: Bool = false, checkBoundingBox: Bool = true) -> Bool {
switch self {
case .polygon(let polygon):
return polygon.contains(coordinate, ignoreBoundary: ignoreBoundary)
return polygon.contains(coordinate, ignoreBoundary: ignoreBoundary, checkBoundingBox: checkBoundingBox)
case .lineString, .point:
return false
}
Expand Down Expand Up @@ -109,14 +109,14 @@ extension GeoJSON.GeometryObject {
*
* Calls contains function for each contained polygon
*/
public func contains(_ coordinate: GeoJSON.Position, ignoreBoundary: Bool = false) -> Bool {
public func contains(_ coordinate: GeoJSON.Position, ignoreBoundary: Bool = false, checkBoundingBox: Bool = true) -> Bool {
switch self {
case .single(let geometry):
return geometry.contains(coordinate, ignoreBoundary: ignoreBoundary)
return geometry.contains(coordinate, ignoreBoundary: ignoreBoundary, checkBoundingBox: checkBoundingBox)
case .multi(let geometries):
return geometries.contains(where: { $0.contains(coordinate, ignoreBoundary: ignoreBoundary) })
return geometries.contains(where: { $0.contains(coordinate, ignoreBoundary: ignoreBoundary, checkBoundingBox: checkBoundingBox) })
case .collection(let objects):
return objects.contains(where: { $0.contains(coordinate, ignoreBoundary: ignoreBoundary) })
return objects.contains(where: { $0.contains(coordinate, ignoreBoundary: ignoreBoundary, checkBoundingBox: checkBoundingBox) })
}
}
}
12 changes: 7 additions & 5 deletions Sources/GeoJSONKitTurf/Turf+LinearRing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension GeoJSON.Polygon.LinearRing {
*
* Ported from: https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts#L77-L108
*/
public func contains(_ coordinate: GeoJSON.Position, ignoreBoundary: Bool = false) -> Bool {
public func contains(_ coordinate: GeoJSON.Position, ignoreBoundary: Bool = false, checkBoundingBox: Bool = true) -> Bool {

// Optimization for triangles, using barycentric method
guard positions.count > 3 else {
Expand Down Expand Up @@ -83,10 +83,12 @@ extension GeoJSON.Polygon.LinearRing {
: (s >= 0 && s + t <= a)
}


let bbox = GeoJSON.BoundingBox(positions: positions)
guard bbox.contains(coordinate, ignoreBoundary: ignoreBoundary) else {
return false

if checkBoundingBox {
let bbox = GeoJSON.BoundingBox(positions: positions)
guard bbox.contains(coordinate, ignoreBoundary: ignoreBoundary) else {
return false
}
}

let coordinates = positions
Expand Down
6 changes: 3 additions & 3 deletions Sources/GeoJSONKitTurf/Turf+Polygon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ extension GeoJSON.Polygon {
/// lies on the boundary line of the polygon or its interior rings.
///
///Ported from: https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts#L31-L75
public func contains(_ position: GeoJSON.Position, ignoreBoundary: Bool = false) -> Bool {
guard exterior.contains(position, ignoreBoundary: ignoreBoundary) else {
public func contains(_ position: GeoJSON.Position, ignoreBoundary: Bool = false, checkBoundingBox: Bool = true) -> Bool {
guard exterior.contains(position, ignoreBoundary: ignoreBoundary, checkBoundingBox: checkBoundingBox) else {
return false
}
for ring in interiors {
if ring.contains(position, ignoreBoundary: !ignoreBoundary) {
if ring.contains(position, ignoreBoundary: !ignoreBoundary, checkBoundingBox: false) {
return false
}
}
Expand Down