Skip to content

Commit

Permalink
Merge pull request #1134 from georust/mkirk/rust-msrv-1.70
Browse files Browse the repository at this point in the history
Introduce `total_cmp` on GeoNum to avoid unwraps
  • Loading branch information
michaelkirk authored Jan 10, 2024
2 parents 47fadf1 + dfdd025 commit e0f4b6a
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 73 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
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
5 changes: 5 additions & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changes

## Unreleased

* POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.70
* <https://github.com/georust/geo/pull/1134>

## 0.7.12

* Add `Polygon::try_exterior_mut` and `Polygon::try_interiors_mut`.
Expand Down
2 changes: 1 addition & 1 deletion geo-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 Down
19 changes: 19 additions & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changes

## Unreleased
* BREAKING: The `HasKernel` trait was removed and it's functionality was merged
into `GeoNum`. If you are using common scalars for your geometry (f32, f64,
i64, i32, i16, isize), this should have no effect on you. If you are using an
exotic scalar type, you'll need to implement `GeoNum` for it instead of
`HasKernel`. If you had functionality defined in terms of `HasKernel` before,
define it in terms of `GeoNum` instead.
* <https://github.com/georust/geo/pull/1134>
* BREAKING: Added a new `total_cmp` method to `GeoNum`. This avoids some
potential crashes when working with geometries that contain NaN points. This
shouldn't break for any common numeric types, but if you are using something
exotic you'll need to manually implement `GeoNum` for your numeric type.
* <https://github.com/georust/geo/pull/1134>
* POSSIBLY BREAKING: `SimplifyVwPreserve` trait implementation moved from
`geo_types::CoordNum` to `geo::GeoNum` as a consequence of introducing the
`GeoNum::total_cmp`. This shouldn't break anything for common numeric
types, but if you are using something exotic you'll need to manually
implement `GeoNum` for your numeric type.
* Implement ChaikinSmoothing to work on Geometry types
* <https://github.com/georust/geo/pull/1116>
* Fix a panic when calculating the haversine closest point to a point intersecting the geometry
Expand All @@ -11,6 +28,8 @@
* <https://github.com/georust/geo/pull/1123>
* PERF: small improvements to TriangulateSpade trait
* <https://github.com/georust/geo/pull/1122>
* POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.70
* <https://github.com/georust/geo/pull/1134>

## 0.27.0

Expand Down
2 changes: 1 addition & 1 deletion geo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../README.md"
keywords = ["gis", "geo", "geography", "geospatial"]
autobenches = true
edition = "2021"
rust-version = "1.65"
rust-version = "1.70"
categories = ["science::geo"]

[features]
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/convex_hull/qhull.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{swap_remove_to_first, trivial_hull};
use crate::kernels::{HasKernel, Kernel, Orientation};
use crate::kernels::{Kernel, Orientation};
use crate::utils::partition_slice;
use crate::{coord, Coord, GeoNum, LineString};

Expand All @@ -13,7 +13,7 @@ fn is_ccw<T>(p_a: Coord<T>, p_b: Coord<T>, p_c: Coord<T>) -> bool
where
T: GeoNum,
{
let o = <T as HasKernel>::Ker::orient2d(p_a, p_b, p_c);
let o = T::Ker::orient2d(p_a, p_b, p_c);
o == Orientation::CounterClockwise
}

Expand Down
1 change: 0 additions & 1 deletion geo/src/algorithm/intersects/line.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{point_in_rect, Intersects};
use crate::kernels::*;
use crate::*;

impl<T> Intersects<Coord<T>> for Line<T>
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/is_convex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::kernels::*;
use crate::{Coord, LineString};
use crate::{Coord, GeoNum, LineString};

/// Predicates to test the convexity of a [ `LineString` ].
/// A closed `LineString` is said to be _convex_ if it
Expand Down Expand Up @@ -108,7 +108,7 @@ pub trait IsConvex {
fn is_collinear(&self) -> bool;
}

