Skip to content

Commit

Permalink
Merge #924
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and frewsxcv authored Nov 8, 2022
2 parents 14e306d + 8d7aa00 commit 3b0d573
Show file tree
Hide file tree
Showing 92 changed files with 701 additions and 798 deletions.
4 changes: 2 additions & 2 deletions geo-bool-ops-benches/benches/utils/bops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]

use geo_types::{Coordinate, LineString, MultiPolygon, Polygon};
use geo_types::{Coord, LineString, MultiPolygon, Polygon};

pub fn convert_poly(poly: &Polygon<f64>) -> gt_prev::Polygon<f64> {
let ext: Vec<_> = poly
Expand All @@ -21,7 +21,7 @@ pub fn convert_back_poly(poly: &gt_prev::Polygon<f64>) -> Polygon<f64> {
.exterior()
.0
.iter()
.map(|c| Coordinate { x: c.x, y: c.y })
.map(|c| Coord { x: c.x, y: c.y })
.collect();
Polygon::new(LineString(ext), vec![])
}
Expand Down
4 changes: 2 additions & 2 deletions geo-postgis/src/to_postgis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use geo_types::{
Coordinate, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
Coord, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon,
};
use postgis::ewkb;
Expand All @@ -19,7 +19,7 @@ pub trait ToPostgis<T> {
}
}

