pub struct Envelope { /* private fields */ }Expand description
Axis-aligned bounding box in 3-D space.
An Envelope is defined by a lower corner and an upper corner such that
each coordinate component of the lower corner is ≤ the corresponding
component of the upper corner.
Corresponds to gml:EnvelopeType in ISO 19136.
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn new(
lower_corner: DirectPosition,
upper_corner: DirectPosition,
) -> Result<Self, Error>
pub fn new( lower_corner: DirectPosition, upper_corner: DirectPosition, ) -> Result<Self, Error>
Creates an envelope from explicit lower and upper corners.
§Errors
Returns Error::InvalidEnvelopeBounds if any coordinate
component of lower_corner is strictly greater than the corresponding
component of upper_corner.
§Examples
use egml_core::model::geometry::{DirectPosition, Envelope};
let lo = DirectPosition::new(0.0, 0.0, 0.0).unwrap();
let hi = DirectPosition::new(1.0, 2.0, 3.0).unwrap();
let env = Envelope::new(lo, hi).unwrap();
assert_eq!(env.size_x(), 1.0);Sourcepub fn new_unchecked(
lower_corner: DirectPosition,
upper_corner: DirectPosition,
) -> Self
pub fn new_unchecked( lower_corner: DirectPosition, upper_corner: DirectPosition, ) -> Self
Creates an Envelope without validating that lower_corner <= upper_corner.
§Safety (logical)
The caller must ensure that each component of lower_corner is less than
or equal to the corresponding component of upper_corner. Violating this
will not cause undefined behavior, but will break the type’s invariants
and produce incorrect results from methods like contains, size, etc.
Sourcepub fn lower_corner(&self) -> &DirectPosition
pub fn lower_corner(&self) -> &DirectPosition
Returns the lower (minimum) corner.
Sourcepub fn upper_corner(&self) -> &DirectPosition
pub fn upper_corner(&self) -> &DirectPosition
Returns the upper (maximum) corner.
pub fn set_lower_corner(&mut self, lower_corner: DirectPosition)
pub fn set_upper_corner(&mut self, upper_corner: DirectPosition)
Sourcepub fn srs_name(&self) -> Option<&str>
pub fn srs_name(&self) -> Option<&str>
Returns the SRS name identifying the CRS of this envelope’s coordinates,
or None if unspecified.
Sourcepub fn srs_dimension(&self) -> Option<u8>
pub fn srs_dimension(&self) -> Option<u8>
Returns the coordinate dimension of this envelope’s positions,
or None if unspecified.
Sourcepub fn set_srs_name(&mut self, srs_name: impl Into<String>)
pub fn set_srs_name(&mut self, srs_name: impl Into<String>)
Sets the SRS name identifying the CRS (e.g. "urn:ogc:def:crs:EPSG::25832").
Sourcepub fn set_srs_name_opt(&mut self, srs_name: Option<String>)
pub fn set_srs_name_opt(&mut self, srs_name: Option<String>)
Sets or clears the SRS name.
Sourcepub fn clear_srs_name(&mut self)
pub fn clear_srs_name(&mut self)
Clears the SRS name.
Sourcepub fn set_srs_dimension(&mut self, srs_dimension: u8)
pub fn set_srs_dimension(&mut self, srs_dimension: u8)
Sets the coordinate dimension of this envelope’s positions (typically 2 or 3).
Sourcepub fn set_srs_dimension_opt(&mut self, srs_dimension: Option<u8>)
pub fn set_srs_dimension_opt(&mut self, srs_dimension: Option<u8>)
Sets or clears the coordinate dimension.
Sourcepub fn clear_srs_dimension(&mut self)
pub fn clear_srs_dimension(&mut self)
Clears the coordinate dimension.
Sourcepub fn size(&self) -> Vector3<f64>
pub fn size(&self) -> Vector3<f64>
Returns the diagonal vector from the lower corner to the upper corner.
Sourcepub fn volume(&self) -> f64
pub fn volume(&self) -> f64
Returns the volume of the box (size_x * size_y * size_z).
Returns 0.0 for degenerate envelopes where one or more extents are zero.
Sourcepub fn is_point(&self) -> bool
pub fn is_point(&self) -> bool
Returns true if the lower and upper corners are equal, i.e. the envelope collapses to a point.
Sourcepub fn is_linear(&self) -> bool
pub fn is_linear(&self) -> bool
Returns true if exactly one axis has non-zero extent (a line segment).
Sourcepub fn is_surface(&self) -> bool
pub fn is_surface(&self) -> bool
Returns true if exactly two axes have non-zero extent (a flat rectangle).
Sourcepub fn center(&self) -> DirectPosition
pub fn center(&self) -> DirectPosition
Returns the center point of the envelope.
Computed as lower + size / 2 to avoid overflow with large coordinates.
Sourcepub fn contains(&self, point: &DirectPosition) -> bool
pub fn contains(&self, point: &DirectPosition) -> bool
Returns true if point lies inside or on the boundary of this envelope.
Sourcepub fn contains_envelope(&self, envelope: &Envelope) -> bool
pub fn contains_envelope(&self, envelope: &Envelope) -> bool
Returns true if envelope is fully contained within (or touches the boundary of) self.
Sourcepub fn contains_envelope_partially(&self, envelope: &Envelope) -> bool
pub fn contains_envelope_partially(&self, envelope: &Envelope) -> bool
Returns true if self and envelope overlap at all (including touching).
Uses the standard per-axis AABB overlap test rather than checking corners: two boxes intersect iff they overlap on every axis independently. A corner-only check would miss cases like a thin slab passing straight through the other box, where neither box’s own min/max corner lies inside the other.
Sourcepub fn enlarge(&self, distance: f64) -> Result<Envelope, Error>
pub fn enlarge(&self, distance: f64) -> Result<Envelope, Error>
Returns a new envelope expanded by distance in every direction.
Each lower-corner coordinate is decreased by distance and each
upper-corner coordinate is increased by distance.
§Errors
Returns Error::NonFiniteCoordinate if distance is NaN or infinite,
or if the resulting coordinates would overflow f64::MAX.
Source§impl Envelope
impl Envelope
Sourcepub fn from_envelopes(envelopes: &[Self]) -> Option<Self>
pub fn from_envelopes(envelopes: &[Self]) -> Option<Self>
Computes the union of a slice of envelopes.
Returns None if envelopes is empty; otherwise returns the smallest
envelope that contains all envelopes in the slice.
Sourcepub fn from_points(points: &[DirectPosition]) -> Result<Self, Error>
pub fn from_points(points: &[DirectPosition]) -> Result<Self, Error>
Computes the smallest envelope that contains all points.
§Errors
Returns Error::TooFewElements if points is empty.
Source§impl Envelope
impl Envelope
Sourcepub fn to_solid(&self) -> Result<Solid, Error>
pub fn to_solid(&self) -> Result<Solid, Error>
Constructs a Solid whose boundary is the six faces of the bounding box.
Each face is a Polygon with an outward-facing LinearRing exterior.
Faces are ordered: bottom (−z), top (+z), front (−y), back (+y), left (−x), right (+x).
§Errors
Returns Error::NotAVolume if the envelope does not have all three extents non-zero.
Sourcepub fn to_polygon(&self) -> Result<Polygon, Error>
pub fn to_polygon(&self) -> Result<Polygon, Error>
Constructs a Polygon from the flat rectangle of this envelope.
The four corners are wound counter-clockwise when viewed from the positive side of the collapsed axis (i.e. outward-facing normal).
§Errors
Returns Error::NotASurface if the envelope does not have exactly two non-zero extents.
Sourcepub fn to_triangulated_surface(&self) -> Result<TriangulatedSurface, Error>
pub fn to_triangulated_surface(&self) -> Result<TriangulatedSurface, Error>
Triangulates the envelope into a TriangulatedSurface.
- For a surface envelope (
is_surface()): triangulates the single rectangular face. - For a volume envelope (
is_volume()): triangulates all six bounding faces and merges them.
§Errors
Returns Error::NotSurfaceOrVolume if the envelope is a point or line segment.
Trait Implementations§
Source§impl ApplyTransform for Envelope
impl ApplyTransform for Envelope
Source§fn apply_isometry(&mut self, isometry: Isometry3<f64>)
fn apply_isometry(&mut self, isometry: Isometry3<f64>)
Applies a rigid-body isometry (rotation + translation) to this envelope in place.
Both corners are transformed and the result is re-fitted as an axis-aligned bounding box by taking per-axis minima/maxima. This keeps the AABB invariant valid after rotation, at the cost of a potentially larger box for non-axis-aligned rotations.
§Examples
use egml_core::model::geometry::{DirectPosition, Envelope};
use nalgebra::{Isometry3, Vector3};
use crate::egml_core::model::common::ApplyTransform;
let lo = DirectPosition::new(0.0, 0.0, 0.0).unwrap();
let hi = DirectPosition::new(1.0, 2.0, 3.0).unwrap();
let mut env = Envelope::new(lo, hi).unwrap();
let translation = Isometry3::translation(10.0, 0.0, 0.0);
env.apply_isometry(translation);
assert_eq!(env.lower_corner().x(), 10.0);
assert_eq!(env.upper_corner().x(), 11.0);Source§fn apply_translation(&mut self, vector: Vector3<f64>)
fn apply_translation(&mut self, vector: Vector3<f64>)
Applies a pure translation to this envelope in place.
Fast path: translation preserves per-axis ordering, so both corners can be shifted directly with no re-fit via min/max — unlike rotation or scale, which can invalidate the axis-aligned invariant and require re-deriving the corners.
Source§fn apply_rotation(&mut self, rotation: Rotation3<f64>)
fn apply_rotation(&mut self, rotation: Rotation3<f64>)
Applies a pure rotation (about the origin) to this envelope in place.
Both corners are rotated and the result is re-fitted as an axis-aligned bounding box
by taking per-axis minima/maxima, same as apply_isometry.
Source§fn apply_scale(&mut self, scale: Scale3<f64>)
fn apply_scale(&mut self, scale: Scale3<f64>)
Applies a per-axis scale to this envelope in place.
Both corners are scaled and the result is re-fitted via min/max, same as
apply_isometry — a negative scale factor mirrors an axis and
would otherwise leave the lower corner greater than the upper corner on that axis.
fn apply_transform(&mut self, transform: Transform3<f64>)
Source§impl From<Envelope> for AbstractObjectKind
impl From<Envelope> for AbstractObjectKind
impl StructuralPartialEq for Envelope
Auto Trait Implementations§
impl Freeze for Envelope
impl RefUnwindSafe for Envelope
impl Send for Envelope
impl Sync for Envelope
impl Unpin for Envelope
impl UnsafeUnpin for Envelope
impl UnwindSafe for Envelope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.