impl<T: HasKernel> IsConvex for LineString<T> {
impl<T: GeoNum> IsConvex for LineString<T> {
fn convex_orientation(
&self,
allow_collinear: bool,
Expand Down Expand Up @@ -140,7 +140,7 @@ fn is_convex_shaped<T>(
specific_orientation: Option<Orientation>,
) -> Option<Orientation>
where
T: HasKernel,
T: GeoNum,
{
let n = coords.len();

Expand Down
27 changes: 0 additions & 27 deletions geo/src/algorithm/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,8 @@ pub trait Kernel<T: CoordNum> {
}
}

/// Marker trait to assign Kernel for scalars
pub trait HasKernel: CoordNum {
type Ker: Kernel<Self>;
}

// Helper macro to implement `HasKernel` on a a scalar type
// `T` (first arg.) by assigning the second arg. It expects
// the second arg. to be a type that takes one generic
// parameter that is `T`.
macro_rules! has_kernel {
($t:ident, $k:ident) => {
impl $crate::HasKernel for $t {
type Ker = $k;
}
};
}

pub mod robust;
pub use self::robust::RobustKernel;
has_kernel!(f64, RobustKernel);
has_kernel!(f32, RobustKernel);

pub mod simple;
pub use self::simple::SimpleKernel;

has_kernel!(i64, SimpleKernel);
has_kernel!(i32, SimpleKernel);
has_kernel!(i16, SimpleKernel);
has_kernel!(isize, SimpleKernel);

#[cfg(has_i128)]
has_kernel!(i128, SimpleKernel);
2 changes: 1 addition & 1 deletion geo/src/algorithm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Kernels to compute various predicates
pub mod kernels;
pub use kernels::{HasKernel, Kernel, Orientation};
pub use kernels::{Kernel, Orientation};

/// Calculate the area of the surface of a `Geometry`.
pub mod area;
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/monotone/mono_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use geo_types::{private_utils::get_bounding_rect, Line};

use crate::{
coordinate_position::CoordPos, sweep::SweepPoint, BoundingRect, Coord, CoordinatePosition,
GeoNum, HasKernel, Intersects, Kernel, LineString, Orientation, Polygon, Rect,
GeoNum, Intersects, Kernel, LineString, Orientation, Polygon, Rect,
};

/// Monotone polygon
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<T: GeoNum> CoordinatePosition for MonoPoly<T> {
return;
};

match <T as HasKernel>::Ker::orient2d(top.start, *coord, top.end) {
match T::Ker::orient2d(top.start, *coord, top.end) {
Orientation::Clockwise => return,
Orientation::Collinear => {
*is_inside = true;
Expand All @@ -145,7 +145,7 @@ impl<T: GeoNum> CoordinatePosition for MonoPoly<T> {
}
_ => {}
}
match <T as HasKernel>::Ker::orient2d(bot.start, *coord, bot.end) {
match T::Ker::orient2d(bot.start, *coord, bot.end) {
Orientation::CounterClockwise => (),
Orientation::Collinear => {
*is_inside = true;
Expand Down
16 changes: 8 additions & 8 deletions geo/src/algorithm/simplify_vw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use crate::{
Coord, CoordFloat, HasKernel, Line, LineString, MultiLineString, MultiPolygon, Point, Polygon,
Coord, CoordFloat, GeoFloat, Line, LineString, MultiLineString, MultiPolygon, Point, Polygon,
Triangle,
};
use std::cmp::Ordering;
Expand Down Expand Up @@ -241,7 +241,7 @@ fn vwp_wrapper<T, const INITIAL_MIN: usize, const MIN_POINTS: usize>(
epsilon: &T,
) -> Vec<Vec<Coord<T>>>
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
let mut rings = vec![];
// Populate R* tree with exterior and interior samples, if any
Expand Down Expand Up @@ -291,7 +291,7 @@ fn visvalingam_preserve<T, const INITIAL_MIN: usize, const MIN_POINTS: usize>(
tree: &mut RTree<CachedEnvelope<Line<T>>>,
) -> Vec<Coord<T>>
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
if orig.0.len() < 3 || *epsilon <= T::zero() {
return orig.0.to_vec();
Expand Down Expand Up @@ -400,7 +400,7 @@ fn tree_intersect<T>(
orig: &[Coord<T>],
) -> bool
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
let new_segment_start = orig[triangle.left];
let new_segment_end = orig[triangle.right];
Expand Down Expand Up @@ -581,7 +581,7 @@ pub trait SimplifyVwPreserve<T, Epsilon = T> {

impl<T> SimplifyVwPreserve<T> for LineString<T>
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
fn simplify_vw_preserve(&self, epsilon: &T) -> LineString<T> {
let mut simplified = vwp_wrapper::<_, 2, 4>(self, None, epsilon);
Expand All @@ -591,7 +591,7 @@ where

impl<T> SimplifyVwPreserve<T> for MultiLineString<T>
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
fn simplify_vw_preserve(&self, epsilon: &T) -> MultiLineString<T> {
MultiLineString::new(
Expand All @@ -605,7 +605,7 @@ where

impl<T> SimplifyVwPreserve<T> for Polygon<T>
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
fn simplify_vw_preserve(&self, epsilon: &T) -> Polygon<T> {
let mut simplified =
Expand All @@ -619,7 +619,7 @@ where

impl<T> SimplifyVwPreserve<T> for MultiPolygon<T>
where
T: CoordFloat + RTreeNum + HasKernel,
T: GeoFloat + RTreeNum,
{
fn simplify_vw_preserve(&self, epsilon: &T) -> MultiPolygon<T> {
MultiPolygon::new(
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/sweep/line_or_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ mod tests {
use geo_types::{Coord, LineString};
use wkt::ToWkt;

use crate::{GeoFloat, GeoNum, HasKernel, Kernel};
use crate::{GeoFloat, GeoNum, Kernel};

use super::LineOrPoint;

Expand Down Expand Up @@ -390,11 +390,11 @@ mod tests {

eprintln!(
"pred: {:?}",
<f64 as HasKernel>::Ker::orient2d(pt_8, pt_7, pt_17)
<f64 as GeoNum>::Ker::orient2d(pt_8, pt_7, pt_17)
);
eprintln!(
"pred: {:?}",
<f64 as HasKernel>::Ker::orient2d(pt_8, pt_14, pt_16)
<f64 as GeoNum>::Ker::orient2d(pt_8, pt_14, pt_16)
);
}
}
10 changes: 5 additions & 5 deletions geo/src/algorithm/sweep/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ impl<T: GeoNum> std::fmt::Debug for SweepPoint<T> {
/// coordinate.
impl<T: GeoNum> PartialOrd for SweepPoint<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match self.0.x.partial_cmp(&other.0.x) {
Some(Ordering::Equal) => self.0.y.partial_cmp(&other.0.y),
o => o,
}
Some(self.cmp(other))
}
}

/// Derive `Ord` from `PartialOrd` and expect to not fail.
impl<T: GeoNum> Ord for SweepPoint<T> {
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap()
match self.0.x.total_cmp(&other.0.x) {
Ordering::Equal => self.0.y.total_cmp(&other.0.y),
o => o,
}
}
}

Expand Down
Loading

0 comments on commit e0f4b6a

Please sign in to comment.