impl ToPostgis<ewkb::Point> for Coordinate {
impl ToPostgis<ewkb::Point> for Coord {
fn to_postgis_with_srid(&self, srid: Option<i32>) -> ewkb::Point {
ewkb::Point::new(self.x, self.y, srid)
}
Expand Down
1 change: 1 addition & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Rename `Coordinate` to `Coord`; add deprecated `Coordinate` that is an alias for `Coord`
* Pin `arbitrary` version to 1.1.3 until our MSRV catches up with its latest release
* Add `point.x_mut()` and `point.y_mut()` methods on `Points`
* Changed license field to [SPDX 2.1 license expression](https://spdx.dev/spdx-specification-21-web-version/#h.jxpfx0ykyb60)
Expand Down
18 changes: 9 additions & 9 deletions geo-types/src/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
CoordFloat, Coordinate, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint,
Coord, CoordFloat, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon, Rect, Triangle,
};
use std::mem;

impl<'a, T> arbitrary::Arbitrary<'a> for Coordinate<T>
impl<'a, T> arbitrary::Arbitrary<'a> for Coord<T>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
{
Expand All @@ -21,7 +21,7 @@ where
T: arbitrary::Arbitrary<'a> + CoordFloat,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary::<Coordinate<T>>().map(Self)
u.arbitrary::<Coord<T>>().map(Self)
}
}

Expand All @@ -30,7 +30,7 @@ where
T: arbitrary::Arbitrary<'a> + CoordFloat,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let coords = u.arbitrary::<Vec<Coordinate<T>>>()?;
let coords = u.arbitrary::<Vec<Coord<T>>>()?;
if coords.len() < 2 {
Err(arbitrary::Error::IncorrectFormat)
} else {
Expand Down Expand Up @@ -97,8 +97,8 @@ where
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::new(
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coord<T>>()?,
u.arbitrary::<Coord<T>>()?,
))
}
}
Expand All @@ -109,9 +109,9 @@ where
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self(
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coord<T>>()?,
u.arbitrary::<Coord<T>>()?,
u.arbitrary::<Coord<T>>()?,
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
///
/// Unlike `Point` (which in the future may contain additional information such
/// as an envelope, a precision model, and spatial reference system
/// information), a `Coordinate` only contains ordinate values and accessor
/// information), a `Coord` only contains ordinate values and accessor
/// methods.
///
/// This type implements the [vector space] operations:
Expand All @@ -25,12 +25,15 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
/// [vector space]: //en.wikipedia.org/wiki/Vector_space
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Coordinate<T: CoordNum = f64> {
pub struct Coord<T: CoordNum = f64> {
pub x: T,
pub y: T,
}

impl<T: CoordNum> From<(T, T)> for Coordinate<T> {
#[deprecated(note = "Renamed to `geo_types::Coord` (or `geo::Coord`)")]
pub type Coordinate<T = f64> = Coord<T>;

impl<T: CoordNum> From<(T, T)> for Coord<T> {
#[inline]
fn from(coords: (T, T)) -> Self {
coord! {
Expand All @@ -40,7 +43,7 @@ impl<T: CoordNum> From<(T, T)> for Coordinate<T> {
}
}

impl<T: CoordNum> From<[T; 2]> for Coordinate<T> {
impl<T: CoordNum> From<[T; 2]> for Coord<T> {
#[inline]
fn from(coords: [T; 2]) -> Self {
coord! {
Expand All @@ -50,7 +53,7 @@ impl<T: CoordNum> From<[T; 2]> for Coordinate<T> {
}
}

impl<T: CoordNum> From<Point<T>> for Coordinate<T> {
impl<T: CoordNum> From<Point<T>> for Coord<T> {
#[inline]
fn from(point: Point<T>) -> Self {
coord! {
Expand All @@ -60,21 +63,21 @@ impl<T: CoordNum> From<Point<T>> for Coordinate<T> {
}
}

impl<T: CoordNum> From<Coordinate<T>> for (T, T) {
impl<T: CoordNum> From<Coord<T>> for (T, T) {
#[inline]
fn from(coord: Coordinate<T>) -> Self {
fn from(coord: Coord<T>) -> Self {
(coord.x, coord.y)
}
}

impl<T: CoordNum> From<Coordinate<T>> for [T; 2] {
impl<T: CoordNum> From<Coord<T>> for [T; 2] {
#[inline]
fn from(coord: Coordinate<T>) -> Self {
fn from(coord: Coord<T>) -> Self {
[coord.x, coord.y]
}
}

impl<T: CoordNum> Coordinate<T> {
impl<T: CoordNum> Coord<T> {
/// Returns a tuple that contains the x/horizontal & y/vertical component of the coordinate.
///
/// # Examples
Expand Down Expand Up @@ -112,7 +115,7 @@ use std::ops::{Add, Div, Mul, Neg, Sub};
/// assert_eq!(q.x, -p.x);
/// assert_eq!(q.y, -p.y);
/// ```
impl<T> Neg for Coordinate<T>
impl<T> Neg for Coord<T>
where
T: CoordNum + Neg<Output = T>,
{
Expand Down Expand Up @@ -141,7 +144,7 @@ where
/// assert_eq!(sum.x, 2.75);
/// assert_eq!(sum.y, 5.0);
/// ```
impl<T: CoordNum> Add for Coordinate<T> {
impl<T: CoordNum> Add for Coord<T> {
type Output = Self;

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

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

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

#[inline]
Expand All @@ -235,15 +238,15 @@ use num_traits::Zero;
/// # Examples
///
/// ```
/// use geo_types::Coordinate;
/// use geo_types::Coord;
/// use num_traits::Zero;
///
/// let p: Coordinate = Zero::zero();
/// let p: Coord = Zero::zero();
///
/// assert_eq!(p.x, 0.);
/// assert_eq!(p.y, 0.);
/// ```
impl<T: CoordNum> Coordinate<T> {
impl<T: CoordNum> Coord<T> {
#[inline]
pub fn zero() -> Self {
coord! {
Expand All @@ -253,7 +256,7 @@ impl<T: CoordNum> Coordinate<T> {
}
}

impl<T: CoordNum> Zero for Coordinate<T> {
impl<T: CoordNum> Zero for Coord<T> {
#[inline]
fn zero() -> Self {
Self::zero()
Expand All @@ -265,7 +268,7 @@ impl<T: CoordNum> Zero for Coordinate<T> {
}

#[cfg(any(feature = "approx", test))]
impl<T: CoordNum + AbsDiffEq> AbsDiffEq for Coordinate<T>
impl<T: CoordNum + AbsDiffEq> AbsDiffEq for Coord<T>
where
T::Epsilon: Copy,
{
Expand All @@ -283,7 +286,7 @@ where
}

#[cfg(any(feature = "approx", test))]
impl<T: CoordNum + RelativeEq> RelativeEq for Coordinate<T>
impl<T: CoordNum + RelativeEq> RelativeEq for Coord<T>
where
T::Epsilon: Copy,
{
Expand All @@ -300,7 +303,7 @@ where
}

#[cfg(any(feature = "approx", test))]
impl<T: CoordNum + UlpsEq> UlpsEq for Coordinate<T>
impl<T: CoordNum + UlpsEq> UlpsEq for Coord<T>
where
T::Epsilon: Copy,
{
Expand All @@ -317,7 +320,7 @@ where
}

#[cfg(feature = "rstar_0_8")]
impl<T> ::rstar_0_8::Point for Coordinate<T>
impl<T> ::rstar_0_8::Point for Coord<T>
where
T: ::num_traits::Float + ::rstar_0_8::RTreeNum,
{
Expand Down Expand Up @@ -353,7 +356,7 @@ where
}

#[cfg(feature = "rstar_0_9")]
impl<T> ::rstar_0_9::Point for Coordinate<T>
impl<T> ::rstar_0_9::Point for Coord<T>
where
T: ::num_traits::Float + ::rstar_0_9::RTreeNum,
{
Expand Down
12 changes: 6 additions & 6 deletions geo-types/src/geometry/line.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{CoordNum, Coordinate, Point};
use crate::{Coord, CoordNum, Point};
#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};

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

impl<T: CoordNum> Line<T> {
Expand All @@ -31,7 +31,7 @@ impl<T: CoordNum> Line<T> {
/// ```
pub fn new<C>(start: C, end: C) -> Self
where
C: Into<Coordinate<T>>,
C: Into<Coord<T>>,
{
Self {
start: start.into(),
Expand All @@ -40,7 +40,7 @@ impl<T: CoordNum> Line<T> {
}

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

Expand Down
Loading

0 comments on commit 3b0d573

Please sign in to comment.