Skip to content

Commit

Permalink
Merge branch 'master' into ed2021
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Feb 22, 2022
2 parents 7527ab0 + 87dd612 commit db99a1a
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 221 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
on:
push:
branches:
- main
- master
- staging
- trying
pull_request:
schedule: [cron: "45 6 * * *"]

name: Run tests
Expand All @@ -15,6 +21,7 @@ jobs:
name: ci result
runs-on: ubuntu-latest
needs:
- clippy
- geo_types
- geo
- geo_postgis
Expand All @@ -28,6 +35,23 @@ jobs:
if: "!success()"
run: exit 1

clippy:
name: clippy
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
container_image:
# Use the latest stable clippy. No need for older versions.
- "georust/geo-ci:rust-1.58"
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- run: rustup component add clippy
- run: cargo clippy --all-features --all-targets -- -Dwarnings

geo_types:
name: geo-types
runs-on: ubuntu-latest
Expand Down
30 changes: 6 additions & 24 deletions geo-types/src/coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ 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>
where
T: CoordNum,
{
pub struct Coordinate<T: CoordNum> {
pub x: T,
pub y: T,
}
Expand Down Expand Up @@ -72,10 +69,7 @@ impl<T: CoordNum> From<Coordinate<T>> for [T; 2] {
}
}

