Skip to content

Commit 3b0d573

Browse files
bors[bot]frewsxcv
andauthored
Merge #924
924: Introduce `Coord`, deprecate `Coordinate` r=michaelkirk a=frewsxcv - [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/main/CODE_OF_CONDUCT.md). - [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users. --- When we're ready :) Fixes #540 Co-authored-by: Corey Farwell <[email protected]>
2 parents 14e306d + 8d7aa00 commit 3b0d573

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+701
-798
lines changed

geo-bool-ops-benches/benches/utils/bops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(dead_code)]
22

3-
use geo_types::{Coordinate, LineString, MultiPolygon, Polygon};
3+
use geo_types::{Coord, LineString, MultiPolygon, Polygon};
44

55
pub fn convert_poly(poly: &Polygon<f64>) -> gt_prev::Polygon<f64> {
66
let ext: Vec<_> = poly
@@ -21,7 +21,7 @@ pub fn convert_back_poly(poly: &gt_prev::Polygon<f64>) -> Polygon<f64> {
2121
.exterior()
2222
.0
2323
.iter()
24-
.map(|c| Coordinate { x: c.x, y: c.y })
24+
.map(|c| Coord { x: c.x, y: c.y })
2525
.collect();
2626
Polygon::new(LineString(ext), vec![])
2727
}

geo-postgis/src/to_postgis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use geo_types::{
2-
Coordinate, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
2+
Coord, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
33
MultiPolygon, Point, Polygon,
44
};
55
use postgis::ewkb;
@@ -19,7 +19,7 @@ pub trait ToPostgis<T> {
1919
}
2020
}
2121

