Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Feb 17, 2019
1 parent 2cb1a5b commit 0015d58
Show file tree
Hide file tree
Showing 32 changed files with 56 additions and 50 deletions.
3 changes: 1 addition & 2 deletions geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::iter::FromIterator;
use crate::{CoordinateType, Geometry};
use std::iter::FromIterator;

/// A collection of [`Geometry`](enum.Geometry.html) types.
///
Expand Down Expand Up @@ -28,7 +28,6 @@ impl<T: CoordinateType> GeometryCollection<T> {
}
}


/// Convert any Geometry (or anything that can be converted to a Geometry) into a
/// GeometryCollection
impl<T: CoordinateType, IG: Into<Geometry<T>>> From<IG> for GeometryCollection<T> {
Expand Down
4 changes: 2 additions & 2 deletions geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ mod test {
let _: MultiPoint<_> = vec![(0., 0.), (1., 2.)].into_iter().collect();

let mut l1: LineString<_> = vec![(0., 0.), (1., 2.)].into();
assert_eq!(l1[1], Coordinate{ x: 1., y: 2. }); // index into linestring
assert_eq!(l1[1], Coordinate { x: 1., y: 2. }); // index into linestring
let _: LineString<_> = vec![(0., 0.), (1., 2.)].into_iter().collect();

// index mutably into a linestring
l1[0] = Coordinate{ x: 1., y: 1. };
l1[0] = Coordinate { x: 1., y: 1. };
assert_eq!(l1, vec![(1., 1.), (1., 2.)].into());
}

Expand Down
3 changes: 1 addition & 2 deletions geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Coordinate, CoordinateType, Line, Point, Triangle};
use std::iter::FromIterator;
use std::ops::{Index, IndexMut};
use crate::{Coordinate, CoordinateType, Line, Point, Triangle};

/// An ordered collection of two or more [`Coordinate`s](struct.Coordinate.html), representing a
/// path between locations.
Expand Down Expand Up @@ -189,7 +189,6 @@ impl<T: CoordinateType> IndexMut<usize> for LineString<T> {
}
}


#[cfg(feature = "rstar")]
impl<T> ::rstar::RTreeObject for LineString<T>
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/multi_line_string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::iter::FromIterator;
use crate::{CoordinateType, LineString};
use std::iter::FromIterator;

/// A collection of [`LineString`s](struct.LineString.html).
///
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/multi_point.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::iter::FromIterator;
use crate::{CoordinateType, Point};
use std::iter::FromIterator;

/// A collection of [`Point`s](struct.Point.html).
///
Expand Down
3 changes: 1 addition & 2 deletions geo-types/src/multi_polygon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::iter::FromIterator;
use crate::{CoordinateType, Polygon};
use std::iter::FromIterator;

/// A collection of [`Polygon`s](struct.Polygon.html).
///
Expand All @@ -24,7 +24,6 @@ impl<T: CoordinateType, IP: Into<Polygon<T>>> From<Vec<IP>> for MultiPolygon<T>
}
}


