geo::algorithm::relate

Trait Relate

Source
pub trait Relate<F: GeoFloat> {
    // Required method
    fn geometry_graph(&self, arg_index: usize) -> GeometryGraph<'_, F>;

    // Provided method
    fn relate(&self, other: &impl Relate<F>) -> IntersectionMatrix { ... }
}
Expand description

Topologically relate two geometries based on DE-9IM semantics.

See IntersectionMatrix for details. All predicates are available on the calculated matrix.

§Examples

use geo::{coord, Line, Rect, line_string};
use crate::geo::relate::Relate;

let line = Line::new(coord! { x: 2.0, y: 2.0}, coord! { x: 4.0, y: 4.0 });
let rect = Rect::new(coord! { x: 2.0, y: 2.0}, coord! { x: 4.0, y: 4.0 });
let intersection_matrix = rect.relate(&line);

assert!(intersection_matrix.is_intersects());
assert!(!intersection_matrix.is_disjoint());
assert!(intersection_matrix.is_contains());
assert!(!intersection_matrix.is_within());

let line = Line::new(coord! { x: 1.0, y: 1.0}, coord! { x: 5.0, y: 5.0 });
let rect = Rect::new(coord! { x: 2.0, y: 2.0}, coord! { x: 4.0, y: 4.0 });
let intersection_matrix = rect.relate(&line);
assert!(intersection_matrix.is_intersects());
assert!(!intersection_matrix.is_disjoint());
assert!(!intersection_matrix.is_contains());
assert!(!intersection_matrix.is_within());

let rect_boundary = line_string![
    (x: 2.0, y: 2.0),
    (x: 4.0, y: 2.0),
    (x: 4.0, y: 4.0),
    (x: 2.0, y: 4.0),
    (x: 2.0, y: 2.0)
];
let intersection_matrix = rect.relate(&rect_boundary);
assert!(intersection_matrix.is_intersects());
assert!(!intersection_matrix.is_disjoint());
// According to DE-9IM, polygons don't contain their own boundary
assert!(!intersection_matrix.is_contains());
assert!(!intersection_matrix.is_within());

Note: Relate must not be called on geometries containing NaN coordinates.

Required Methods§

Source

fn geometry_graph(&self, arg_index: usize) -> GeometryGraph<'_, F>

Construct a GeometryGraph

Provided Methods§

Source

fn relate(&self, other: &impl Relate<F>) -> IntersectionMatrix

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F: GeoFloat> Relate<F> for Geometry<F>

Source§

impl<F: GeoFloat> Relate<F> for GeometryCollection<F>

Source§

impl<F: GeoFloat> Relate<F> for Line<F>

Source§

impl<F: GeoFloat> Relate<F> for LineString<F>

Source§

impl<F: GeoFloat> Relate<F> for MultiLineString<F>

Source§

impl<F: GeoFloat> Relate<F> for MultiPoint<F>

Source§

impl<F: GeoFloat> Relate<F> for MultiPolygon<F>

Source§

impl<F: GeoFloat> Relate<F> for Point<F>

Source§

impl<F: GeoFloat> Relate<F> for Polygon<F>

Source§

impl<F: GeoFloat> Relate<F> for Rect<F>

Source§

impl<F: GeoFloat> Relate<F> for Triangle<F>

Source§

impl<F: GeoFloat> Relate<F> for PreparedGeometry<'_, F>