Skip to content

Commit

Permalink
Merge branch 'main' into borrow-affine
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv authored Feb 13, 2024
2 parents 433360c + d3aac79 commit f381d35
Show file tree
Hide file tree
Showing 48 changed files with 2,168 additions and 280 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
matrix:
container_image:
# Use the latest stable version. No need for older versions.
- "georust/geo-ci:proj-9.2.1-rust-1.72"
- "georust/geo-ci:proj-9.3.1-rust-1.75"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -77,10 +77,10 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:proj-9.2.1-rust-1.65"
- "georust/geo-ci:proj-9.3.1-rust-1.70"
# 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"
- "georust/geo-ci:proj-9.3.1-rust-1.74"
- "georust/geo-ci:proj-9.3.1-rust-1.75"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -105,10 +105,10 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:proj-9.2.1-rust-1.65"
- "georust/geo-ci:proj-9.3.1-rust-1.70"
# 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"
- "georust/geo-ci:proj-9.3.1-rust-1.74"
- "georust/geo-ci:proj-9.3.1-rust-1.75"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -132,10 +132,10 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:proj-9.2.1-rust-1.65"
- "georust/geo-ci:proj-9.3.1-rust-1.70"
# 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"
- "georust/geo-ci:proj-9.3.1-rust-1.74"
- "georust/geo-ci:proj-9.3.1-rust-1.75"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -155,7 +155,7 @@ jobs:
matrix:
container_image:
# Fuzz only on latest
- "georust/geo-ci:proj-9.2.1-rust-1.72"
- "georust/geo-ci:proj-9.3.1-rust-1.75"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -168,7 +168,7 @@ jobs:
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
image: georust/geo-ci:proj-9.3.1-rust-1.75
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -179,7 +179,7 @@ jobs:
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
image: georust/geo-ci:proj-9.3.1-rust-1.75
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ The `geo` crate provides geospatial primitive types such as `Point`, `LineString
- Simplification and convex hull operations
- Euclidean and Haversine distance measurement
- Intersection checks
- Affine transforms such as rotation and translation.
- Affine transforms such as rotation and translation
- All DE-9IM spatial predicates such as contains, crosses, and touches.

Please refer to [the documentation](https://docs.rs/geo) for a complete list.

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.65"
rust-version = "1.70"
edition = "2021"

[dependencies]
Expand Down
9 changes: 8 additions & 1 deletion geo-types/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changes

## Unrealeased
## Unreleased

* POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.70
* <https://github.com/georust/geo/pull/1134>
* Add feature for rstar v0.12.0
* Add num_rings and num_interior_rings methods to polygons.

## 0.7.12

* Add `Polygon::try_exterior_mut` and `Polygon::try_interiors_mut`.
<https://github.com/georust/geo/pull/1071>
Expand Down
6 changes: 4 additions & 2 deletions geo-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "geo-types"
version = "0.7.11"
version = "0.7.12"
license = "MIT OR Apache-2.0"
repository = "https://github.com/georust/geo"
documentation = "https://docs.rs/geo-types/"
readme = "../README.md"
keywords = ["gis", "geo", "geography", "geospatial"]
description = "Geospatial primitive data types"
rust-version = "1.65"
rust-version = "1.70"
edition = "2021"

[features]
Expand All @@ -22,6 +22,7 @@ use-rstar_0_8 = ["rstar_0_8", "approx"]
use-rstar_0_9 = ["rstar_0_9", "approx"]
use-rstar_0_10 = ["rstar_0_10", "approx"]
use-rstar_0_11 = ["rstar_0_11", "approx"]
use-rstar_0_12 = ["rstar_0_12", "approx"]

[dependencies]
approx = { version = ">= 0.4.0, < 0.6.0", optional = true, default-features = false }
Expand All @@ -31,6 +32,7 @@ rstar_0_8 = { package = "rstar", version = "0.8", optional = true }
rstar_0_9 = { package = "rstar", version = "0.9", optional = true }
rstar_0_10 = { package = "rstar", version = "0.10", optional = true }
rstar_0_11 = { package = "rstar", version = "0.11", optional = true }
rstar_0_12 = { package = "rstar", version = "0.12", optional = true }
serde = { version = "1", optional = true, default-features = false, features = ["alloc", "derive"] }

[dev-dependencies]
Expand Down
36 changes: 36 additions & 0 deletions geo-types/src/geometry/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,39 @@ where
}
}
}

#[cfg(feature = "rstar_0_12")]
impl<T> ::rstar_0_12::Point for Coord<T>
where
T: ::num_traits::Float + ::rstar_0_12::RTreeNum,
{
type Scalar = T;

const DIMENSIONS: usize = 2;

#[inline]
fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self {
coord! {
x: generator(0),
y: generator(1),
}
}

#[inline]
fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.x,
1 => self.y,
_ => unreachable!(),
}
}

#[inline]
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.x,
1 => &mut self.y,
_ => unreachable!(),
}
}
}
6 changes: 5 additions & 1 deletion geo-types/src/geometry/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for Line<T> {
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_line {
($rstar:ident) => {
Expand Down Expand Up @@ -265,6 +266,9 @@ impl_rstar_line!(rstar_0_10);
#[cfg(feature = "rstar_0_11")]
impl_rstar_line!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_line!(rstar_0_12);

#[cfg(test)]
mod test {
use super::*;
Expand Down
6 changes: 5 additions & 1 deletion geo-types/src/geometry/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for LineString<T> {
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_line_string {
($rstar:ident) => {
Expand Down Expand Up @@ -544,6 +545,9 @@ impl_rstar_line_string!(rstar_0_10);
#[cfg(feature = "rstar_0_11")]
impl_rstar_line_string!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_line_string!(rstar_0_12);

#[cfg(test)]
mod test {
use super::*;
Expand Down
16 changes: 12 additions & 4 deletions geo-types/src/geometry/multi_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ use core::iter::FromIterator;
pub struct MultiPoint<T: CoordNum = f64>(pub Vec<Point<T>>);

impl<T: CoordNum, IP: Into<Point<T>>> From<IP> for MultiPoint<T> {
/// Convert a single `Point` (or something which can be converted to a `Point`) into a
/// one-member `MultiPoint`
/// Convert a single `Point` (or something which can be converted to a
/// `Point`) into a one-member `MultiPoint`
fn from(x: IP) -> Self {
Self(vec![x.into()])
}
}

impl<T: CoordNum, IP: Into<Point<T>>> From<Vec<IP>> for MultiPoint<T> {
/// Convert a `Vec` of `Points` (or `Vec` of things which can be converted to a `Point`) into a
/// `MultiPoint`.
/// Convert a `Vec` of `Points` (or `Vec` of things which can be converted
/// to a `Point`) into a `MultiPoint`.
fn from(v: Vec<IP>) -> Self {
Self(v.into_iter().map(|p| p.into()).collect())
}
Expand Down Expand Up @@ -90,6 +90,14 @@ impl<T: CoordNum> MultiPoint<T> {
Self(value)
}

pub fn len(&self) -> usize {
self.0.len()
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

pub fn iter(&self) -> impl Iterator<Item = &Point<T>> {
self.0.iter()
}
Expand Down
29 changes: 29 additions & 0 deletions geo-types/src/geometry/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,35 @@ where
}
}

#[cfg(feature = "rstar_0_12")]
impl<T> ::rstar_0_12::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_12::RTreeNum,
{
type Scalar = T;

const DIMENSIONS: usize = 2;

fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self {
Point::new(generator(0), generator(1))
}

fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.0.x,
1 => self.0.y,
_ => unreachable!(),
}
}
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.0.x,
1 => &mut self.0.y,
_ => unreachable!(),
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
56 changes: 55 additions & 1 deletion geo-types/src/geometry/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,56 @@ impl<T: CoordNum> Polygon<T> {
{
(current_vertex + (self.exterior.0.len() - 1) - 1) % (self.exterior.0.len() - 1)
}

/// Count the total number of rings (interior and exterior) in the polygon
///
/// # Examples
///
/// ```
/// use geo_types::{coord, LineString, Polygon};
///
/// let polygon = Polygon::new(
/// LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
/// vec![],
/// );
///
/// assert_eq!(polygon.num_rings(), 1);
///
/// let polygon = Polygon::new(
/// LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
/// vec![LineString::from(vec![(0.1, 0.1), (0.9, 0.9), (0.9, 0.1)])],
/// );
///
/// assert_eq!(polygon.num_rings(), 2);
/// ```
pub fn num_rings(&self) -> usize {
self.num_interior_rings() + 1
}

/// Count the number of interior rings in the polygon
///
/// # Examples
///
/// ```
/// use geo_types::{coord, LineString, Polygon};
///
/// let polygon = Polygon::new(
/// LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
/// vec![],
/// );
///
/// assert_eq!(polygon.num_interior_rings(), 0);
///
/// let polygon = Polygon::new(
/// LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
/// vec![LineString::from(vec![(0.1, 0.1), (0.9, 0.9), (0.9, 0.1)])],
/// );
///
/// assert_eq!(polygon.num_interior_rings(), 1);
/// ```
pub fn num_interior_rings(&self) -> usize {
self.interiors.len()
}
}

// used to check the sign of a vec of floats
Expand Down Expand Up @@ -571,7 +621,8 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for Polygon<T> {
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_polygon {
($rstar:ident) => {
Expand Down Expand Up @@ -599,3 +650,6 @@ impl_rstar_polygon!(rstar_0_10);

#[cfg(feature = "rstar_0_11")]
impl_rstar_polygon!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_polygon!(rstar_0_12);
Loading

0 comments on commit f381d35

Please sign in to comment.