11pub ( crate ) mod coord;
2- pub ( crate ) mod geometry_collection;
32pub ( crate ) mod line;
3+ pub ( crate ) mod point;
4+ pub ( crate ) mod rect;
5+ pub ( crate ) mod triangle;
6+
7+ #[ cfg( feature = "alloc" ) ]
8+ pub ( crate ) mod geometry_collection;
9+ #[ cfg( feature = "alloc" ) ]
410pub ( crate ) mod line_string;
11+ #[ cfg( feature = "alloc" ) ]
512pub ( crate ) mod multi_line_string;
13+ #[ cfg( feature = "alloc" ) ]
614pub ( crate ) mod multi_point;
15+ #[ cfg( feature = "alloc" ) ]
716pub ( crate ) mod multi_polygon;
8- pub ( crate ) mod point ;
17+ # [ cfg ( feature = "alloc" ) ]
918pub ( crate ) mod polygon;
10- pub ( crate ) mod rect;
11- pub ( crate ) mod triangle;
1219
1320// re-export all the geometry variants:
1421#[ allow( deprecated) ]
1522pub use coord:: { Coord , Coordinate } ;
16- pub use geometry_collection:: GeometryCollection ;
1723pub use line:: Line ;
24+ pub use point:: Point ;
25+ pub use rect:: Rect ;
26+ pub use triangle:: Triangle ;
27+
28+ #[ cfg( feature = "alloc" ) ]
29+ pub use geometry_collection:: GeometryCollection ;
30+ #[ cfg( feature = "alloc" ) ]
1831pub use line_string:: LineString ;
32+ #[ cfg( feature = "alloc" ) ]
1933pub use multi_line_string:: MultiLineString ;
34+ #[ cfg( feature = "alloc" ) ]
2035pub use multi_point:: MultiPoint ;
36+ #[ cfg( feature = "alloc" ) ]
2137pub use multi_polygon:: MultiPolygon ;
22- pub use point :: Point ;
38+ # [ cfg ( feature = "alloc" ) ]
2339pub use polygon:: Polygon ;
24- pub use rect:: Rect ;
25- pub use triangle:: Triangle ;
2640
27- use crate :: { CoordNum , Error } ;
41+ use crate :: CoordNum ;
42+ use crate :: Error ;
2843
2944#[ cfg( any( feature = "approx" , test) ) ]
3045use approx:: { AbsDiffEq , RelativeEq } ;
@@ -41,7 +56,7 @@ use core::convert::TryFrom;
4156///
4257/// ```
4358/// use std::convert::TryFrom;
44- /// use geo_types::{Point, point, Geometry, GeometryCollection };
59+ /// use geo_types::{Point, point, Geometry};
4560/// let p = point!(x: 1.0, y: 1.0);
4661/// let pe: Geometry = p.into();
4762/// let pn = Point::try_from(pe).unwrap();
@@ -52,11 +67,17 @@ use core::convert::TryFrom;
5267pub enum Geometry < T : CoordNum = f64 > {
5368 Point ( Point < T > ) ,
5469 Line ( Line < T > ) ,
70+ #[ cfg( feature = "alloc" ) ]
5571 LineString ( LineString < T > ) ,
72+ #[ cfg( feature = "alloc" ) ]
5673 Polygon ( Polygon < T > ) ,
74+ #[ cfg( feature = "alloc" ) ]
5775 MultiPoint ( MultiPoint < T > ) ,
76+ #[ cfg( feature = "alloc" ) ]
5877 MultiLineString ( MultiLineString < T > ) ,
78+ #[ cfg( feature = "alloc" ) ]
5979 MultiPolygon ( MultiPolygon < T > ) ,
80+ #[ cfg( feature = "alloc" ) ]
6081 GeometryCollection ( GeometryCollection < T > ) ,
6182 Rect ( Rect < T > ) ,
6283 Triangle ( Triangle < T > ) ,
@@ -72,26 +93,31 @@ impl<T: CoordNum> From<Line<T>> for Geometry<T> {
7293 Self :: Line ( x)
7394 }
7495}
96+ #[ cfg( feature = "alloc" ) ]
7597impl < T : CoordNum > From < LineString < T > > for Geometry < T > {
7698 fn from ( x : LineString < T > ) -> Self {
7799 Self :: LineString ( x)
78100 }
79101}
102+ #[ cfg( feature = "alloc" ) ]
80103impl < T : CoordNum > From < Polygon < T > > for Geometry < T > {
81104 fn from ( x : Polygon < T > ) -> Self {
82105 Self :: Polygon ( x)
83106 }
84107}
108+ #[ cfg( feature = "alloc" ) ]
85109impl < T : CoordNum > From < MultiPoint < T > > for Geometry < T > {
86110 fn from ( x : MultiPoint < T > ) -> Self {
87111 Self :: MultiPoint ( x)
88112 }
89113}
114+ #[ cfg( feature = "alloc" ) ]
90115impl < T : CoordNum > From < MultiLineString < T > > for Geometry < T > {
91116 fn from ( x : MultiLineString < T > ) -> Self {
92117 Self :: MultiLineString ( x)
93118 }
94119}
120+ #[ cfg( feature = "alloc" ) ]
95121impl < T : CoordNum > From < MultiPolygon < T > > for Geometry < T > {
96122 fn from ( x : MultiPolygon < T > ) -> Self {
97123 Self :: MultiPolygon ( x)
@@ -145,6 +171,7 @@ impl<T: CoordNum> Geometry<T> {
145171 #[ deprecated(
146172 note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<LineString>"
147173 ) ]
174+ #[ cfg( feature = "alloc" ) ]
148175 pub fn into_line_string ( self ) -> Option < LineString < T > > {
149176 if let Geometry :: LineString ( x) = self {
150177 Some ( x)
@@ -169,6 +196,7 @@ impl<T: CoordNum> Geometry<T> {
169196 #[ deprecated(
170197 note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>"
171198 ) ]
199+ #[ cfg( feature = "alloc" ) ]
172200 pub fn into_polygon ( self ) -> Option < Polygon < T > > {
173201 if let Geometry :: Polygon ( x) = self {
174202 Some ( x)
@@ -181,6 +209,7 @@ impl<T: CoordNum> Geometry<T> {
181209 #[ deprecated(
182210 note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>"
183211 ) ]
212+ #[ cfg( feature = "alloc" ) ]
184213 pub fn into_multi_point ( self ) -> Option < MultiPoint < T > > {
185214 if let Geometry :: MultiPoint ( x) = self {
186215 Some ( x)
@@ -193,6 +222,7 @@ impl<T: CoordNum> Geometry<T> {
193222 #[ deprecated(
194223 note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>"
195224 ) ]
225+ #[ cfg( feature = "alloc" ) ]
196226 pub fn into_multi_line_string ( self ) -> Option < MultiLineString < T > > {
197227 if let Geometry :: MultiLineString ( x) = self {
198228 Some ( x)
@@ -205,6 +235,7 @@ impl<T: CoordNum> Geometry<T> {
205235 #[ deprecated(
206236 note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPolygon>"
207237 ) ]
238+ #[ cfg( feature = "alloc" ) ]
208239 pub fn into_multi_polygon ( self ) -> Option < MultiPolygon < T > > {
209240 if let Geometry :: MultiPolygon ( x) = self {
210241 Some ( x)
@@ -215,11 +246,12 @@ impl<T: CoordNum> Geometry<T> {
215246}
216247
217248macro_rules! try_from_geometry_impl {
218- ( $( $type: ident) ,+) => {
249+ ( $( $( # [ $attr : meta ] ) * $ type: ident) ,+) => {
219250 $(
220251 /// Convert a Geometry enum into its inner type.
221252 ///
222253 /// Fails if the enum case does not match the type you are trying to convert it to.
254+ $( #[ $attr] ) *
223255 impl <T : CoordNum > TryFrom <Geometry <T >> for $type<T > {
224256 type Error = Error ;
225257
@@ -240,10 +272,15 @@ macro_rules! try_from_geometry_impl {
240272try_from_geometry_impl ! (
241273 Point ,
242274 Line ,
275+ #[ cfg( feature = "alloc" ) ]
243276 LineString ,
277+ #[ cfg( feature = "alloc" ) ]
244278 Polygon ,
279+ #[ cfg( feature = "alloc" ) ]
245280 MultiPoint ,
281+ #[ cfg( feature = "alloc" ) ]
246282 MultiLineString ,
283+ #[ cfg( feature = "alloc" ) ]
247284 MultiPolygon ,
248285 // Disabled until we remove the deprecated GeometryCollection::from(single_geom) impl.
249286 // GeometryCollection,
@@ -258,11 +295,17 @@ where
258295 match geometry {
259296 Geometry :: Point ( _) => type_name :: < Point < T > > ( ) ,
260297 Geometry :: Line ( _) => type_name :: < Line < T > > ( ) ,
298+ #[ cfg( feature = "alloc" ) ]
261299 Geometry :: LineString ( _) => type_name :: < LineString < T > > ( ) ,
300+ #[ cfg( feature = "alloc" ) ]
262301 Geometry :: Polygon ( _) => type_name :: < Polygon < T > > ( ) ,
302+ #[ cfg( feature = "alloc" ) ]
263303 Geometry :: MultiPoint ( _) => type_name :: < MultiPoint < T > > ( ) ,
304+ #[ cfg( feature = "alloc" ) ]
264305 Geometry :: MultiLineString ( _) => type_name :: < MultiLineString < T > > ( ) ,
306+ #[ cfg( feature = "alloc" ) ]
265307 Geometry :: MultiPolygon ( _) => type_name :: < MultiPolygon < T > > ( ) ,
308+ #[ cfg( feature = "alloc" ) ]
266309 Geometry :: GeometryCollection ( _) => type_name :: < GeometryCollection < T > > ( ) ,
267310 Geometry :: Rect ( _) => type_name :: < Rect < T > > ( ) ,
268311 Geometry :: Triangle ( _) => type_name :: < Triangle < T > > ( ) ,
@@ -284,10 +327,10 @@ where
284327 /// # Examples
285328 ///
286329 /// ```
287- /// use geo_types::{Geometry, polygon };
330+ /// use geo_types::{Geometry, Line, point };
288331 ///
289- /// let a: Geometry<f32> = polygon![ (x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)] .into();
290- /// let b: Geometry<f32> = polygon![ (x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)] .into();
332+ /// let a: Geometry<f32> = Line::new(point! (x: 0., y: 0.), point! (x: 7., y: 9.)) .into();
333+ /// let b: Geometry<f32> = Line::new(point! (x: 0., y: 0.), point! (x: 7.01, y: 9.)) .into();
291334 ///
292335 /// approx::assert_relative_eq!(a, b, max_relative=0.1);
293336 /// approx::assert_relative_ne!(a, b, max_relative=0.001);
@@ -302,21 +345,27 @@ where
302345 match ( self , other) {
303346 ( Geometry :: Point ( g1) , Geometry :: Point ( g2) ) => g1. relative_eq ( g2, epsilon, max_relative) ,
304347 ( Geometry :: Line ( g1) , Geometry :: Line ( g2) ) => g1. relative_eq ( g2, epsilon, max_relative) ,
348+ #[ cfg( feature = "alloc" ) ]
305349 ( Geometry :: LineString ( g1) , Geometry :: LineString ( g2) ) => {
306350 g1. relative_eq ( g2, epsilon, max_relative)
307351 }
352+ #[ cfg( feature = "alloc" ) ]
308353 ( Geometry :: Polygon ( g1) , Geometry :: Polygon ( g2) ) => {
309354 g1. relative_eq ( g2, epsilon, max_relative)
310355 }
356+ #[ cfg( feature = "alloc" ) ]
311357 ( Geometry :: MultiPoint ( g1) , Geometry :: MultiPoint ( g2) ) => {
312358 g1. relative_eq ( g2, epsilon, max_relative)
313359 }
360+ #[ cfg( feature = "alloc" ) ]
314361 ( Geometry :: MultiLineString ( g1) , Geometry :: MultiLineString ( g2) ) => {
315362 g1. relative_eq ( g2, epsilon, max_relative)
316363 }
364+ #[ cfg( feature = "alloc" ) ]
317365 ( Geometry :: MultiPolygon ( g1) , Geometry :: MultiPolygon ( g2) ) => {
318366 g1. relative_eq ( g2, epsilon, max_relative)
319367 }
368+ #[ cfg( feature = "alloc" ) ]
320369 ( Geometry :: GeometryCollection ( g1) , Geometry :: GeometryCollection ( g2) ) => {
321370 g1. relative_eq ( g2, epsilon, max_relative)
322371 }
@@ -343,10 +392,10 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for Geometry<T> {
343392 /// # Examples
344393 ///
345394 /// ```
346- /// use geo_types::{Geometry, polygon };
395+ /// use geo_types::{Geometry, Line, point };
347396 ///
348- /// let a: Geometry<f32> = polygon![ (x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)] .into();
349- /// let b: Geometry<f32> = polygon![ (x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)] .into();
397+ /// let a: Geometry<f32> = Line::new(point! (x: 0., y: 0.), point! (x: 7., y: 9.)) .into();
398+ /// let b: Geometry<f32> = Line::new(point! (x: 0., y: 0.), point! (x: 7.01, y: 9.)) .into();
350399 ///
351400 /// approx::assert_abs_diff_eq!(a, b, epsilon=0.1);
352401 /// approx::assert_abs_diff_ne!(a, b, epsilon=0.001);
@@ -355,13 +404,19 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for Geometry<T> {
355404 match ( self , other) {
356405 ( Geometry :: Point ( g1) , Geometry :: Point ( g2) ) => g1. abs_diff_eq ( g2, epsilon) ,
357406 ( Geometry :: Line ( g1) , Geometry :: Line ( g2) ) => g1. abs_diff_eq ( g2, epsilon) ,
407+ #[ cfg( feature = "alloc" ) ]
358408 ( Geometry :: LineString ( g1) , Geometry :: LineString ( g2) ) => g1. abs_diff_eq ( g2, epsilon) ,
409+ #[ cfg( feature = "alloc" ) ]
359410 ( Geometry :: Polygon ( g1) , Geometry :: Polygon ( g2) ) => g1. abs_diff_eq ( g2, epsilon) ,
411+ #[ cfg( feature = "alloc" ) ]
360412 ( Geometry :: MultiPoint ( g1) , Geometry :: MultiPoint ( g2) ) => g1. abs_diff_eq ( g2, epsilon) ,
413+ #[ cfg( feature = "alloc" ) ]
361414 ( Geometry :: MultiLineString ( g1) , Geometry :: MultiLineString ( g2) ) => {
362415 g1. abs_diff_eq ( g2, epsilon)
363416 }
417+ #[ cfg( feature = "alloc" ) ]
364418 ( Geometry :: MultiPolygon ( g1) , Geometry :: MultiPolygon ( g2) ) => g1. abs_diff_eq ( g2, epsilon) ,
419+ #[ cfg( feature = "alloc" ) ]
365420 ( Geometry :: GeometryCollection ( g1) , Geometry :: GeometryCollection ( g2) ) => {
366421 g1. abs_diff_eq ( g2, epsilon)
367422 }
0 commit comments