pub struct IntersectionMatrix(_);
Expand description

Models a Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix.

DE-9IM matrix values (such as “212FF1FF2”) specify the topological relationship between two Geometries.

DE-9IM matrices are 3x3 matrices that represent the topological locations that occur in a geometry (Interior, Boundary, Exterior).

The indices are provided by the enum cases CoordPos::Inside, CoordPos::OnBoundary, CoordPos::Outside.

The matrix entries represent the Dimensions of each intersection.

For a description of the DE-9IM and the spatial predicates derived from it, see the following references:

This implementation is heavily based on that from the JTS project.

Implementations§

source§

impl IntersectionMatrix

source

pub fn empty() -> Self

source

pub fn is_disjoint(&self) -> bool

Tests if this matrix matches [FF*FF****].

returns true if the two geometries related by this matrix are disjoint

source

pub fn is_intersects(&self) -> bool

Tests if is_disjoint returns false.

returns true if the two geometries related by this matrix intersect.

source

pub fn is_within(&self) -> bool

Tests whether this matrix matches [T*F**F***].

returns true if the first geometry is within the second.

source

pub fn is_contains(&self) -> bool

Tests whether this matrix matches [T*****FF*].

returns true if the first geometry contains the second.

source

pub fn get(&self, lhs: CoordPos, rhs: CoordPos) -> Dimensions

Directly accesses this matrix

use geo_types::{LineString, Rect, line_string};
use geo::{coordinate_position::CoordPos, dimensions::Dimensions, relate::Relate};

let line_string: LineString = line_string![(x: 0.0, y: 0.0), (x: 10.0, y: 0.0), (x: 5.0, y: 5.0)];
let rect = Rect::new((0.0, 0.0), (5.0, 5.0));

let intersection = line_string.relate(&rect);

// The intersection of the two interiors is empty, because no part of the string is inside the rect
assert_eq!(intersection.get(CoordPos::Inside, CoordPos::Inside), Dimensions::Empty);

// The intersection of the line string's interior with the rect's boundary is one-dimensional, because part of the first line overlaps one of the rect's edges
assert_eq!(intersection.get(CoordPos::Inside, CoordPos::OnBoundary), Dimensions::OneDimensional);

// The intersection of the line string's interior with the rect's exterior is one-dimensional, because part of the string is outside the rect
assert_eq!(intersection.get(CoordPos::Inside, CoordPos::Outside), Dimensions::OneDimensional);

// The intersection of the line string's boundary with the rect's interior is empty, because neither of its end points are inside the rect
assert_eq!(intersection.get(CoordPos::OnBoundary, CoordPos::Inside), Dimensions::Empty);

// The intersection of the line string's boundary with the rect's boundary is zero-dimensional, because the string's start and end points are on the rect's edges
assert_eq!(intersection.get(CoordPos::OnBoundary, CoordPos::OnBoundary), Dimensions::ZeroDimensional);

// The intersection of the line string's boundary with the rect's exterior is empty, because neither of its end points are outside the rect
assert_eq!(intersection.get(CoordPos::OnBoundary, CoordPos::Outside), Dimensions::Empty);

// The intersection of the the line's exterior with the rect's interior is two-dimensional, because it's simply the rect's interior
assert_eq!(intersection.get(CoordPos::Outside, CoordPos::Inside), Dimensions::TwoDimensional);

// The intersection of the line's exterior with the rect's boundary is one-dimensional, because it's the rect's edges (minus where the string overlaps it)
assert_eq!(intersection.get(CoordPos::Outside, CoordPos::OnBoundary), Dimensions::OneDimensional);

// The intersection of the two exteriors is two-dimensional, because it's the whole plane around the two shapes
assert_eq!(intersection.get(CoordPos::Outside, CoordPos::Outside), Dimensions::TwoDimensional);

Trait Implementations§

source§

impl Clone for IntersectionMatrix

source§

fn clone(&self) -> IntersectionMatrix

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for IntersectionMatrix

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for IntersectionMatrix

§

type Err = InvalidInputError

The associated error which can be returned from parsing.
source§

fn from_str(str: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq<IntersectionMatrix> for IntersectionMatrix

source§

fn eq(&self, other: &IntersectionMatrix) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for IntersectionMatrix

source§

impl StructuralEq for IntersectionMatrix

source§

impl StructuralPartialEq for IntersectionMatrix

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

source§

fn is_within(&self, b: &G2) -> bool