Trait geo::algorithm::dimensions::HasDimensions [−][src]
pub trait HasDimensions { fn is_empty(&self) -> bool; fn dimensions(&self) -> Dimensions; fn boundary_dimensions(&self) -> Dimensions; }
Operate on the dimensionality of geometries.
Required methods
fn is_empty(&self) -> bool
[src]
Some geometries, like a MultiPoint
, can have zero coordinates - we call these empty
.
Types like Point
and Rect
, which have at least one coordinate by construction, can
never be considered empty.
use geo_types::{Point, Coordinate, LineString}; use geo::algorithm::dimensions::HasDimensions; let line_string = LineString(vec![ Coordinate { x: 0., y: 0. }, Coordinate { x: 10., y: 0. }, ]); assert!(!line_string.is_empty()); let empty_line_string: LineString<f64> = LineString(vec![]); assert!(empty_line_string.is_empty()); let point = Point::new(0.0, 0.0); assert!(!point.is_empty());
fn dimensions(&self) -> Dimensions
[src]
The dimensions of some geometries are fixed, e.g. a Point always has 0 dimensions. However
for others, the dimensionality depends on the specific geometry instance - for example
typical Rect
s are 2-dimensional, but it’s possible to create degenerate Rect
s which
have either 1 or 0 dimensions.
Examples
use geo_types::{GeometryCollection, Rect, Point}; use geo::algorithm::dimensions::{Dimensions, HasDimensions}; // normal rectangle let rect = Rect::new((0.0, 0.0), (10.0, 10.0)); assert_eq!(Dimensions::TwoDimensional, rect.dimensions()); // "rectangle" with zero height degenerates to a line let degenerate_line_rect = Rect::new((0.0, 10.0), (10.0, 10.0)); assert_eq!(Dimensions::OneDimensional, degenerate_line_rect.dimensions()); // "rectangle" with zero height and zero width degenerates to a point let degenerate_point_rect = Rect::new((10.0, 10.0), (10.0, 10.0)); assert_eq!(Dimensions::ZeroDimensional, degenerate_point_rect.dimensions()); // collections inherit the greatest dimensionality of their elements let geometry_collection = GeometryCollection(vec![degenerate_line_rect.into(), degenerate_point_rect.into()]); assert_eq!(Dimensions::OneDimensional, geometry_collection.dimensions()); let point = Point::new(10.0, 10.0); assert_eq!(Dimensions::ZeroDimensional, point.dimensions()); // An `Empty` dimensionality is distinct from, and less than, being 0-dimensional let empty_collection = GeometryCollection::<f32>(vec![]); assert_eq!(Dimensions::Empty, empty_collection.dimensions()); assert!(empty_collection.dimensions() < point.dimensions());
fn boundary_dimensions(&self) -> Dimensions
[src]
The dimensions of the Geometry
’s boundary, as used by OGC-SFA.
Examples
use geo_types::{GeometryCollection, Rect, Point}; use geo::algorithm::dimensions::{Dimensions, HasDimensions}; // a point has no boundary let point = Point::new(10.0, 10.0); assert_eq!(Dimensions::Empty, point.boundary_dimensions()); // a typical rectangle has a *line* (one dimensional) boundary let rect = Rect::new((0.0, 0.0), (10.0, 10.0)); assert_eq!(Dimensions::OneDimensional, rect.boundary_dimensions()); // a "rectangle" with zero height degenerates to a line, whose boundary is two points let degenerate_line_rect = Rect::new((0.0, 10.0), (10.0, 10.0)); assert_eq!(Dimensions::ZeroDimensional, degenerate_line_rect.boundary_dimensions()); // a "rectangle" with zero height and zero width degenerates to a point, // and points have no boundary let degenerate_point_rect = Rect::new((10.0, 10.0), (10.0, 10.0)); assert_eq!(Dimensions::Empty, degenerate_point_rect.boundary_dimensions()); // collections inherit the greatest dimensionality of their elements let geometry_collection = GeometryCollection(vec![degenerate_line_rect.into(), degenerate_point_rect.into()]); assert_eq!(Dimensions::ZeroDimensional, geometry_collection.boundary_dimensions()); let geometry_collection = GeometryCollection::<f32>(vec![]); assert_eq!(Dimensions::Empty, geometry_collection.boundary_dimensions());
Implementors
impl<C: CoordNum> HasDimensions for Line<C>
[src]
fn is_empty(&self) -> bool
[src]
fn dimensions(&self) -> Dimensions
[src]
fn boundary_dimensions(&self) -> Dimensions
[src]
impl<C: CoordNum> HasDimensions for LineString<C>
[src]
fn is_empty(&self) -> bool
[src]
fn dimensions(&self) -> Dimensions
[src]
fn boundary_dimensions(&self) -> Dimensions
[src]
use geo_types::line_string; use geo::algorithm::dimensions::{HasDimensions, Dimensions}; let ls = line_string![(x: 0., y: 0.), (x: 0., y: 1.), (x: 1., y: 1.)]; assert_eq!(Dimensions::ZeroDimensional, ls.boundary_dimensions()); let ls = line_string![(x: 0., y: 0.), (x: 0., y: 1.), (x: 1., y: 1.), (x: 0., y: 0.)]; assert_eq!(Dimensions::Empty, ls.boundary_dimensions());