Skip to main content

Envelope

Struct Envelope 

Source
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

Source

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);
Source

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.

Source

pub fn lower_corner(&self) -> &DirectPosition

Returns the lower (minimum) corner.

Source

pub fn upper_corner(&self) -> &DirectPosition

Returns the upper (maximum) corner.

Source

pub fn set_lower_corner(&mut self, lower_corner: DirectPosition)

Source

pub fn set_upper_corner(&mut self, upper_corner: DirectPosition)

Source

pub fn srs_name(&self) -> Option<&str>

Returns the SRS name identifying the CRS of this envelope’s coordinates, or None if unspecified.

Source

pub fn srs_dimension(&self) -> Option<u8>

Returns the coordinate dimension of this envelope’s positions, or None if unspecified.

Source

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").

Source

pub fn set_srs_name_opt(&mut self, srs_name: Option<String>)

Sets or clears the SRS name.

Source

pub fn clear_srs_name(&mut self)

Clears the SRS name.

Source

pub fn set_srs_dimension(&mut self, srs_dimension: u8)

Sets the coordinate dimension of this envelope’s positions (typically 2 or 3).

Source

pub fn set_srs_dimension_opt(&mut self, srs_dimension: Option<u8>)

Sets or clears the coordinate dimension.

Source

pub fn clear_srs_dimension(&mut self)

Clears the coordinate dimension.

Source

pub fn size(&self) -> Vector3<f64>

Returns the diagonal vector from the lower corner to the upper corner.

Source

pub fn size_x(&self) -> f64

Returns the extent along the X axis (upper.x - lower.x).

Source

pub fn size_y(&self) -> f64

Returns the extent along the Y axis (upper.y - lower.y).

Source

pub fn size_z(&self) -> f64

Returns the extent along the Z axis (upper.z - lower.z).

Source

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.

Source

pub fn is_point(&self) -> bool

Returns true if the lower and upper corners are equal, i.e. the envelope collapses to a point.

Source

pub fn is_linear(&self) -> bool

Returns true if exactly one axis has non-zero extent (a line segment).

Source

pub fn is_surface(&self) -> bool

Returns true if exactly two axes have non-zero extent (a flat rectangle).

Source

pub fn is_volume(&self) -> bool

Returns true if all three axes have non-zero extent.

Source

pub fn center(&self) -> DirectPosition

Returns the center point of the envelope.

Computed as lower + size / 2 to avoid overflow with large coordinates.

Source

pub fn contains(&self, point: &DirectPosition) -> bool

Returns true if point lies inside or on the boundary of this envelope.

Source

pub fn contains_envelope(&self, envelope: &Envelope) -> bool

Returns true if envelope is fully contained within (or touches the boundary of) self.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source§

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>)

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>)

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>)

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.

Source§

fn apply_transform(&mut self, transform: Transform3<f64>)

Source§

impl Clone for Envelope

Source§

fn clone(&self) -> Envelope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Envelope

Source§

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

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

impl Default for Envelope

Source§

fn default() -> Envelope

Returns the “default value” for a type. Read more
Source§

impl Display for Envelope

Source§

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

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

impl From<Envelope> for AbstractObjectKind

Source§

fn from(x: Envelope) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Envelope

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Envelope

Source§

impl TryFrom<AbstractObjectKind> for Envelope

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(x: AbstractObjectKind) -> Result<Self, ()>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.