impl<T: CoordinateType, IP: Into<Polygon<T>>> FromIterator<IP> for MultiPolygon<T> {
fn from_iter<I: IntoIterator<Item = IP>>(iter: I) -> Self {
MultiPolygon(iter.into_iter().map(|p| p.into()).collect())
Expand Down
7 changes: 2 additions & 5 deletions geo-types/src/point.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{Coordinate, CoordinateType};
use num_traits::Float;
use std::ops::Add;
use std::ops::Neg;
use std::ops::Sub;
use crate::{Coordinate, CoordinateType};

/// A single point in 2D space.
///
Expand Down Expand Up @@ -360,10 +360,7 @@ where

const DIMENSIONS: usize = 2;

fn generate(
generator: impl Fn(usize) -> Self::Scalar
) -> Self
{
fn generate(generator: impl Fn(usize) -> Self::Scalar) -> Self {
Point::new(generator(0), generator(1))
}

Expand Down
8 changes: 5 additions & 3 deletions geo-types/src/polygon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::{Float, Signed};
use crate::{CoordinateType, LineString, Point, Rect};
use num_traits::{Float, Signed};

/// A bounded two-dimensional area.
///
Expand Down Expand Up @@ -239,7 +239,8 @@ where
///
/// [will be closed]: #linestring-closing-operation
pub fn exterior_mut<F>(&mut self, mut f: F)
where F: FnMut(&mut LineString<T>)
where
F: FnMut(&mut LineString<T>),
{
f(&mut self.exterior);
self.exterior.close();
Expand Down Expand Up @@ -348,7 +349,8 @@ where
///
/// [will be closed]: #linestring-closing-operation
pub fn interiors_mut<F>(&mut self, mut f: F)
where F: FnMut(&mut [LineString<T>])
where
F: FnMut(&mut [LineString<T>]),
{
f(&mut self.interiors);
for interior in &mut self.interiors {
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/private_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// hidden module is public so the geo crate can reuse these algorithms to
// prevent duplication. These functions are _not_ meant for public consumption.

use num_traits::Float;
use crate::{Coordinate, CoordinateType, Line, LineString, Point, Rect};
use num_traits::Float;

pub static COORD_PRECISION: f32 = 1e-1; // 0.1m

Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/area.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::Float;
use crate::{CoordinateType, Line, LineString, MultiPolygon, Polygon, Rect, Triangle};
use num_traits::Float;

use crate::algorithm::winding_order::twice_signed_ring_area;

Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/bearing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::Float;
use crate::Point;
use num_traits::Float;

/// Returns the bearing to another Point in degrees.
///
Expand Down
6 changes: 4 additions & 2 deletions geo/src/algorithm/bounding_rect.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use geo_types::private_utils::{get_bounding_rect, line_string_bounding_rect};
use crate::{
Coordinate, CoordinateType, Line, LineString, MultiLineString, MultiPoint, MultiPolygon,
Polygon, Rect, Triangle,
};
use geo_types::private_utils::{get_bounding_rect, line_string_bounding_rect};

/// Calculation of the bounding rectangle of a geometry.
pub trait BoundingRect<T: CoordinateType> {
Expand Down Expand Up @@ -139,7 +139,9 @@ where
#[cfg(test)]
mod test {
use crate::algorithm::bounding_rect::BoundingRect;
use crate::{Coordinate, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon, Rect};
use crate::{
Coordinate, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon, Rect,
};

#[test]
fn empty_linestring_test() {
Expand Down
4 changes: 3 additions & 1 deletion geo/src/algorithm/centroid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,10 @@ where
mod test {
use crate::algorithm::centroid::Centroid;
use crate::algorithm::euclidean_distance::EuclideanDistance;
use crate::{
Coordinate, Line, LineString, MultiPolygon, Point, Polygon, Rect, COORD_PRECISION,
};
use num_traits::Float;
use crate::{Coordinate, Line, LineString, MultiPolygon, Point, Polygon, Rect, COORD_PRECISION};

/// small helper to create a coordinate
fn c<T: Float>(x: T, y: T) -> Coordinate<T> {
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/closest_point.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use num_traits::Float;
use crate::prelude::*;
use std::iter;
use crate::{Closest, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon};
use num_traits::Float;
use std::iter;

/// Find the closest point between two objects, where the other object is
/// assumed to be a `Point` by default.
Expand Down
4 changes: 3 additions & 1 deletion geo/src/algorithm/contains.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use num_traits::Float;

use crate::algorithm::intersects::Intersects;
use crate::{Coordinate, CoordinateType, Line, LineString, MultiPolygon, Point, Polygon, Rect, Triangle};
use crate::{
Coordinate, CoordinateType, Line, LineString, MultiPolygon, Point, Polygon, Rect, Triangle,
};

/// Checks if the geometry A is completely inside the B geometry
pub trait Contains<Rhs = Self> {
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/convexhull.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::algorithm::euclidean_distance::EuclideanDistance;
use num_traits::Float;
use std::mem;
use crate::utils::partition_slice;
use crate::{Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon};
use num_traits::Float;
use std::mem;

fn swap_remove_to_first<'a, T>(slice: &mut &'a mut [T], idx: usize) -> &'a mut T {
let tmp = mem::replace(slice, &mut []);
Expand Down
6 changes: 4 additions & 2 deletions geo/src/algorithm/euclidean_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::algorithm::contains::{get_position, Contains, PositionPoint};
use crate::algorithm::euclidean_length::EuclideanLength;
use crate::algorithm::intersects::Intersects;
use crate::algorithm::polygon_distance_fast_path::*;
use crate::{
Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Triangle,
};
use num_traits::float::FloatConst;
use num_traits::{Bounded, Float, Signed};
use crate::{Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Triangle};

use rstar::RTree;
use rstar::RTreeNum;
Expand Down Expand Up @@ -490,8 +492,8 @@ mod test {
use super::*;
use crate::algorithm::convexhull::ConvexHull;
use crate::algorithm::euclidean_distance::EuclideanDistance;
use geo_types::private_utils::line_segment_distance;
use crate::{Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon};
use geo_types::private_utils::line_segment_distance;

#[test]
fn line_segment_distance_test() {
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/extremes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::algorithm::convexhull::ConvexHull;
use num_traits::{Float, Signed};
use crate::{ExtremePoint, Extremes};
use crate::{MultiPoint, MultiPolygon, Point, Polygon};
use num_traits::{Float, Signed};

// Useful direction vectors, aligned with x and y axes:
// 1., 0. = largest x
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/from_postgis.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use postgis;
use postgis::ewkb::{GeometryCollectionT, GeometryT};
use crate::{
Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point,
Polygon,
};
use postgis;
use postgis::ewkb::{GeometryCollectionT, GeometryT};

/// Creates geometry from a PostGIS type.
///
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/haversine_destination.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::{Float, FromPrimitive};
use crate::{Point, MEAN_EARTH_RADIUS};
use num_traits::{Float, FromPrimitive};

/// Returns a new Point using the distance to the existing Point and a bearing for the direction
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/haversine_distance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::{Float, FromPrimitive};
use crate::{Point, MEAN_EARTH_RADIUS};
use num_traits::{Float, FromPrimitive};

/// Determine the distance between two geometries using the [haversine formula].
///
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/haversine_intermediate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::{Float, FromPrimitive};
use crate::{Point, MEAN_EARTH_RADIUS};
use num_traits::{Float, FromPrimitive};

/// Returns a new Point along a great circle route between two existing points
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/intersects.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::algorithm::contains::Contains;
use num_traits::Float;
use crate::{Line, LineString, Point, Polygon, Rect};
use num_traits::Float;

/// Checks if the geometry A intersects the geometry B.
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/map_coords.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use failure::Error;
use crate::{
Coordinate, CoordinateType, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect,
};
use failure::Error;

/// Map a function over all the coordinates in an object, returning a new one
pub trait MapCoords<T, NT> {
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/polygon_distance_fast_path.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::algorithm::extremes::ExtremeIndices;
use num_traits::float::FloatConst;
use num_traits::{Float, Signed};
use crate::prelude::*;
use crate::{Line, Point, Polygon, Triangle};
use num_traits::float::FloatConst;
use num_traits::{Float, Signed};

// These are helper functions for the "fast path" of Polygon-Polygon distance
// They use the rotating calipers method to speed up calculations.
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/rotate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::algorithm::centroid::Centroid;
use crate::algorithm::map_coords::MapCoords;
use crate::{Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon};
use num_traits::{Float, FromPrimitive};
use std::iter::Sum;
use crate::{Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon};

#[inline]
fn rotate_inner<T>(x: T, y: T, x0: T, y0: T, sin_theta: T, cos_theta: T) -> Point<T>
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/simplify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::algorithm::euclidean_distance::EuclideanDistance;
use num_traits::Float;
use crate::{Line, LineString, MultiLineString, MultiPolygon, Point, Polygon};
use num_traits::Float;

// Ramer–Douglas-Peucker line simplification algorithm
fn rdp<T>(points: &[Point<T>], epsilon: &T) -> Vec<Point<T>>
Expand Down
6 changes: 4 additions & 2 deletions geo/src/algorithm/simplifyvw.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use num_traits::Float;
use crate::prelude::*;
use crate::{
Coordinate, Line, LineString, MultiLineString, MultiPolygon, Point, Polygon, Triangle,
};
use num_traits::Float;
use std::cmp::Ordering;
use std::collections::BinaryHeap;
use crate::{Coordinate, Line, LineString, MultiLineString, MultiPolygon, Point, Polygon, Triangle};

use rstar::{RTree, RTreeNum};

Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/to_postgis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use postgis::ewkb;
use crate::{
Coordinate, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon,
};
use postgis::ewkb;

/// Converts geometry to a PostGIS type.
///
Expand Down
2 changes: 1 addition & 1 deletion geo/src/algorithm/vincenty_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// - https://nathanrooy.github.io/posts/2016-12-18/vincenty-formula-with-python/
// - https://github.com/janantala/GPS-distance/blob/master/java/Distance.java

use crate::{Point, EARTH_FLATTENING, EQUATORIAL_EARTH_RADIUS, POLAR_EARTH_RADIUS};
use num_traits::{Float, FromPrimitive};
use std::{error, fmt};
use crate::{Point, EARTH_FLATTENING, EQUATORIAL_EARTH_RADIUS, POLAR_EARTH_RADIUS};

/// Determine the distance between two geometries using [Vincenty’s formulae].
///
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/winding_order.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use geo_types::line_string::PointsIter;
use std::iter::Rev;
use crate::utils::EitherIter;
use crate::{CoordinateType, LineString, Point};
use geo_types::line_string::PointsIter;
use std::iter::Rev;

pub(crate) fn twice_signed_ring_area<T>(linestring: &LineString<T>) -> T
where
Expand Down
2 changes: 1 addition & 1 deletion geo/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num_traits::Float;
use crate::{CoordinateType, Point};
use num_traits::Float;

pub use geo_types::private_utils::COORD_PRECISION;

Expand Down

0 comments on commit 0015d58

Please sign in to comment.