Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new geo-traits crate #1019

Closed
wants to merge 17 commits into from
Closed
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
99 changes: 74 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ on:
- trying
- release/**
pull_request:
merge_group:
schedule: [cron: "45 6 * * *"]

name: Run tests
jobs:
# The `ci-result` job doesn't actually test anything - it just aggregates the
# overall build status for bors, otherwise our bors.toml would need an entry
# overall build status, otherwise the merge queue would need an entry
# for each individual job produced by the job-matrix.
#
# Ref: https://github.com/rust-lang/crater/blob/9ab6f9697c901c4a44025cf0a39b73ad5b37d198/.github/workflows/bors.yml#L125-L149
#
# ALL THE SUBSEQUENT JOBS NEED THEIR `name` ADDED TO THE `needs` SECTION OF THIS JOB!
ci-result:
# ALL THE SUBSEQUENT JOBS NEED THEIR `name` ADDED TO THE `needs` SECTION OF both "ci result" JOBS!
ci-success:
name: ci result
runs-on: ubuntu-latest
needs:
Expand All @@ -26,13 +25,25 @@ jobs:
- geo
- geo_postgis
- geo_fuzz
- geo_traits
- bench
if: success()
steps:
- name: Mark the job as a success
if: success()
run: exit 0
ci-failure:
name: ci result
runs-on: ubuntu-latest
needs:
- lint
- geo_types
- geo
- geo_postgis
- geo_fuzz
- bench
if: failure()
steps:
- name: Mark the job as a failure
if: "!success()"
run: exit 1

lint:
Expand All @@ -43,12 +54,12 @@ jobs:
matrix:
container_image:
# Use the latest stable version. No need for older versions.
- "georust/geo-ci:rust-1.66"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: rustup component add rustfmt clippy
- run: cargo fmt --all -- --check
- run: cargo clippy --all-features --all-targets -- -Dwarnings
Expand All @@ -67,15 +78,15 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:rust-1.63"
- "georust/geo-ci:proj-9.2.1-rust-1.65"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:rust-1.65"
- "georust/geo-ci:rust-1.66"
- "georust/geo-ci:proj-9.2.1-rust-1.71"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: rustup target add thumbv7em-none-eabihf
- run: cargo check --all-targets --no-default-features
- run: cargo check --lib --target thumbv7em-none-eabihf --no-default-features -F use-rstar_0_9,serde
Expand All @@ -95,19 +106,45 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:rust-1.63"
- "georust/geo-ci:proj-9.2.1-rust-1.65"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:rust-1.65"
- "georust/geo-ci:rust-1.66"
- "georust/geo-ci:proj-9.2.1-rust-1.71"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: cargo check --all-targets --no-default-features
# we don't want to test `proj-network` because it only enables the `proj` feature
- run: cargo test --features "use-proj use-serde"

geo_traits:
name: geo-traits
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
defaults:
run:
working-directory: geo-traits
strategy:
matrix:
container_image:
# We aim to support rust-stable plus (at least) the prior 3 releases,
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:proj-9.2.1-rust-1.65"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:proj-9.2.1-rust-1.71"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- run: cargo check --all-targets --no-default-features
- run: cargo test

geo_postgis:
name: geo-postgis
runs-on: ubuntu-latest
Expand All @@ -122,15 +159,15 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:rust-1.63"
- "georust/geo-ci:proj-9.2.1-rust-1.65"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:rust-1.65"
- "georust/geo-ci:rust-1.66"
- "georust/geo-ci:proj-9.2.1-rust-1.71"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: cargo check --all-targets
- run: cargo test

Expand All @@ -145,21 +182,33 @@ jobs:
matrix:
container_image:
# Fuzz only on latest
- "georust/geo-ci:rust-1.66"
- "georust/geo-ci:proj-9.2.1-rust-1.72"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: cargo build --bins

bench:
name: bench
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
container:
image: georust/geo-ci:rust-1.66
image: georust/geo-ci:proj-9.2.1-rust-1.72
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: cargo bench --no-run

docs:
name: build documentation
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
container:
image: georust/geo-ci:proj-9.2.1-rust-1.72
steps:
- name: Checkout repository
uses: actions/checkout@v3
- run: RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[workspace]
members = ["geo", "geo-types", "geo-postgis", "geo-test-fixtures", "jts-test-runner", "geo-bool-ops-benches"]
resolver = "2"
members = [
"geo",
"geo-types",
"geo-traits",
"geo-postgis",
"geo-test-fixtures",
"jts-test-runner",
"geo-bool-ops-benches",
]

[patch.crates-io]

Expand Down
3 changes: 0 additions & 3 deletions bors.toml

This file was deleted.

10 changes: 5 additions & 5 deletions geo-bool-ops-benches/benches/boolean_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn run_complex<T: Measurement>(c: &mut Criterion<T>) {
|b, _| {
b.iter_batched(
polys.sampler(),
|&(ref poly, ref poly2, _, _)| poly.intersection(poly2),
|(poly, poly2, _, _)| poly.intersection(poly2),
BatchSize::SmallInput,
);
},
Expand All @@ -55,7 +55,7 @@ fn run_complex<T: Measurement>(c: &mut Criterion<T>) {
group.bench_with_input(BenchmarkId::new("bops::union", steps), &(), |b, _| {
b.iter_batched(
polys.sampler(),
|&(ref poly, ref poly2, _, _)| poly.union(poly2),
|(poly, poly2, _, _)| poly.union(poly2),
BatchSize::SmallInput,
);
});
Expand All @@ -66,7 +66,7 @@ fn run_complex<T: Measurement>(c: &mut Criterion<T>) {
|b, _| {
b.iter_batched(
polys.sampler(),
|&(_, _, ref poly, ref poly2)| OtherBooleanOp::intersection(poly, poly2),
|(_, _, poly, poly2)| OtherBooleanOp::intersection(poly, poly2),
BatchSize::SmallInput,
);
},
Expand All @@ -75,15 +75,15 @@ fn run_complex<T: Measurement>(c: &mut Criterion<T>) {
group.bench_with_input(BenchmarkId::new("rgbops::union", steps), &(), |b, _| {
b.iter_batched(
polys.sampler(),
|&(_, _, ref poly, ref poly2)| OtherBooleanOp::union(poly, poly2),
|(_, _, poly, poly2)| OtherBooleanOp::union(poly, poly2),
BatchSize::SmallInput,
);
});

group.bench_with_input(BenchmarkId::new("geo::relate", steps), &(), |b, _| {
b.iter_batched(
polys.sampler(),
|&(ref poly, ref poly2, _, _)| poly.relate(poly2).is_intersects(),
|(poly, poly2, _, _)| poly.relate(poly2).is_intersects(),
BatchSize::SmallInput,
);
});
Expand Down
2 changes: 1 addition & 1 deletion geo-postgis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ documentation = "https://docs.rs/geo-postgis/"
readme = "../README.md"
keywords = ["gis", "geo", "geography", "geospatial", "postgis"]
description = "Conversion between `geo-types` and `postgis` types."
rust-version = "1.63"
rust-version = "1.65"
edition = "2021"

[dependencies]
Expand Down
19 changes: 19 additions & 0 deletions geo-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "geo-traits"
version = "0.1.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/georust/geo"
documentation = "https://docs.rs/geo-traits/"
readme = "../README.md"
keywords = ["gis", "geo", "geography", "geospatial"]
description = "Geospatial traits"
rust-version = "1.65"
edition = "2021"

[features]

[dependencies]
geo-types = "0.7.9"

[dev-dependencies]
approx = ">= 0.4.0, < 0.6.0"
76 changes: 76 additions & 0 deletions geo-traits/src/coord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use geo_types::{Coord, CoordNum, Point};

pub trait CoordTrait {
type T: CoordNum;

/// x component of this coord
fn x(&self) -> Self::T;

/// y component of this coord
fn y(&self) -> Self::T;

/// Returns a tuple that contains the x/horizontal & y/vertical component of the coord.
fn x_y(&self) -> (Self::T, Self::T) {
(self.x(), self.y())
}
}

impl<T: CoordNum> CoordTrait for Point<T> {
type T = T;

fn x(&self) -> Self::T {
self.0.x
}

fn y(&self) -> Self::T {
self.0.y
}
}

impl<T: CoordNum> CoordTrait for &Point<T> {
type T = T;

fn x(&self) -> Self::T {
self.0.x
}

fn y(&self) -> Self::T {
self.0.y
}
}

impl<T: CoordNum> CoordTrait for Coord<T> {
type T = T;

fn x(&self) -> Self::T {
self.x
}

fn y(&self) -> Self::T {
self.y
}
}

impl<T: CoordNum> CoordTrait for &Coord<T> {
type T = T;

fn x(&self) -> Self::T {
self.x
}

fn y(&self) -> Self::T {
self.y
}
}

impl<T: CoordNum> CoordTrait for (T, T) {
type T = T;

fn x(&self) -> Self::T {
self.0
}

fn y(&self) -> Self::T {
self.1
}
}
Loading