Skip to content

Commit

Permalink
Merge georust#559
Browse files Browse the repository at this point in the history
559: Resolved all clippy issues. r=frewsxcv a=martinfrances107

This PR is in relation to 

georust#558

Naming things is hard ... 

there are a couple of new type names, such as 

RectChainIter<T> 

which people might object to .. I am happy to make changes.


Co-authored-by: Martin <martinfrances107@hotmail.com>
  • Loading branch information
bors[bot] and martinfrances107 committed Dec 6, 2020
2 parents a8ac14e + 35b5159 commit 8498785
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 27 deletions.
9 changes: 3 additions & 6 deletions geo-postgis/src/from_postgis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
.rings()
.map(|x| LineString::from_postgis(x))
.collect::<Vec<_>>();
if rings.len() == 0 {
if rings.is_empty() {
return None;
}
let exterior = rings.remove(0);
Expand Down Expand Up @@ -75,10 +75,7 @@ where
/// This implementation discards PostGIS polygons that don't convert
/// (return `None` when `from_postgis()` is called on them).
fn from_postgis(mp: &'a T) -> Self {
let ret = mp
.polygons()
.filter_map(|x| Option::from_postgis(x))
.collect();
let ret = mp.polygons().filter_map(Option::from_postgis).collect();
MultiPolygon(ret)
}
}
Expand All @@ -92,7 +89,7 @@ where
let geoms = gc
.geometries
.iter()
.filter_map(|x| Option::from_postgis(x))
.filter_map(Option::from_postgis)
.collect();
GeometryCollection(geoms)
}
Expand Down
6 changes: 6 additions & 0 deletions geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pub struct GeometryCollection<T>(pub Vec<Geometry<T>>)
where
T: CoordinateType;

impl<T: CoordinateType> Default for GeometryCollection<T> {
fn default() -> Self {
Self::new()
}
}

