Skip to content

Commit

Permalink
Merge pull request #109 from georust/mkirk/partial-eq
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk authored Sep 16, 2023
2 parents 1f88c38 + c9d1829 commit a5759db
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Unreleased

* Changed license field to [SPDX 2.1 license expression](https://spdx.dev/spdx-specification-21-web-version/#h.jxpfx0ykyb60)
* Bump min version of geo-types, and update geo_types::Coordinate to non-deprecated geo_types::Coord
* BREAKING: WktNum must implement PartialEq
* Implement PartialEq for Wkt

## 0.10.3 - 2022-06-22

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ keywords = ["geo", "geospatial", "wkt"]
edition = "2021"

[dependencies]
geo-types = { version = "0.7.4", optional = true }
geo-types = { version = "0.7.8", optional = true }
num-traits = "0.2"
serde = { version = "1.0", default-features = false, optional = true }
thiserror = "1.0.23"
log = "0.4.17"

[dev-dependencies]
criterion = { version = "0.2" }
criterion = "0.5.1"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"

Expand Down
8 changes: 4 additions & 4 deletions src/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ struct TryFromWktVisitor<T, G: TryFromWkt<T>> {
impl<T, G: TryFromWkt<T>> Default for TryFromWktVisitor<T, G> {
fn default() -> Self {
Self {
_marker_t: PhantomData::default(),
_marker_g: PhantomData::default(),
_marker_t: PhantomData,
_marker_g: PhantomData,
}
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ struct WktVisitor<T> {
impl<T> Default for WktVisitor<T> {
fn default() -> Self {
WktVisitor {
_marker: PhantomData::default(),
_marker: PhantomData,
}
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ struct GeometryVisitor<T> {
impl<T> Default for GeometryVisitor<T> {
fn default() -> Self {
GeometryVisitor {
_marker: PhantomData::default(),
_marker: PhantomData,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/geo_types_from_wkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ impl<T: CoordNum> TryFrom<Wkt<T>> for geo_types::GeometryCollection<T> {
}
}

impl<T> From<Coord<T>> for geo_types::Coordinate<T>
impl<T> From<Coord<T>> for geo_types::Coord<T>
where
T: CoordNum,
{
/// Convert from a WKT Coordinate to a [`geo_types::Coordinate`]
fn from(coord: Coord<T>) -> geo_types::Coordinate<T> {
fn from(coord: Coord<T>) -> geo_types::Coord<T> {
coord! { x: coord.x, y: coord.y }
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ where
let coords = line_string
.0
.into_iter()
.map(geo_types::Coordinate::from)
.map(geo_types::Coord::from)
.collect();

geo_types::LineString(coords)
Expand Down
22 changes: 11 additions & 11 deletions src/geo_types_to_wkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ where
}
}

fn g_point_to_w_coord<T>(g_point: &geo_types::Coordinate<T>) -> Coord<T>
fn g_point_to_w_coord<T>(g_point: &geo_types::Coord<T>) -> Coord<T>
where
T: CoordNum,
{
Expand All @@ -263,7 +263,7 @@ where
Point(Some(coord))
}

fn g_points_to_w_coords<T>(g_points: &[geo_types::Coordinate<T>]) -> Vec<Coord<T>>
fn g_points_to_w_coords<T>(g_points: &[geo_types::Coord<T>]) -> Vec<Coord<T>>
where
T: CoordNum,
{
Expand Down Expand Up @@ -293,11 +293,11 @@ fn g_linestring_to_w_linestring<T>(g_linestring: &geo_types::LineString<T>) -> L
where
T: CoordNum,
{
let &geo_types::LineString(ref g_points) = g_linestring;
let geo_types::LineString(g_points) = g_linestring;
g_points_to_w_linestring(g_points)
}

fn g_points_to_w_linestring<T>(g_coords: &[geo_types::Coordinate<T>]) -> LineString<T>
fn g_points_to_w_linestring<T>(g_coords: &[geo_types::Coord<T>]) -> LineString<T>
where
T: CoordNum,
{
Expand All @@ -311,7 +311,7 @@ where
{
let mut w_lines = vec![];
for g_line in g_lines {
let &geo_types::LineString(ref g_points) = g_line;
let geo_types::LineString(g_points) = g_line;
w_lines.push(g_points_to_w_linestring(g_points));
}
w_lines
Expand Down Expand Up @@ -342,14 +342,14 @@ where
let mut poly_lines = vec![];

// Outer
let &geo_types::LineString(ref outer_points) = outer_line;
let geo_types::LineString(outer_points) = outer_line;
if !outer_points.is_empty() {
poly_lines.push(g_points_to_w_linestring(outer_points));
}

// Inner
let inner = g_lines_to_w_lines(inner_lines);
poly_lines.extend(inner.into_iter());
poly_lines.extend(inner);

Polygon(poly_lines)
}
Expand All @@ -358,7 +358,7 @@ fn g_mpoint_to_w_mpoint<T>(g_mpoint: &geo_types::MultiPoint<T>) -> MultiPoint<T>
where
T: CoordNum,
{
let &geo_types::MultiPoint(ref g_points) = g_mpoint;
let geo_types::MultiPoint(g_points) = g_mpoint;
let w_points = g_points_to_w_points(g_points);
MultiPoint(w_points)
}
Expand All @@ -367,7 +367,7 @@ fn g_mline_to_w_mline<T>(g_mline: &geo_types::MultiLineString<T>) -> MultiLineSt
where
T: CoordNum,
{
let &geo_types::MultiLineString(ref g_lines) = g_mline;
let geo_types::MultiLineString(g_lines) = g_mline;
let w_lines = g_lines_to_w_lines(g_lines);
MultiLineString(w_lines)
}
Expand All @@ -387,7 +387,7 @@ fn g_mpolygon_to_w_mpolygon<T>(g_mpolygon: &geo_types::MultiPolygon<T>) -> Multi
where
T: CoordNum,
{
let &geo_types::MultiPolygon(ref g_polygons) = g_mpolygon;
let geo_types::MultiPolygon(g_polygons) = g_mpolygon;
let w_polygons = g_polygons_to_w_polygons(g_polygons);
MultiPolygon(w_polygons)
}
Expand All @@ -396,7 +396,7 @@ fn g_geocol_to_w_geocol<T>(g_geocol: &geo_types::GeometryCollection<T>) -> Geome
where
T: CoordNum,
{
let &geo_types::GeometryCollection(ref g_geoms) = g_geocol;
let geo_types::GeometryCollection(g_geoms) = g_geocol;
let mut w_geoms = vec![];
for g_geom in g_geoms {
let w_geom = g_geom_to_w_geom(g_geom);
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ pub use deserialize::geo_types::deserialize_geometry;
)]
pub use deserialize::geo_types::deserialize_point;

pub trait WktNum: Num + NumCast + PartialOrd + Copy + fmt::Debug {}
impl<T> WktNum for T where T: Num + NumCast + PartialOrd + Copy + fmt::Debug {}
pub trait WktNum: Num + NumCast + PartialOrd + PartialEq + Copy + fmt::Debug {}
impl<T> WktNum for T where T: Num + NumCast + PartialOrd + PartialEq + Copy + fmt::Debug {}

pub trait WktFloat: WktNum + Float {}
impl<T> WktFloat for T where T: WktNum + Float {}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
/// All supported WKT geometry [`types`]
pub enum Geometry<T>
where
Expand Down
2 changes: 1 addition & 1 deletion src/types/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{FromTokens, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Coord<T>
where
T: WktNum,
Expand Down
2 changes: 1 addition & 1 deletion src/types/geometrycollection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct GeometryCollection<T: WktNum>(pub Vec<Geometry<T>>);

impl<T> GeometryCollection<T>
Expand Down
2 changes: 1 addition & 1 deletion src/types/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct LineString<T: WktNum>(pub Vec<Coord<T>>);

impl<T> LineString<T>
Expand Down
2 changes: 1 addition & 1 deletion src/types/multilinestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct MultiLineString<T: WktNum>(pub Vec<LineString<T>>);

impl<T> MultiLineString<T>
Expand Down
2 changes: 1 addition & 1 deletion src/types/multipoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct MultiPoint<T: WktNum>(pub Vec<Point<T>>);

impl<T> MultiPoint<T>
Expand Down
2 changes: 1 addition & 1 deletion src/types/multipolygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct MultiPolygon<T: WktNum>(pub Vec<Polygon<T>>);

impl<T> MultiPolygon<T>
Expand Down
2 changes: 1 addition & 1 deletion src/types/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Point<T: WktNum>(pub Option<Coord<T>>);

impl<T> Point<T>
Expand Down
2 changes: 1 addition & 1 deletion src/types/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{FromTokens, Geometry, WktNum};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Polygon<T: WktNum>(pub Vec<LineString<T>>);

impl<T> Polygon<T>
Expand Down

0 comments on commit a5759db

Please sign in to comment.