geo::algorithm::dimensions

Trait HasDimensions

Source
pub trait HasDimensions {
    // Required methods
    fn is_empty(&self) -> bool;
    fn dimensions(&self) -> Dimensions;
    fn boundary_dimensions(&self) -> Dimensions;
}
Expand description

Operate on the dimensionality of geometries.

Required Methods§

Source

fn is_empty(&self) -> bool

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, coord, LineString};
use geo::HasDimensions;

let line_string = LineString::new(vec![
    coord! { x: 0., y: 0. },
    coord! { x: 10., y: 0. },
]);
assert!(!line_string.is_empty());

let empty_line_string: LineString = LineString::new(vec![]);
assert!(empty_line_string.is_empty());

let point = Point::new(0.0, 0.0);
assert!(!point.is_empty());
Source

fn dimensions(&self) -> Dimensions

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 Rects are 2-dimensional, but it’s possible to create degenerate Rects which have either 1 or 0 dimensions.

§Examples
use geo_types::{GeometryCollection, Rect, Point};
use geo::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::new_from(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>::new_from(vec![]);
assert_eq!(Dimensions::Empty, empty_collection.dimensions());
assert!(empty_collection.dimensions() < point.dimensions());
Source

fn boundary_dimensions(&self) -> Dimensions

The dimensions of the Geometry’s boundary, as used by OGC-SFA.

§Examples
use geo_types::{GeometryCollection, Rect, Point};
use geo::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::new_from(vec![degenerate_line_rect.into(), degenerate_point_rect.into()]);
assert_eq!(Dimensions::ZeroDimensional, geometry_collection.boundary_dimensions());

let geometry_collection = GeometryCollection::<f32>::new_from(vec![]);
assert_eq!(Dimensions::Empty, geometry_collection.boundary_dimensions());

Implementors§