Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use geometry::* to concisely include all the geometry variants #853

Merged
merged 6 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* the `geometry` module now re-exports all the inner geometry variants, so you
can `use geo_types::geometry::*` to concisely include `Point`, `LineString`, etc.
* <https://github.com/georust/geo/pull/853>
* You may now specify `Geometry` rather than `Geometry<f64>` since we've added
a default trait implementation. You may still explicitly declare the numeric
type as f64, or any other implementation of `CoordNum`, but this should save
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod test {
let failure = Point::try_from(rect_geometry).unwrap_err();
assert_eq!(
failure.to_string(),
"Expected a geo_types::point::Point, but found a geo_types::rect::Rect"
"Expected a geo_types::geometry::point::Point, but found a geo_types::geometry::rect::Rect"
);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 29 additions & 7 deletions geo-types/src/geometry.rs → geo-types/src/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
use crate::{
CoordNum, Error, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon, Rect, Triangle,
};
pub(crate) mod coordinate;
pub(crate) mod geometry_collection;
pub(crate) mod line;
pub(crate) mod line_string;
pub(crate) mod multi_line_string;
pub(crate) mod multi_point;
pub(crate) mod multi_polygon;
pub(crate) mod point;
pub(crate) mod polygon;
pub(crate) mod rect;
pub(crate) mod triangle;

// re-export all the geometry variants:
pub use coordinate::Coordinate;
pub use geometry_collection::GeometryCollection;
pub use line::Line;
pub use line_string::LineString;
pub use multi_line_string::MultiLineString;
pub use multi_point::MultiPoint;
pub use multi_polygon::MultiPolygon;
pub use point::Point;
pub use polygon::Polygon;
pub use rect::Rect;
pub use triangle::Triangle;

use crate::{CoordNum, Error};

#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};
Expand All @@ -10,9 +32,9 @@ use std::convert::TryFrom;

/// An enum representing any possible geometry type.
///
/// All `Geo` types can be converted to a `Geometry` member using `.into()` (as part of the
/// `std::convert::Into` pattern), and `Geo` types implement the `TryFrom` trait in order to
/// convert _back_ from enum members.
/// All geometry variants ([`Point`], [`LineString`], etc.) can be converted to a `Geometry` using
/// [`Into::into`]. Conversely, [`TryFrom::try_from`] can be used to convert a [`Geometry`]
/// _back_ to one of it's specific enum members.
///
/// # Example
///
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
77 changes: 24 additions & 53 deletions geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@
//! compatibility with other GeoRust crates. Otherwise, the [`geo`](https://crates.io/crates/geo)
//! crate re-exports these types and additionally provides geospatial algorithms.
//!
//! # Types
//! ## Geometries
//!
//! - **[`Point`]**: A single point represented by one [`Coordinate`]
//! - **[`MultiPoint`]**: A collection of [`Point`]s
//! - **[`Line`]**: A line segment represented by two [`Coordinate`]s
//! - **[`LineString`]**: A series of contiguous line segments represented by two or more
//! [`Coordinate`]s
//! - **[`MultiLineString`]**: A collection of [`LineString`]s
//! - **[`Polygon`]**: A bounded area represented by one [`LineString`] exterior ring, and zero or
//! more [`LineString`] interior rings
//! - **[`MultiPolygon`]**: A collection of [`Polygon`]s
//! - **[`Rect`]**: An axis-aligned bounded rectangle represented by minimum and maximum
//! [`Coordinate`]s
//! - **[`Triangle`]**: A bounded area represented by three [`Coordinate`] vertices
//! - **[`GeometryCollection`]**: A collection of [`Geometry`]s
//! - **[`Geometry`]**: An enumeration of all geometry types, excluding [`Coordinate`]
//!
//! ## Coordinates and Numeric Types
//!
//! - **[`Coordinate`]**: A two-dimensional coordinate. All geometry types are composed of [`Coordinate`]s, though [`Coordinate`] itself is not a [`Geometry`] type.
//! - **[`Coordinate`]**: A two-dimensional coordinate. All geometry types are composed of [`Coordinate`]s, though [`Coordinate`] itself is not a [`Geometry`] type. See [`Point`] for a single coordinate geometry.
//!
//! By default, coordinates are 64-bit floating point numbers, but this is generic, and you may specify any numeric type that implements [`CoordNum`] or [`CoordFloat`]. As well as f64, this includes common numeric types like f32, i32, i64, etc.
//! By default, coordinates are 64-bit floating point numbers, but this is generic, and you may specify any numeric type that implements [`CoordNum`] or [`CoordFloat`]. As well as [`f64`], this includes common numeric types like [`f32`], [`i32`], [`i64`], etc.
//!
//! ```rust
//! use geo_types::Point;
Expand All @@ -33,23 +50,6 @@
//! assert_eq!(std::mem::size_of::<Point<i32>>(), 32 * 2 / 8);
//! ```
//!
//! ## Geometries
//!
//! - **[`Point`]**: A single point represented by one [`Coordinate`]
//! - **[`MultiPoint`]**: A collection of [`Point`]s
//! - **[`Line`]**: A line segment represented by two [`Coordinate`]s
//! - **[`LineString`]**: A series of contiguous line segments represented by two or more
//! [`Coordinate`]s
//! - **[`MultiLineString`]**: A collection of [`LineString`]s
//! - **[`Polygon`]**: A bounded area represented by one [`LineString`] exterior ring, and zero or
//! more [`LineString`] interior rings
//! - **[`MultiPolygon`]**: A collection of [`Polygon`]s
//! - **[`Rect`]**: An axis-aligned bounded rectangle represented by minimum and maximum
//! [`Coordinate`]s
//! - **[`Triangle`]**: A bounded area represented by three [`Coordinate`] vertices
//! - **[`GeometryCollection`]**: A collection of [`Geometry`]s
//! - **[`Geometry`]**: An enumeration of all geometry types, excluding [`Coordinate`]
//!
//! # Semantics
//!
//! The geospatial types provided here aim to adhere to the [OpenGIS Simple feature access][OGC-SFA]
Expand Down Expand Up @@ -109,42 +109,13 @@ impl<T: CoordinateType + Debug> CoordNum for T {}
pub trait CoordFloat: CoordNum + Float {}
impl<T: CoordNum + Float> CoordFloat for T {}

mod coordinate;
pub use crate::coordinate::Coordinate;

mod point;
pub use crate::point::Point;

mod multi_point;
pub use crate::multi_point::MultiPoint;

mod line;
pub use crate::line::Line;

mod line_string;
pub use crate::line_string::{LineString, PointsIter};

mod multi_line_string;
pub use crate::multi_line_string::MultiLineString;

mod polygon;
pub use crate::polygon::Polygon;

mod multi_polygon;
pub use crate::multi_polygon::MultiPolygon;

mod geometry;
pub use crate::geometry::Geometry;

mod geometry_collection;
pub use crate::geometry_collection::GeometryCollection;
pub mod geometry;
pub use geometry::*;

mod triangle;
pub use crate::triangle::Triangle;
pub use geometry::line_string::PointsIter;

mod rect;
#[allow(deprecated)]
pub use crate::rect::{InvalidRectCoordinatesError, Rect};
pub use geometry::rect::InvalidRectCoordinatesError;

mod error;
pub use error::Error;
Expand Down
3 changes: 3 additions & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* Reexport everything from the `proj` crate
* <https://github.com/georust/geo/pull/839>
* Added a `geometry` module which re-exports all the inner geometry variants, so you
can `use geo::geometry::*` to concisely include `Point`, `LineString`, etc.
* <https://github.com/georust/geo/pull/853>
* Add densification algorithm for linear geometry components
* <https://github.com/georust/geo/pull/847>
* Fix fast path euclidean distance
Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/area.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
CoordFloat, CoordNum, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::geometry::*;
use crate::{CoordFloat, CoordNum};

pub(crate) fn twice_signed_ring_area<T>(linestring: &LineString<T>) -> T
where
Expand Down
5 changes: 1 addition & 4 deletions geo/src/algorithm/bounding_rect.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::utils::{partial_max, partial_min};
use crate::{
coord, CoordNum, Coordinate, Geometry, GeometryCollection, GeometryCow, Line, LineString,
MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::{coord, geometry::*, CoordNum, GeometryCow};
use geo_types::private_utils::{get_bounding_rect, line_string_bounding_rect};

/// Calculation of the bounding rectangle of a geometry.
Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/centroid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::cmp::Ordering;

use crate::area::{get_linestring_area, Area};
use crate::dimensions::{Dimensions, Dimensions::*, HasDimensions};
use crate::geometry::*;
use crate::EuclideanLength;
use crate::{
Coordinate, GeoFloat, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::GeoFloat;

/// Calculation of the centroid.
/// The centroid is the arithmetic mean position of all points in the shape.
Expand Down
21 changes: 9 additions & 12 deletions geo/src/algorithm/chamberlain_duquette_area.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{
CoordNum, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon, Rect, Triangle, EQUATORIAL_EARTH_RADIUS,
};
use num_traits::Float;
use crate::geometry::*;
use crate::{CoordFloat, EQUATORIAL_EARTH_RADIUS};

/// Calculate the signed approximate geodesic area of a `Geometry`.
///
Expand Down Expand Up @@ -49,7 +46,7 @@ use num_traits::Float;
/// ```
pub trait ChamberlainDuquetteArea<T>
where
T: Float + CoordNum,
T: CoordFloat,
Copy link
Member Author

@michaelkirk michaelkirk Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These CoordFloat changes are an unrelated no-op cleanup. I just prefer to uniformly reference our internal types over the num_types.

{
fn chamberlain_duquette_signed_area(&self) -> T;

Expand All @@ -58,7 +55,7 @@ where

impl<T> ChamberlainDuquetteArea<T> for Polygon<T>
where
T: Float + CoordNum,
T: CoordFloat,
{
fn chamberlain_duquette_signed_area(&self) -> T {
self.interiors()
Expand All @@ -75,7 +72,7 @@ where

fn ring_area<T>(coords: &LineString<T>) -> T
where
T: Float + CoordNum,
T: CoordFloat,
{
let mut total = T::zero();
let coords_len = coords.0.len();
Expand Down Expand Up @@ -111,7 +108,7 @@ macro_rules! zero_impl {
($type:ident) => {
impl<T> ChamberlainDuquetteArea<T> for $type<T>
where
T: Float + CoordNum,
T: CoordFloat,
{
fn chamberlain_duquette_signed_area(&self) -> T {
T::zero()
Expand All @@ -130,7 +127,7 @@ macro_rules! to_polygon_impl {
($type:ident) => {
impl<T> ChamberlainDuquetteArea<T> for $type<T>
where
T: Float + CoordNum,
T: CoordFloat,
{
fn chamberlain_duquette_signed_area(&self) -> T {
self.to_polygon().chamberlain_duquette_signed_area()
Expand All @@ -149,7 +146,7 @@ macro_rules! sum_impl {
($type:ident) => {
impl<T> ChamberlainDuquetteArea<T> for $type<T>
where
T: Float + CoordNum,
T: CoordFloat,
{
fn chamberlain_duquette_signed_area(&self) -> T {
self.iter().fold(T::zero(), |total, next| {
Expand Down Expand Up @@ -178,7 +175,7 @@ sum_impl!(MultiPolygon);

impl<T> ChamberlainDuquetteArea<T> for Geometry<T>
where
T: Float + CoordNum,
T: CoordFloat,
{
crate::geometry_delegate_impl! {
fn chamberlain_duquette_signed_area(&self) -> T;
Expand Down
11 changes: 6 additions & 5 deletions geo/src/algorithm/closest_point.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::prelude::*;
use crate::{
Closest, Coordinate, GeoFloat, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::algorithm::{EuclideanLength, Intersects};
use crate::geometry::*;
use crate::Closest;
use crate::GeoFloat;

use std::iter;

/// Find the closest `Point` between a given geometry and an input `Point`.
Expand Down Expand Up @@ -185,6 +185,7 @@ impl<F: GeoFloat> ClosestPoint<F> for Geometry<F> {
#[cfg(test)]
mod tests {
use super::*;
use crate::algorithm::{Contains, Translate};
use crate::{point, polygon};

/// Create a test which checks that we get `$should_be` when trying to find
Expand Down
4 changes: 3 additions & 1 deletion geo/src/algorithm/contains/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::Contains;
use crate::*;
use crate::geometry::{Coordinate, Geometry, GeometryCollection, Point};
use crate::geometry_delegate_impl;
use crate::GeoNum;

// ┌──────────────────────────────┐
// │ Implementations for Geometry │
Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/coordinate_position.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
coord, Coordinate, GeoNum, Geometry, GeometryCollection, GeometryCow, Line, LineString,
MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::geometry::*;
use crate::{coord, GeoNum, GeometryCow};
use crate::{BoundingRect, HasDimensions, Intersects};

/// The position of a `Coordinate` relative to a `Geometry`
Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/coords_iter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::fmt::Debug;

use crate::{
coord, CoordNum, Coordinate, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::geometry::*;
use crate::{coord, CoordNum};

use std::{fmt, iter, marker, slice};

Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/dimensions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::geometry::*;
use crate::Orientation::Collinear;
use crate::{
CoordNum, GeoNum, Geometry, GeometryCollection, GeometryCow, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::{CoordNum, GeoNum, GeometryCow};

/// Geometries can have 0, 1, or two dimensions. Or, in the case of an [`empty`](#is_empty)
/// geometry, a special `Empty` dimensionality.
Expand Down
4 changes: 3 additions & 1 deletion geo/src/algorithm/intersects/collections.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{has_disjoint_bboxes, Intersects};
use crate::geometry::*;
use crate::geometry_delegate_impl;
use crate::BoundingRect;
use crate::*;
use crate::CoordNum;

impl<T, G> Intersects<G> for Geometry<T>
where
Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/map_coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

pub use modern::*;
mod modern {
pub(crate) use crate::{
CoordNum, Coordinate, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
pub(crate) use crate::geometry::*;
pub(crate) use crate::CoordNum;

/// Map a function over all the coordinates in an object, returning a new one
pub trait MapCoords<T, NT> {
Expand Down
6 changes: 2 additions & 4 deletions geo/src/algorithm/relate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
pub(crate) use edge_end_builder::EdgeEndBuilder;
pub use geomgraph::intersection_matrix::IntersectionMatrix;

use crate::{
GeoFloat, Geometry, GeometryCollection, GeometryCow, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use crate::geometry::*;
use crate::{GeoFloat, GeometryCow};

mod edge_end_builder;
mod geomgraph;
Expand Down
1 change: 1 addition & 0 deletions geo/src/geometry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use geo_types::geometry::*;
Loading