impl<T: CoordinateType> GeometryCollection<T> {
/// Return an empty GeometryCollection
pub fn new() -> GeometryCollection<T> {
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<T: CoordinateType> LineString<T> {
pub fn close(&mut self) {
if !self.is_closed() {
// by definition, we treat empty LineString's as closed.
debug_assert!(self.0.len() > 0);
debug_assert!(!self.0.is_empty());
self.0.push(self.0[0]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/centroid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where
// length == 0 means that all points in all constituent linestrings were equal.
// we can just use the first defined point in this case.
for linestring in self.0.iter() {
if linestring.0.len() > 0 {
if !linestring.0.is_empty() {
return Some(Point(linestring[0]));
}
}
Expand Down
1 change: 1 addition & 0 deletions geo/src/algorithm/closest_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl<F: Float> ClosestPoint<F> for Point<F> {
}
}

#[allow(clippy::many_single_char_names)]
impl<F: Float + HasKernel> ClosestPoint<F> for Line<F> {
fn closest_point(&self, p: &Point<F>) -> Closest<F> {
let line_length = self.euclidean_length();
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/concave_hull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ where
let interior_coords: Vec<Coordinate<T>> = coords
.iter()
.filter(|coord| !hull_tree.contains(coord))
.map(|coord| *coord)
.copied()
.collect();
let mut interior_points_tree: RTree<Coordinate<T>> = RTree::bulk_load(interior_coords);
let mut line_tree: RTree<Line<T>> = RTree::new();
Expand Down
29 changes: 14 additions & 15 deletions geo/src/algorithm/coords_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::{
};
use std::{iter, marker, slice};

type CoordinateChainOnce<T> = iter::Chain<iter::Once<Coordinate<T>>, iter::Once<Coordinate<T>>>;

/// Iterate over geometry coordinates.
pub trait CoordsIter<'a, T: CoordinateType> {
type Iter: Iterator<Item = Coordinate<T>>;
Expand Down Expand Up @@ -69,12 +71,13 @@ impl<'a, T: CoordinateType + 'a> CoordsIter<'a, T> for LineString<T> {
// ┌────────────────────────────┐
// │ Implementation for Polygon │
// └────────────────────────────┘
type PolygonChainIter<'a, T> = iter::Chain<
<LineString<T> as CoordsIter<'a, T>>::Iter,
iter::Flatten<MapCoordsIter<'a, T, slice::Iter<'a, LineString<T>>, LineString<T>>>,
>;

impl<'a, T: CoordinateType + 'a> CoordsIter<'a, T> for Polygon<T> {
type Iter = iter::Chain<
<LineString<T> as CoordsIter<'a, T>>::Iter,
iter::Flatten<MapCoordsIter<'a, T, slice::Iter<'a, LineString<T>>, LineString<T>>>,
>;
type Iter = PolygonChainIter<'a, T>;

fn coords_iter(&'a self) -> Self::Iter {
self.exterior()
Expand Down Expand Up @@ -135,14 +138,13 @@ impl<'a, T: CoordinateType + 'a> CoordsIter<'a, T> for GeometryCollection<T> {
// │ Implementation for Rect │
// └─────────────────────────┘

type RectChainIter<T> = iter::Chain<
iter::Chain<CoordinateChainOnce<T>, iter::Once<Coordinate<T>>>,
iter::Once<Coordinate<T>>,
>;

impl<'a, T: CoordinateType + 'a> CoordsIter<'a, T> for Rect<T> {
type Iter = iter::Chain<
iter::Chain<
iter::Chain<iter::Once<Coordinate<T>>, iter::Once<Coordinate<T>>>,
iter::Once<Coordinate<T>>,
>,
iter::Once<Coordinate<T>>,
>;
type Iter = RectChainIter<T>;

fn coords_iter(&'a self) -> Self::Iter {
iter::once(Coordinate {
Expand All @@ -169,10 +171,7 @@ impl<'a, T: CoordinateType + 'a> CoordsIter<'a, T> for Rect<T> {
// └─────────────────────────────┘

impl<'a, T: CoordinateType + 'a> CoordsIter<'a, T> for Triangle<T> {
type Iter = iter::Chain<
iter::Chain<iter::Once<Coordinate<T>>, iter::Once<Coordinate<T>>>,
iter::Once<Coordinate<T>>,
>;
type Iter = iter::Chain<CoordinateChainOnce<T>, iter::Once<Coordinate<T>>>;

fn coords_iter(&'a self) -> Self::Iter {
iter::once(self.0)
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/geodesic_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl GeodesicLength<f64> for LineString<f64> {
fn geodesic_length(&self) -> f64 {
let mut length = 0.0;
for line in self.lines() {
length = length + line.geodesic_length();
length += line.geodesic_length();
}
length
}
Expand All @@ -67,7 +67,7 @@ impl GeodesicLength<f64> for MultiLineString<f64> {
fn geodesic_length(&self) -> f64 {
let mut length = 0.0;
for line_string in &self.0 {
length = length + line_string.geodesic_length();
length += line_string.geodesic_length();
}
length
}
Expand Down
3 changes: 3 additions & 0 deletions geo/src/algorithm/haversine_intermediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ where
}
}

#[allow(clippy::many_single_char_names)]
struct HaversineParams<T: Float + FromPrimitive> {
d: T,
n: T,
Expand All @@ -97,6 +98,7 @@ struct HaversineParams<T: Float + FromPrimitive> {
s: T,
}

#[allow(clippy::many_single_char_names)]
fn get_point<T: Float + FromPrimitive>(params: &HaversineParams<T>, f: T) -> Point<T> {
let one = T::one();

Expand All @@ -123,6 +125,7 @@ fn get_point<T: Float + FromPrimitive>(params: &HaversineParams<T>, f: T) -> Poi
Point::new(lon.to_degrees(), lat.to_degrees())
}

#[allow(clippy::many_single_char_names)]
fn get_params<T: Float + FromPrimitive>(p1: &Point<T>, p2: &Point<T>) -> HaversineParams<T> {
let one = T::one();
let two = one + one;
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/is_convex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ where
.map(orientation_at)
.find(|&(_, orientation)| match orientation {
Orientation::Collinear => !allow_collinear,
orientation => !(orientation == first_non_collinear),
orientation => orientation != first_non_collinear,
})
.is_none()
{
Expand Down
1 change: 1 addition & 0 deletions geo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_return)]
#![doc(html_logo_url = "https://raw.githubusercontent.com/georust/meta/master/logo/logo.png")]
//! The `geo` crate provides geospatial primitive types such as `Coordinate`, `Point`, `LineString`, and `Polygon` as
//! well as their `Multi–` equivalents, and provides algorithms and operations such as:
Expand Down

0 comments on commit 8498785

Please sign in to comment.