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

Implement Area based on traits #1115

Draft
wants to merge 4 commits into
base: traits
Choose a base branch
from
Draft
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
72 changes: 47 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 @@ -28,12 +27,23 @@ jobs:
- 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 @@ -44,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 @@ -68,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 @@ -96,15 +106,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 --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"
Expand Down Expand Up @@ -149,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 @@ -172,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-traits", "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
1 change: 1 addition & 0 deletions geo-bool-ops-benches/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{bail, Context, Result};
use geo::area::AreaMultiPolygon;
use geo::prelude::*;
use geo_booleanop::boolean::BooleanOp as OtherBOp;
use geo_types::*;
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
40 changes: 26 additions & 14 deletions geo-traits/src/coord.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use geo_types::{Coord, CoordNum, Point};

pub trait CoordTrait: Send + Sync {
type T: CoordNum + Send + Sync;
pub trait CoordTrait {
type T: CoordNum;

/// x component of this coord
fn x(&self) -> Self::T;
Expand All @@ -15,50 +15,62 @@ pub trait CoordTrait: Send + Sync {
}
}

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

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

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

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

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

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

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

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

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

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

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

fn y(&self) -> T {
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
Loading