22-
impl ToPostgis<ewkb::Point> for Coordinate {
22+
impl ToPostgis<ewkb::Point> for Coord {
2323
fn to_postgis_with_srid(&self, srid: Option<i32>) -> ewkb::Point {
2424
ewkb::Point::new(self.x, self.y, srid)
2525
}

geo-types/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
* Rename `Coordinate` to `Coord`; add deprecated `Coordinate` that is an alias for `Coord`
56
* Pin `arbitrary` version to 1.1.3 until our MSRV catches up with its latest release
67
* Add `point.x_mut()` and `point.y_mut()` methods on `Points`
78
* Changed license field to [SPDX 2.1 license expression](https://spdx.dev/spdx-specification-21-web-version/#h.jxpfx0ykyb60)

geo-types/src/arbitrary.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::{
2-
CoordFloat, Coordinate, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint,
2+
Coord, CoordFloat, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint,
33
MultiPolygon, Point, Polygon, Rect, Triangle,
44
};
55
use std::mem;
66

7-
impl<'a, T> arbitrary::Arbitrary<'a> for Coordinate<T>
7+
impl<'a, T> arbitrary::Arbitrary<'a> for Coord<T>
88
where
99
T: arbitrary::Arbitrary<'a> + CoordFloat,
1010
{
@@ -21,7 +21,7 @@ where
2121
T: arbitrary::Arbitrary<'a> + CoordFloat,
2222
{
2323
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
24-
u.arbitrary::<Coordinate<T>>().map(Self)
24+
u.arbitrary::<Coord<T>>().map(Self)
2525
}
2626
}
2727

@@ -30,7 +30,7 @@ where
3030
T: arbitrary::Arbitrary<'a> + CoordFloat,
3131
{
3232
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
33-
let coords = u.arbitrary::<Vec<Coordinate<T>>>()?;
33+
let coords = u.arbitrary::<Vec<Coord<T>>>()?;
3434
if coords.len() < 2 {
3535
Err(arbitrary::Error::IncorrectFormat)
3636
} else {
@@ -97,8 +97,8 @@ where
9797
{
9898
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
9999
Ok(Self::new(
100-
u.arbitrary::<Coordinate<T>>()?,
101-
u.arbitrary::<Coordinate<T>>()?,
100+
u.arbitrary::<Coord<T>>()?,
101+
u.arbitrary::<Coord<T>>()?,
102102
))
103103
}
104104
}
@@ -109,9 +109,9 @@ where
109109
{
110110
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
111111
Ok(Self(
112-
u.arbitrary::<Coordinate<T>>()?,
113-
u.arbitrary::<Coordinate<T>>()?,
114-
u.arbitrary::<Coordinate<T>>()?,
112+
u.arbitrary::<Coord<T>>()?,
113+
u.arbitrary::<Coord<T>>()?,
114+
u.arbitrary::<Coord<T>>()?,
115115
))
116116
}
117117
}

geo-types/src/geometry/coordinate.rs renamed to geo-types/src/geometry/coord.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
88
///
99
/// Unlike `Point` (which in the future may contain additional information such
1010
/// as an envelope, a precision model, and spatial reference system
11-
/// information), a `Coordinate` only contains ordinate values and accessor
11+
/// information), a `Coord` only contains ordinate values and accessor
1212
/// methods.
1313
///
1414
/// This type implements the [vector space] operations:
@@ -25,12 +25,15 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
2525
/// [vector space]: //en.wikipedia.org/wiki/Vector_space
2626
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash, Default)]
2727
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28-
pub struct Coordinate<T: CoordNum = f64> {
28+
pub struct Coord<T: CoordNum = f64> {
2929
pub x: T,
3030
pub y: T,
3131
}
3232

33-
impl<T: CoordNum> From<(T, T)> for Coordinate<T> {
33+
#[deprecated(note = "Renamed to `geo_types::Coord` (or `geo::Coord`)")]
34+
pub type Coordinate<T = f64> = Coord<T>;
35+
36+
impl<T: CoordNum> From<(T, T)> for Coord<T> {
3437
#[inline]
3538
fn from(coords: (T, T)) -> Self {
3639
coord! {
@@ -40,7 +43,7 @@ impl<T: CoordNum> From<(T, T)> for Coordinate<T> {
4043
}
4144
}
4245

43-
impl<T: CoordNum> From<[T; 2]> for Coordinate<T> {
46+
impl<T: CoordNum> From<[T; 2]> for Coord<T> {
4447
#[inline]
4548
fn from(coords: [T; 2]) -> Self {
4649
coord! {
@@ -50,7 +53,7 @@ impl<T: CoordNum> From<[T; 2]> for Coordinate<T> {
5053
}
5154
}
5255

53-
impl<T: CoordNum> From<Point<T>> for Coordinate<T> {
56+
impl<T: CoordNum> From<Point<T>> for Coord<T> {
5457
#[inline]
5558
fn from(point: Point<T>) -> Self {
5659
coord! {
@@ -60,21 +63,21 @@ impl<T: CoordNum> From<Point<T>> for Coordinate<T> {
6063
}
6164
}
6265

63-
impl<T: CoordNum> From<Coordinate<T>> for (T, T) {
66+
impl<T: CoordNum> From<Coord<T>> for (T, T) {
6467
#[inline]
65-
fn from(coord: Coordinate<T>) -> Self {
68+
fn from(coord: Coord<T>) -> Self {
6669
(coord.x, coord.y)
6770
}
6871
}
6972

70-
impl<T: CoordNum> From<Coordinate<T>> for [T; 2] {
73+
impl<T: CoordNum> From<Coord<T>> for [T; 2] {
7174
#[inline]
72-
fn from(coord: Coordinate<T>) -> Self {
75+
fn from(coord: Coord<T>) -> Self {
7376
[coord.x, coord.y]
7477
}
7578
}
7679

77-
impl<T: CoordNum> Coordinate<T> {
80+
impl<T: CoordNum> Coord<T> {
7881
/// Returns a tuple that contains the x/horizontal & y/vertical component of the coordinate.
7982
///
8083
/// # Examples
@@ -112,7 +115,7 @@ use std::ops::{Add, Div, Mul, Neg, Sub};
112115
/// assert_eq!(q.x, -p.x);
113116
/// assert_eq!(q.y, -p.y);
114117
/// ```
115-
impl<T> Neg for Coordinate<T>
118+
impl<T> Neg for Coord<T>
116119
where
117120
T: CoordNum + Neg<Output = T>,
118121
{
@@ -141,7 +144,7 @@ where
141144
/// assert_eq!(sum.x, 2.75);
142145
/// assert_eq!(sum.y, 5.0);
143146
/// ```
144-
impl<T: CoordNum> Add for Coordinate<T> {
147+
impl<T: CoordNum> Add for Coord<T> {
145148
type Output = Self;
146149

147150
#[inline]
@@ -167,7 +170,7 @@ impl<T: CoordNum> Add for Coordinate<T> {
167170
/// assert_eq!(diff.x, 0.25);
168171
/// assert_eq!(diff.y, 0.);
169172
/// ```
170-
impl<T: CoordNum> Sub for Coordinate<T> {
173+
impl<T: CoordNum> Sub for Coord<T> {
171174
type Output = Self;
172175

173176
#[inline]
@@ -192,7 +195,7 @@ impl<T: CoordNum> Sub for Coordinate<T> {
192195
/// assert_eq!(q.x, 5.0);
193196
/// assert_eq!(q.y, 10.0);
194197
/// ```
195-
impl<T: CoordNum> Mul<T> for Coordinate<T> {
198+
impl<T: CoordNum> Mul<T> for Coord<T> {
196199
type Output = Self;
197200

198201
#[inline]
@@ -217,7 +220,7 @@ impl<T: CoordNum> Mul<T> for Coordinate<T> {
217220
/// assert_eq!(q.x, 1.25);
218221
/// assert_eq!(q.y, 2.5);
219222
/// ```
220-
impl<T: CoordNum> Div<T> for Coordinate<T> {
223+
impl<T: CoordNum> Div<T> for Coord<T> {
221224
type Output = Self;
222225

223226
#[inline]
@@ -235,15 +238,15 @@ use num_traits::Zero;
235238
/// # Examples
236239
///
237240
/// ```
238-
/// use geo_types::Coordinate;
241+
/// use geo_types::Coord;
239242
/// use num_traits::Zero;
240243
///
241-
/// let p: Coordinate = Zero::zero();
244+
/// let p: Coord = Zero::zero();
242245
///
243246
/// assert_eq!(p.x, 0.);
244247
/// assert_eq!(p.y, 0.);
245248
/// ```
246-
impl<T: CoordNum> Coordinate<T> {
249+
impl<T: CoordNum> Coord<T> {
247250
#[inline]
248251
pub fn zero() -> Self {
249252
coord! {
@@ -253,7 +256,7 @@ impl<T: CoordNum> Coordinate<T> {
253256
}
254257
}
255258

256-
impl<T: CoordNum> Zero for Coordinate<T> {
259+
impl<T: CoordNum> Zero for Coord<T> {
257260
#[inline]
258261
fn zero() -> Self {
259262
Self::zero()
@@ -265,7 +268,7 @@ impl<T: CoordNum> Zero for Coordinate<T> {
265268
}
266269

267270
#[cfg(any(feature = "approx", test))]
268-
impl<T: CoordNum + AbsDiffEq> AbsDiffEq for Coordinate<T>
271+
impl<T: CoordNum + AbsDiffEq> AbsDiffEq for Coord<T>
269272
where
270273
T::Epsilon: Copy,
271274
{
@@ -283,7 +286,7 @@ where
283286
}
284287

285288
#[cfg(any(feature = "approx", test))]
286-
impl<T: CoordNum + RelativeEq> RelativeEq for Coordinate<T>
289+
impl<T: CoordNum + RelativeEq> RelativeEq for Coord<T>
287290
where
288291
T::Epsilon: Copy,
289292
{
@@ -300,7 +303,7 @@ where
300303
}
301304

302305
#[cfg(any(feature = "approx", test))]
303-
impl<T: CoordNum + UlpsEq> UlpsEq for Coordinate<T>
306+
impl<T: CoordNum + UlpsEq> UlpsEq for Coord<T>
304307
where
305308
T::Epsilon: Copy,
306309
{
@@ -317,7 +320,7 @@ where
317320
}
318321

319322
#[cfg(feature = "rstar_0_8")]
320-
impl<T> ::rstar_0_8::Point for Coordinate<T>
323+
impl<T> ::rstar_0_8::Point for Coord<T>
321324
where
322325
T: ::num_traits::Float + ::rstar_0_8::RTreeNum,
323326
{
@@ -353,7 +356,7 @@ where
353356
}
354357

355358
#[cfg(feature = "rstar_0_9")]
356-
impl<T> ::rstar_0_9::Point for Coordinate<T>
359+
impl<T> ::rstar_0_9::Point for Coord<T>
357360
where
358361
T: ::num_traits::Float + ::rstar_0_9::RTreeNum,
359362
{

geo-types/src/geometry/line.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::{CoordNum, Coordinate, Point};
1+
use crate::{Coord, CoordNum, Point};
22
#[cfg(any(feature = "approx", test))]
33
use approx::{AbsDiffEq, RelativeEq};
44

55
/// A line segment made up of exactly two
6-
/// [`Coordinate`s](struct.Coordinate.html).
6+
/// [`Coord`]s.
77
///
88
/// # Semantics
99
///
@@ -12,8 +12,8 @@ use approx::{AbsDiffEq, RelativeEq};
1212
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
1313
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1414
pub struct Line<T: CoordNum = f64> {
15-
pub start: Coordinate<T>,
16-
pub end: Coordinate<T>,
15+
pub start: Coord<T>,
16+
pub end: Coord<T>,
1717
}
1818

1919
impl<T: CoordNum> Line<T> {
@@ -31,7 +31,7 @@ impl<T: CoordNum> Line<T> {
3131
/// ```
3232
pub fn new<C>(start: C, end: C) -> Self
3333
where
34-
C: Into<Coordinate<T>>,
34+
C: Into<Coord<T>>,
3535
{
3636
Self {
3737
start: start.into(),
@@ -40,7 +40,7 @@ impl<T: CoordNum> Line<T> {
4040
}
4141

4242
/// Calculate the difference in coordinates (Δx, Δy).
43-
pub fn delta(&self) -> Coordinate<T> {
43+
pub fn delta(&self) -> Coord<T> {
4444
self.end - self.start
4545
}
4646

0 commit comments

Comments
 (0)