impl<T> Coordinate<T>
where
T: CoordNum,
{
impl<T: CoordNum> Coordinate<T> {
/// Returns a tuple that contains the x/horizontal & y/vertical component of the coordinate.
///
/// # Examples
Expand Down Expand Up @@ -137,10 +131,7 @@ where
/// assert_eq!(sum.x, 2.75);
/// assert_eq!(sum.y, 5.0);
/// ```
impl<T> Add for Coordinate<T>
where
T: CoordNum,
{
impl<T: CoordNum> Add for Coordinate<T> {
type Output = Coordinate<T>;

fn add(self, rhs: Coordinate<T>) -> Coordinate<T> {
Expand All @@ -162,10 +153,7 @@ where
/// assert_eq!(diff.x, 0.25);
/// assert_eq!(diff.y, 0.);
/// ```
impl<T> Sub for Coordinate<T>
where
T: CoordNum,
{
impl<T: CoordNum> Sub for Coordinate<T> {
type Output = Coordinate<T>;

fn sub(self, rhs: Coordinate<T>) -> Coordinate<T> {
Expand All @@ -186,10 +174,7 @@ where
/// assert_eq!(q.x, 5.0);
/// assert_eq!(q.y, 10.0);
/// ```
impl<T> Mul<T> for Coordinate<T>
where
T: CoordNum,
{
impl<T: CoordNum> Mul<T> for Coordinate<T> {
type Output = Coordinate<T>;

fn mul(self, rhs: T) -> Coordinate<T> {
Expand All @@ -210,10 +195,7 @@ where
/// assert_eq!(q.x, 1.25);
/// assert_eq!(q.y, 2.5);
/// ```
impl<T> Div<T> for Coordinate<T>
where
T: CoordNum,
{
impl<T: CoordNum> Div<T> for Coordinate<T> {
type Output = Coordinate<T>;

fn div(self, rhs: T) -> Coordinate<T> {
Expand Down
5 changes: 1 addition & 4 deletions geo-types/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use std::convert::TryFrom;
///
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Geometry<T>
where
T: CoordNum,
{
pub enum Geometry<T: CoordNum> {
Point(Point<T>),
Line(Line<T>),
LineString(LineString<T>),
Expand Down
4 changes: 1 addition & 3 deletions geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ use std::ops::{Index, IndexMut};
///
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct GeometryCollection<T>(pub Vec<Geometry<T>>)
where
T: CoordNum;
pub struct GeometryCollection<T: CoordNum>(pub Vec<Geometry<T>>);

// Implementing Default by hand because T does not have Default restriction
// todo: consider adding Default as a CoordNum requirement
Expand Down
10 changes: 2 additions & 8 deletions geo-types/src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ use approx::{AbsDiffEq, RelativeEq};
/// `LineString` with the two end points.
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Line<T>
where
T: CoordNum,
{
pub struct Line<T: CoordNum> {
pub start: Coordinate<T>,
pub end: Coordinate<T>,
}

impl<T> Line<T>
where
T: CoordNum,
{
impl<T: CoordNum> Line<T> {
/// Creates a new line segment.
///
/// # Examples
Expand Down
4 changes: 1 addition & 3 deletions geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ use std::ops::{Index, IndexMut};
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LineString<T>(pub Vec<Coordinate<T>>)
where
T: CoordNum;
pub struct LineString<T: CoordNum>(pub Vec<Coordinate<T>>);

/// A [`Point`] iterator returned by the `points` method
#[derive(Debug)]
Expand Down
4 changes: 1 addition & 3 deletions geo-types/src/multi_line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use std::iter::FromIterator;
/// of a closed `MultiLineString` is always empty.
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MultiLineString<T>(pub Vec<LineString<T>>)
where
T: CoordNum;
pub struct MultiLineString<T: CoordNum>(pub Vec<LineString<T>>);

impl<T: CoordNum> MultiLineString<T> {
/// True if the MultiLineString is empty or if all of its LineStrings are closed - see
Expand Down
4 changes: 1 addition & 3 deletions geo-types/src/multi_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ use std::iter::FromIterator;
/// ```
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MultiPoint<T>(pub Vec<Point<T>>)
where
T: CoordNum;
pub struct MultiPoint<T: CoordNum>(pub Vec<Point<T>>);

impl<T: CoordNum, IP: Into<Point<T>>> From<IP> for MultiPoint<T> {
/// Convert a single `Point` (or something which can be converted to a `Point`) into a
Expand Down
4 changes: 1 addition & 3 deletions geo-types/src/multi_polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ use std::iter::FromIterator;
/// predicates that operate on it.
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MultiPolygon<T>(pub Vec<Polygon<T>>)
where
T: CoordNum;
pub struct MultiPolygon<T: CoordNum>(pub Vec<Polygon<T>>);

impl<T: CoordNum, IP: Into<Polygon<T>>> From<IP> for MultiPolygon<T> {
fn from(x: IP) -> Self {
Expand Down
59 changes: 12 additions & 47 deletions geo-types/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssi
/// ```
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Point<T>(pub Coordinate<T>)
where
T: CoordNum;
pub struct Point<T: CoordNum>(pub Coordinate<T>);

impl<T: CoordNum> From<Coordinate<T>> for Point<T> {
fn from(x: Coordinate<T>) -> Point<T> {
Expand Down Expand Up @@ -62,10 +60,7 @@ impl<T: CoordNum> From<Point<T>> for [T; 2] {
}
}

impl<T> Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> Point<T> {
/// Creates a new point.
///
/// # Examples
Expand Down Expand Up @@ -230,10 +225,7 @@ where
}
}

impl<T> Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> Point<T> {
/// Returns the dot product of the two points:
/// `dot = x1 * x2 + y1 * y2`
///
Expand Down Expand Up @@ -274,10 +266,7 @@ where
}
}

impl<T> Point<T>
where
T: CoordFloat,
{
impl<T: CoordFloat> Point<T> {
/// Converts the (x,y) components of Point to degrees
///
/// # Example
Expand Down Expand Up @@ -338,10 +327,7 @@ where
}
}

impl<T> Add for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> Add for Point<T> {
type Output = Point<T>;

/// Add a point to the given point.
Expand All @@ -361,10 +347,7 @@ where
}
}

impl<T> AddAssign for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> AddAssign for Point<T> {
/// Add a point to the given point and assign it to the original point.
///
/// # Examples
Expand All @@ -383,10 +366,7 @@ where
}
}

impl<T> Sub for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> Sub for Point<T> {
type Output = Point<T>;

/// Subtract a point from the given point.
Expand All @@ -406,10 +386,7 @@ where
}
}

impl<T> SubAssign for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> SubAssign for Point<T> {
/// Subtract a point from the given point and assign it to the original point.
///
/// # Examples
Expand All @@ -428,10 +405,7 @@ where
}
}

impl<T> Mul<T> for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> Mul<T> for Point<T> {
type Output = Point<T>;

/// Scaler multiplication of a point
Expand All @@ -451,10 +425,7 @@ where
}
}

impl<T> MulAssign<T> for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> MulAssign<T> for Point<T> {
/// Scaler multiplication of a point in place
///
/// # Examples
Expand All @@ -473,10 +444,7 @@ where
}
}

impl<T> Div<T> for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> Div<T> for Point<T> {
type Output = Point<T>;

/// Scaler division of a point
Expand All @@ -496,10 +464,7 @@ where
}
}

impl<T> DivAssign<T> for Point<T>
where
T: CoordNum,
{
impl<T: CoordNum> DivAssign<T> for Point<T> {
/// Scaler division of a point in place
///
/// # Examples
Expand Down
15 changes: 3 additions & 12 deletions geo-types/src/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,12 @@ use approx::{AbsDiffEq, RelativeEq};
/// [`LineString`]: line_string/struct.LineString.html
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Polygon<T>
where
T: CoordNum,
{
pub struct Polygon<T: CoordNum> {
exterior: LineString<T>,
interiors: Vec<LineString<T>>,
}

impl<T> Polygon<T>
where
T: CoordNum,
{
impl<T: CoordNum> Polygon<T> {
/// Create a new `Polygon` with the provided exterior `LineString` ring and
/// interior `LineString` rings.
///
Expand Down Expand Up @@ -408,10 +402,7 @@ enum ListSign {
Mixed,
}

impl<T> Polygon<T>
where
T: CoordFloat + Signed,
{
impl<T: CoordFloat + Signed> Polygon<T> {
/// Determine whether a Polygon is convex
// For each consecutive pair of edges of the polygon (each triplet of points),
// compute the z-component of the cross product of the vectors defined by the
Expand Down
5 changes: 1 addition & 4 deletions geo-types/src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ use approx::{AbsDiffEq, RelativeEq};
/// ```
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rect<T>
where
T: CoordNum,
{
pub struct Rect<T: CoordNum> {
min: Coordinate<T>,
max: Coordinate<T>,
}
Expand Down
Loading

0 comments on commit db99a1a

Please sign in to comment.