diff --git a/geo-types/src/arbitrary.rs b/geo-types/src/arbitrary.rs index 40f454b72..6b8d3142e 100644 --- a/geo-types/src/arbitrary.rs +++ b/geo-types/src/arbitrary.rs @@ -14,7 +14,7 @@ impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for Point { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - u.arbitrary::>().map(Point) + u.arbitrary::>().map(Self) } } @@ -26,7 +26,7 @@ impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for return Err(arbitrary::Error::IncorrectFormat); } - Ok(LineString(coords)) + Ok(Self(coords)) } fn size_hint(_depth: usize) -> (usize, Option) { @@ -45,19 +45,19 @@ impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for MultiPoint { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - u.arbitrary::>>().map(MultiPoint) + u.arbitrary::>>().map(Self) } } impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for MultiLineString { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - u.arbitrary::>>().map(MultiLineString) + u.arbitrary::>>().map(Self) } } impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for MultiPolygon { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - u.arbitrary::>>().map(MultiPolygon) + u.arbitrary::>>().map(Self) } } @@ -80,7 +80,7 @@ impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for impl<'a, T: arbitrary::Arbitrary<'a> + CoordFloat> arbitrary::Arbitrary<'a> for Triangle { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - Ok(Triangle( + Ok(Self( u.arbitrary::>()?, u.arbitrary::>()?, u.arbitrary::>()?, diff --git a/geo-types/src/coordinate.rs b/geo-types/src/coordinate.rs index 8196c8161..c06350285 100644 --- a/geo-types/src/coordinate.rs +++ b/geo-types/src/coordinate.rs @@ -110,9 +110,9 @@ impl Neg for Coordinate where T: CoordNum + Neg, { - type Output = Coordinate; + type Output = Self; - fn neg(self) -> Coordinate { + fn neg(self) -> Self { (-self.x, -self.y).into() } } @@ -132,9 +132,9 @@ where /// assert_eq!(sum.y, 5.0); /// ``` impl Add for Coordinate { - type Output = Coordinate; + type Output = Self; - fn add(self, rhs: Coordinate) -> Coordinate { + fn add(self, rhs: Self) -> Self { (self.x + rhs.x, self.y + rhs.y).into() } } @@ -154,9 +154,9 @@ impl Add for Coordinate { /// assert_eq!(diff.y, 0.); /// ``` impl Sub for Coordinate { - type Output = Coordinate; + type Output = Self; - fn sub(self, rhs: Coordinate) -> Coordinate { + fn sub(self, rhs: Self) -> Self { (self.x - rhs.x, self.y - rhs.y).into() } } @@ -175,9 +175,9 @@ impl Sub for Coordinate { /// assert_eq!(q.y, 10.0); /// ``` impl Mul for Coordinate { - type Output = Coordinate; + type Output = Self; - fn mul(self, rhs: T) -> Coordinate { + fn mul(self, rhs: T) -> Self { (self.x * rhs, self.y * rhs).into() } } @@ -196,9 +196,9 @@ impl Mul for Coordinate { /// assert_eq!(q.y, 2.5); /// ``` impl Div for Coordinate { - type Output = Coordinate; + type Output = Self; - fn div(self, rhs: T) -> Coordinate { + fn div(self, rhs: T) -> Self { (self.x / rhs, self.y / rhs).into() } } diff --git a/geo-types/src/geometry.rs b/geo-types/src/geometry.rs index 330fd7662..b14be511d 100644 --- a/geo-types/src/geometry.rs +++ b/geo-types/src/geometry.rs @@ -40,49 +40,49 @@ pub enum Geometry { } impl From> for Geometry { - fn from(x: Point) -> Geometry { + fn from(x: Point) -> Self { Geometry::Point(x) } } impl From> for Geometry { - fn from(x: Line) -> Geometry { + fn from(x: Line) -> Self { Geometry::Line(x) } } impl From> for Geometry { - fn from(x: LineString) -> Geometry { + fn from(x: LineString) -> Self { Geometry::LineString(x) } } impl From> for Geometry { - fn from(x: Polygon) -> Geometry { + fn from(x: Polygon) -> Self { Geometry::Polygon(x) } } impl From> for Geometry { - fn from(x: MultiPoint) -> Geometry { + fn from(x: MultiPoint) -> Self { Geometry::MultiPoint(x) } } impl From> for Geometry { - fn from(x: MultiLineString) -> Geometry { + fn from(x: MultiLineString) -> Self { Geometry::MultiLineString(x) } } impl From> for Geometry { - fn from(x: MultiPolygon) -> Geometry { + fn from(x: MultiPolygon) -> Self { Geometry::MultiPolygon(x) } } impl From> for Geometry { - fn from(x: Rect) -> Geometry { + fn from(x: Rect) -> Self { Geometry::Rect(x) } } impl From> for Geometry { - fn from(x: Triangle) -> Geometry { + fn from(x: Triangle) -> Self { Geometry::Triangle(x) } } diff --git a/geo-types/src/geometry_collection.rs b/geo-types/src/geometry_collection.rs index 810c662d5..da022b809 100644 --- a/geo-types/src/geometry_collection.rs +++ b/geo-types/src/geometry_collection.rs @@ -77,13 +77,13 @@ pub struct GeometryCollection(pub Vec>); // todo: consider adding Default as a CoordNum requirement impl Default for GeometryCollection { fn default() -> Self { - GeometryCollection(Vec::new()) + Self(Vec::new()) } } impl GeometryCollection { /// Return an empty GeometryCollection - pub fn new() -> GeometryCollection { + pub fn new() -> Self { GeometryCollection::default() } @@ -102,14 +102,14 @@ impl GeometryCollection { /// GeometryCollection impl>> From for GeometryCollection { fn from(x: IG) -> Self { - GeometryCollection(vec![x.into()]) + Self(vec![x.into()]) } } /// Collect Geometries (or what can be converted to a Geometry) into a GeometryCollection impl>> FromIterator for GeometryCollection { fn from_iter>(iter: I) -> Self { - GeometryCollection(iter.into_iter().map(|g| g.into()).collect()) + Self(iter.into_iter().map(|g| g.into()).collect()) } } diff --git a/geo-types/src/line.rs b/geo-types/src/line.rs index be1e8fa94..f1feb4b10 100644 --- a/geo-types/src/line.rs +++ b/geo-types/src/line.rs @@ -29,11 +29,11 @@ impl Line { /// assert_eq!(line.start, coord! { x: 0., y: 0. }); /// assert_eq!(line.end, coord! { x: 1., y: 2. }); /// ``` - pub fn new(start: C, end: C) -> Line + pub fn new(start: C, end: C) -> Self where C: Into>, { - Line { + Self { start: start.into(), end: end.into(), } @@ -156,7 +156,7 @@ impl Line { } impl From<[(T, T); 2]> for Line { - fn from(coord: [(T, T); 2]) -> Line { + fn from(coord: [(T, T); 2]) -> Self { Line::new(coord[0], coord[1]) } } diff --git a/geo-types/src/line_string.rs b/geo-types/src/line_string.rs index dce624064..dd7a3cc1e 100644 --- a/geo-types/src/line_string.rs +++ b/geo-types/src/line_string.rs @@ -333,20 +333,20 @@ impl LineString { /// Turn a [`Vec`] of [`Point`]-like objects into a [`LineString`]. impl>> From> for LineString { fn from(v: Vec) -> Self { - LineString(v.into_iter().map(|c| c.into()).collect()) + Self(v.into_iter().map(|c| c.into()).collect()) } } impl From> for LineString { fn from(line: Line) -> Self { - LineString(vec![line.start, line.end]) + Self(vec![line.start, line.end]) } } /// Turn an iterator of [`Point`]-like objects into a [`LineString`]. impl>> FromIterator for LineString { fn from_iter>(iter: I) -> Self { - LineString(iter.into_iter().map(|c| c.into()).collect()) + Self(iter.into_iter().map(|c| c.into()).collect()) } } diff --git a/geo-types/src/multi_line_string.rs b/geo-types/src/multi_line_string.rs index 9d4e7b77e..9ea620a79 100644 --- a/geo-types/src/multi_line_string.rs +++ b/geo-types/src/multi_line_string.rs @@ -64,13 +64,13 @@ impl MultiLineString { impl>> From for MultiLineString { fn from(ls: ILS) -> Self { - MultiLineString(vec![ls.into()]) + Self(vec![ls.into()]) } } impl>> FromIterator for MultiLineString { fn from_iter>(iter: I) -> Self { - MultiLineString(iter.into_iter().map(|ls| ls.into()).collect()) + Self(iter.into_iter().map(|ls| ls.into()).collect()) } } diff --git a/geo-types/src/multi_point.rs b/geo-types/src/multi_point.rs index 88e944aed..df9af3430 100644 --- a/geo-types/src/multi_point.rs +++ b/geo-types/src/multi_point.rs @@ -35,23 +35,23 @@ pub struct MultiPoint(pub Vec>); impl>> From for MultiPoint { /// Convert a single `Point` (or something which can be converted to a `Point`) into a /// one-member `MultiPoint` - fn from(x: IP) -> MultiPoint { - MultiPoint(vec![x.into()]) + fn from(x: IP) -> Self { + Self(vec![x.into()]) } } impl>> From> for MultiPoint { /// Convert a `Vec` of `Points` (or `Vec` of things which can be converted to a `Point`) into a /// `MultiPoint`. - fn from(v: Vec) -> MultiPoint { - MultiPoint(v.into_iter().map(|p| p.into()).collect()) + fn from(v: Vec) -> Self { + Self(v.into_iter().map(|p| p.into()).collect()) } } impl>> FromIterator for MultiPoint { /// Collect the results of a `Point` iterator into a `MultiPoint` fn from_iter>(iter: I) -> Self { - MultiPoint(iter.into_iter().map(|p| p.into()).collect()) + Self(iter.into_iter().map(|p| p.into()).collect()) } } diff --git a/geo-types/src/multi_polygon.rs b/geo-types/src/multi_polygon.rs index 253d28a16..6a1d40f7b 100644 --- a/geo-types/src/multi_polygon.rs +++ b/geo-types/src/multi_polygon.rs @@ -31,19 +31,19 @@ pub struct MultiPolygon(pub Vec>); impl>> From for MultiPolygon { fn from(x: IP) -> Self { - MultiPolygon(vec![x.into()]) + Self(vec![x.into()]) } } impl>> From> for MultiPolygon { fn from(x: Vec) -> Self { - MultiPolygon(x.into_iter().map(|p| p.into()).collect()) + Self(x.into_iter().map(|p| p.into()).collect()) } } impl>> FromIterator for MultiPolygon { fn from_iter>(iter: I) -> Self { - MultiPolygon(iter.into_iter().map(|p| p.into()).collect()) + Self(iter.into_iter().map(|p| p.into()).collect()) } } diff --git a/geo-types/src/point.rs b/geo-types/src/point.rs index 5c959d82d..4844a39a1 100644 --- a/geo-types/src/point.rs +++ b/geo-types/src/point.rs @@ -31,19 +31,19 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssi pub struct Point(pub Coordinate); impl From> for Point { - fn from(x: Coordinate) -> Point { + fn from(x: Coordinate) -> Self { Point(x) } } impl From<(T, T)> for Point { - fn from(coords: (T, T)) -> Point { + fn from(coords: (T, T)) -> Self { Point::new(coords.0, coords.1) } } impl From<[T; 2]> for Point { - fn from(coords: [T; 2]) -> Point { + fn from(coords: [T; 2]) -> Self { Point::new(coords[0], coords[1]) } } @@ -73,7 +73,7 @@ impl Point { /// assert_eq!(p.x(), 1.234); /// assert_eq!(p.y(), 2.345); /// ``` - pub fn new(x: T, y: T) -> Point { + pub fn new(x: T, y: T) -> Self { point! { x: x, y: y } } @@ -104,7 +104,7 @@ impl Point { /// /// assert_eq!(p.x(), 9.876); /// ``` - pub fn set_x(&mut self, x: T) -> &mut Point { + pub fn set_x(&mut self, x: T) -> &mut Self { self.0.x = x; self } @@ -136,7 +136,7 @@ impl Point { /// /// assert_eq!(p.y(), 9.876); /// ``` - pub fn set_y(&mut self, y: T) -> &mut Point { + pub fn set_y(&mut self, y: T) -> &mut Self { self.0.y = y; self } @@ -187,7 +187,7 @@ impl Point { /// assert_eq!(p.x(), 9.876); /// ``` #[deprecated = "use `Point::set_x` instead, it's less ambiguous"] - pub fn set_lng(&mut self, lng: T) -> &mut Point { + pub fn set_lng(&mut self, lng: T) -> &mut Self { self.set_x(lng) } @@ -220,7 +220,7 @@ impl Point { /// assert_eq!(p.y(), 9.876); /// ``` #[deprecated = "use `Point::set_y` instead, it's less ambiguous"] - pub fn set_lat(&mut self, lat: T) -> &mut Point { + pub fn set_lat(&mut self, lat: T) -> &mut Self { self.set_y(lat) } } @@ -239,7 +239,7 @@ impl Point { /// /// assert_eq!(dot, 5.25); /// ``` - pub fn dot(self, other: Point) -> T { + pub fn dot(self, other: Self) -> T { self.x() * other.x() + self.y() * other.y() } @@ -260,7 +260,7 @@ impl Point { /// /// assert_eq!(cross, 2.0) /// ``` - pub fn cross_prod(self, point_b: Point, point_c: Point) -> T { + pub fn cross_prod(self, point_b: Self, point_c: Self) -> T { (point_b.x() - self.x()) * (point_c.y() - self.y()) - (point_b.y() - self.y()) * (point_c.x() - self.x()) } @@ -278,7 +278,7 @@ impl Point { /// assert_eq!(x.round(), 71.0); /// assert_eq!(y.round(), 134.0); /// ``` - pub fn to_degrees(self) -> Point { + pub fn to_degrees(self) -> Self { let (x, y) = self.x_y(); let x = x.to_degrees(); let y = y.to_degrees(); @@ -296,7 +296,7 @@ impl Point { /// assert_eq!(x.round(), 3.0); /// assert_eq!(y.round(), 6.0); /// ``` - pub fn to_radians(self) -> Point { + pub fn to_radians(self) -> Self { let (x, y) = self.x_y(); let x = x.to_radians(); let y = y.to_radians(); @@ -308,7 +308,7 @@ impl Neg for Point where T: CoordNum + Neg, { - type Output = Point; + type Output = Self; /// Returns a point with the x and y components negated. /// @@ -322,13 +322,13 @@ where /// assert_eq!(p.x(), 1.25); /// assert_eq!(p.y(), -2.5); /// ``` - fn neg(self) -> Point { + fn neg(self) -> Self::Output { Point(-self.0) } } impl Add for Point { - type Output = Point; + type Output = Self; /// Add a point to the given point. /// @@ -342,7 +342,7 @@ impl Add for Point { /// assert_eq!(p.x(), 2.75); /// assert_eq!(p.y(), 5.0); /// ``` - fn add(self, rhs: Point) -> Point { + fn add(self, rhs: Self) -> Self::Output { Point(self.0 + rhs.0) } } @@ -361,13 +361,13 @@ impl AddAssign for Point { /// assert_eq!(p.x(), 2.75); /// assert_eq!(p.y(), 5.0); /// ``` - fn add_assign(&mut self, rhs: Point) { + fn add_assign(&mut self, rhs: Self) { self.0 = self.0 + rhs.0; } } impl Sub for Point { - type Output = Point; + type Output = Self; /// Subtract a point from the given point. /// @@ -381,7 +381,7 @@ impl Sub for Point { /// assert_eq!(p.x(), -0.25); /// assert_eq!(p.y(), 0.5); /// ``` - fn sub(self, rhs: Point) -> Point { + fn sub(self, rhs: Self) -> Self::Output { Point(self.0 - rhs.0) } } @@ -400,13 +400,13 @@ impl SubAssign for Point { /// assert_eq!(p.x(), -0.25); /// assert_eq!(p.y(), 0.0); /// ``` - fn sub_assign(&mut self, rhs: Point) { + fn sub_assign(&mut self, rhs: Self) { self.0 = self.0 - rhs.0; } } impl Mul for Point { - type Output = Point; + type Output = Self; /// Scaler multiplication of a point /// @@ -420,7 +420,7 @@ impl Mul for Point { /// assert_eq!(p.x(), 4.0); /// assert_eq!(p.y(), 6.0); /// ``` - fn mul(self, rhs: T) -> Point { + fn mul(self, rhs: T) -> Self::Output { Point(self.0 * rhs) } } @@ -445,7 +445,7 @@ impl MulAssign for Point { } impl Div for Point { - type Output = Point; + type Output = Self; /// Scaler division of a point /// @@ -459,7 +459,7 @@ impl Div for Point { /// assert_eq!(p.x(), 1.0); /// assert_eq!(p.y(), 1.5); /// ``` - fn div(self, rhs: T) -> Point { + fn div(self, rhs: T) -> Self::Output { Point(self.0 / rhs) } } diff --git a/geo-types/src/polygon.rs b/geo-types/src/polygon.rs index e867a5bff..104e183f4 100644 --- a/geo-types/src/polygon.rs +++ b/geo-types/src/polygon.rs @@ -122,12 +122,12 @@ impl Polygon { /// &LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.),]) /// ); /// ``` - pub fn new(mut exterior: LineString, mut interiors: Vec>) -> Polygon { + pub fn new(mut exterior: LineString, mut interiors: Vec>) -> Self { exterior.close(); for interior in &mut interiors { interior.close(); } - Polygon { + Self { exterior, interiors, } @@ -440,7 +440,7 @@ impl Polygon { } impl From> for Polygon { - fn from(r: Rect) -> Polygon { + fn from(r: Rect) -> Self { Polygon::new( vec![ (r.min().x, r.min().y), @@ -456,7 +456,7 @@ impl From> for Polygon { } impl From> for Polygon { - fn from(t: Triangle) -> Polygon { + fn from(t: Triangle) -> Self { Polygon::new(vec![t.0, t.1, t.2, t.0].into(), Vec::new()) } } diff --git a/geo-types/src/triangle.rs b/geo-types/src/triangle.rs index 7dd3ae50f..4d1ec8987 100644 --- a/geo-types/src/triangle.rs +++ b/geo-types/src/triangle.rs @@ -53,8 +53,8 @@ impl Triangle { } impl> + Copy, T: CoordNum> From<[IC; 3]> for Triangle { - fn from(array: [IC; 3]) -> Triangle { - Triangle(array[0].into(), array[1].into(), array[2].into()) + fn from(array: [IC; 3]) -> Self { + Self(array[0].into(), array[1].into(), array[2].into()) } }