pub trait RelationBetweenShapes<Other: ?Sized> {
// Required method
fn relation(&self, other: &Other, relation: InputRelation) -> OutputRelation;
// Provided methods
fn all_relation(&self, other: &Other) -> OutputRelation { ... }
fn any_relation(&self, other: &Other) -> OutputRelation { ... }
fn contains(&self, other: &Other) -> bool { ... }
fn strict_contains(&self, other: &Other) -> bool { ... }
fn contained(&self, other: &Other) -> bool { ... }
fn strict_contained(&self, other: &Other) -> bool { ... }
fn intersects(&self, other: &Other) -> bool { ... }
fn disjoint(&self, other: &Other) -> bool { ... }
}Expand description
Lets you query the relation between two shapes.
Required Methods§
Sourcefn relation(&self, other: &Other, relation: InputRelation) -> OutputRelation
fn relation(&self, other: &Other, relation: InputRelation) -> OutputRelation
Return the relation between two shapes.
The InputRelation lets you specify the kind of relation you want to retrieve.
use zerometry::{Zoint, Zolygon, RelationBetweenShapes, InputRelation};
let point = geo_types::Point::new(0.0, 0.0); let polygon = geo_types::polygon![(x: -1.0, y: -1.0), (x: 1.0, y: -1.0), (x: 1.0, y: 1.0), (x: -1.0, y: 1.0)];
let mut buffer = Vec::new(); Zoint::write_from_geometry(&mut buffer, &point).unwrap(); let zoint = Zoint::from_bytes(&buffer); let mut buffer = Vec::new(); Zoint::write_from_geometry(&mut buffer, &polygon).unwrap(); let zolygon = Zolygon::from_bytes(&buffer);
// Let’s say we just want to know if the point is contained in the polygon,
// we could write
let relation = InputRelation { contains: true, ..InputRelation::default() };
// The we can ask the relation between our two shape with the relation method:
let relation = zolygon.relation(&zoint, relation);
assert_eq!(relation.contains, Some(true));
Provided Methods§
Sourcefn all_relation(&self, other: &Other) -> OutputRelation
fn all_relation(&self, other: &Other) -> OutputRelation
Return all relations with no early return.
Sourcefn any_relation(&self, other: &Other) -> OutputRelation
fn any_relation(&self, other: &Other) -> OutputRelation
Return the first relation we find with early return.
Sourcefn strict_contains(&self, other: &Other) -> bool
fn strict_contains(&self, other: &Other) -> bool
Return true if Self strictly contains Other.
Sourcefn strict_contained(&self, other: &Other) -> bool
fn strict_contained(&self, other: &Other) -> bool
Return true if Self is strictly contained in Other.
Sourcefn intersects(&self, other: &Other) -> bool
fn intersects(&self, other: &Other) -> bool
Return true if Self intersects with Other.