Skip to content

Commit

Permalink
Move new macros to geo-types; reexport in geo.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Apr 24, 2019
1 parent e82d9d4 commit 6cae63c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 50 deletions.
3 changes: 3 additions & 0 deletions geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub use crate::triangle::Triangle;
mod rect;
pub use crate::rect::Rect;

#[macro_use]
mod macros;

#[doc(hidden)]
pub mod private_utils;

Expand Down
28 changes: 14 additions & 14 deletions geo/src/macros.rs → geo-types/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
/// Creating a [`Point`], supplying x/y values:
///
/// ```
/// use geo::point;
/// use geo_types::point;
///
/// let p = point!(x: 181.2, y: 51.79);
///
/// assert_eq!(p, geo::Point(geo::Coordinate {
/// assert_eq!(p, geo_types::Point(geo_types::Coordinate {
/// x: 181.2,
/// y: 51.79,
/// }));
Expand All @@ -38,7 +38,7 @@ macro_rules! point {
/// Creating a [`LineString`], supplying x/y values:
///
/// ```
/// use geo::line_string;
/// use geo_types::line_string;
///
/// let ls = line_string![
/// (x: -21.95156, y: 64.1446),
Expand All @@ -47,7 +47,7 @@ macro_rules! point {
/// (x: -21.951445, y: 64.145508)
/// ];
///
/// assert_eq!(ls[1], geo::Coordinate {
/// assert_eq!(ls[1], geo_types::Coordinate {
/// x: -21.951,
/// y: 64.14479
/// });
Expand All @@ -56,16 +56,16 @@ macro_rules! point {
/// Creating a [`LineString`], supplying [`Coordinate`]s:
///
/// ```
/// use geo::line_string;
/// use geo_types::line_string;
///
/// let coord1 = geo::Coordinate { x: -21.95156, y: 64.1446 };
/// let coord2 = geo::Coordinate { x: -21.951, y: 64.14479 };
/// let coord3 = geo::Coordinate { x: -21.95044, y: 64.14527 };
/// let coord4 = geo::Coordinate { x: -21.951445, y: 64.145508 };
/// let coord1 = geo_types::Coordinate { x: -21.95156, y: 64.1446 };
/// let coord2 = geo_types::Coordinate { x: -21.951, y: 64.14479 };
/// let coord3 = geo_types::Coordinate { x: -21.95044, y: 64.14527 };
/// let coord4 = geo_types::Coordinate { x: -21.951445, y: 64.145508 };
///
/// let ls = line_string![coord1, coord2, coord3, coord4];
///
/// assert_eq!(ls[1], geo::Coordinate {
/// assert_eq!(ls[1], geo_types::Coordinate {
/// x: -21.951,
/// y: 64.14479
/// });
Expand Down Expand Up @@ -119,7 +119,7 @@ macro_rules! line_string {
/// Creating a [`Polygon`] without interior rings, supplying x/y values:
///
/// ```
/// use geo::polygon;
/// use geo_types::polygon;
///
/// let poly = polygon![
/// (x: -111., y: 45.),
Expand All @@ -130,14 +130,14 @@ macro_rules! line_string {
///
/// assert_eq!(
/// poly.exterior()[1],
/// geo::Coordinate { x: -111., y: 41. },
/// geo_types::Coordinate { x: -111., y: 41. },
/// );
/// ```
///
/// Creating a [`Polygon`], supplying x/y values:
///
/// ```
/// use geo::polygon;
/// use geo_types::polygon;
///
/// let poly = polygon!(
/// exterior: [
Expand All @@ -158,7 +158,7 @@ macro_rules! line_string {
///
/// assert_eq!(
/// poly.exterior()[1],
/// geo::Coordinate { x: -111., y: 41. },
/// geo_types::Coordinate { x: -111., y: 41. },
/// );
/// ```
///
Expand Down
37 changes: 23 additions & 14 deletions geo/src/algorithm/convexhull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,29 @@ pub trait ConvexHull<T> {
/// # Examples
///
/// ```
/// use geo::{Point, LineString, Polygon};
/// use geo::{line_string, polygon};
/// use geo::convexhull::ConvexHull;
///
/// // an L shape
/// let coords = vec![(0.0, 0.0), (4.0, 0.0), (4.0, 1.0), (1.0, 1.0), (1.0, 4.0), (0.0, 4.0), (0.0, 0.0)];
/// let ls: LineString<_> = coords.iter().map(|e| Point::new(e.0, e.1)).collect();
/// let poly = Polygon::new(ls, vec![]);
/// let poly = polygon![
/// (x: 0.0, y: 0.0),
/// (x: 4.0, y: 0.0),
/// (x: 4.0, y: 1.0),
/// (x: 1.0, y: 1.0),
/// (x: 1.0, y: 4.0),
/// (x: 0.0, y: 4.0),
/// (x: 0.0, y: 0.0),
/// ];
///
/// // The correct convex hull coordinates
/// let hull_coords = vec![(4.0, 0.0), (4.0, 1.0), (1.0, 4.0), (0.0, 4.0), (0.0, 0.0), (4.0, 0.0)];
/// let correct_hull: LineString<_> = hull_coords.iter().map(|e| Point::new(e.0, e.1)).collect();
/// let correct_hull = line_string![
/// (x: 4.0, y: 0.0),
/// (x: 4.0, y: 1.0),
/// (x: 1.0, y: 4.0),
/// (x: 0.0, y: 4.0),
/// (x: 0.0, y: 0.0),
/// (x: 4.0, y: 0.0),
/// ];
///
/// let res = poly.convex_hull();
/// assert_eq!(res.exterior(), &correct_hull);
Expand Down Expand Up @@ -197,7 +210,7 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::{line_string, Coordinate, Point};
use crate::{line_string, polygon, Coordinate, Point};

#[test]
fn quick_hull_test1() {
Expand Down Expand Up @@ -341,7 +354,7 @@ mod test {
(x: -1.0, y: -1.0),
(x: -10.0, y: 0.0),
(x: -1.0, y: 1.0),
(x: 0.0, y: 10.0)
(x: 0.0, y: 10.0),
];
let correct = vec![
Coordinate::from((0.0, -10.0)),
Expand Down Expand Up @@ -370,12 +383,8 @@ mod test {
}
#[test]
fn quick_hull_multipolygon_test() {
let ls1 =
line_string![(x: 0.0, y: 0.0), (x: 1.0, y: 10.0), (x: 2.0, y: 0.0), (x: 0.0, y: 0.0)];
let ls2 =
line_string![(x: 3.0, y: 0.0), (x: 4.0, y: 10.0), (x: 5.0, y: 0.0), (x: 3.0, y: 0.0)];
let p1 = Polygon::new(ls1, vec![]);
let p2 = Polygon::new(ls2, vec![]);
let p1 = polygon![(x: 0.0, y: 0.0), (x: 1.0, y: 10.0), (x: 2.0, y: 0.0), (x: 0.0, y: 0.0)];
let p2 = polygon![(x: 3.0, y: 0.0), (x: 4.0, y: 10.0), (x: 5.0, y: 0.0), (x: 3.0, y: 0.0)];
let mp = MultiPolygon(vec![p1, p2]);
let correct = vec![
Coordinate::from((5.0, 0.0)),
Expand Down
44 changes: 27 additions & 17 deletions geo/src/algorithm/rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::{line_string, point, polygon, Coordinate, LineString, Point, Polygon};
use crate::{line_string, point, polygon, Coordinate, Point};

#[test]
fn test_rotate_around_point() {
Expand Down Expand Up @@ -274,23 +274,33 @@ mod test {
}
#[test]
fn test_rotate_polygon_holes() {
let ls1 = line_string![
(x: 5.0, y: 1.0),
(x: 4.0, y: 2.0),
(x: 4.0, y: 3.0),
(x: 5.0, y: 4.0),
(x: 6.0, y: 4.0),
(x: 7.0, y: 3.0),
(x: 7.0, y: 2.0),
(x: 6.0, y: 1.0),
(x: 5.0, y: 1.0)
let poly1 = polygon![
exterior: [
(x: 5.0, y: 1.0),
(x: 4.0, y: 2.0),
(x: 4.0, y: 3.0),
(x: 5.0, y: 4.0),
(x: 6.0, y: 4.0),
(x: 7.0, y: 3.0),
(x: 7.0, y: 2.0),
(x: 6.0, y: 1.0),
(x: 5.0, y: 1.0)
],
interiors: [
[
(x: 5.0, y: 1.3),
(x: 5.5, y: 2.0),
(x: 6.0, y: 1.3),
(x: 5.0, y: 1.3),
],
[
(x: 5., y: 2.3),
(x: 5.5, y: 3.0),
(x: 6., y: 2.3),
(x: 5., y: 2.3),
],
],
];

let ls2 = LineString::from(vec![(5.0, 1.3), (5.5, 2.0), (6.0, 1.3), (5.0, 1.3)]);

let ls3 = LineString::from(vec![(5., 2.3), (5.5, 3.0), (6., 2.3), (5., 2.3)]);

let poly1 = Polygon::new(ls1, vec![ls2, ls3]);
let rotated = poly1.rotate(-15.0);
let correct_outside = vec![
Coordinate::from((4.628808519201685, 1.180520783117658)),
Expand Down
7 changes: 2 additions & 5 deletions geo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub use crate::traits::ToGeo;
pub use crate::types::*;

pub use geo_types::{
Coordinate, CoordinateType, Geometry, GeometryCollection, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
line_string, point, polygon, Coordinate, CoordinateType, Geometry, GeometryCollection, Line,
LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};

/// This module includes all the functions of geometric calculations
Expand All @@ -26,9 +26,6 @@ mod traits;
mod types;
mod utils;

#[macro_use]
mod macros;

#[cfg(test)]
#[macro_use]
extern crate approx;
Expand Down

0 comments on commit 6cae63c

Please sign in to comment.