Skip to main content

Hypercuboid

Struct Hypercuboid 

Source
pub struct Hypercuboid<const N: usize> {
    pub edge_lengths: [PositiveReal; N],
}
Expand description

A shape with with all perpendicular angles made from axis-aligned edges.

A Hypercuboid is the N-dimensional analog of a rectangle, and is defined by its edge lengths. Each perpendicular edge of the cuboid is aligned along the corresponding Cartesian axis. The hypercuboid is placed with its centroid at the origin.

§Example

Construction and basic methods:

use hoomd_geometry::{Volume, shape::Hypercuboid};

let unit_cube = Hypercuboid {
    edge_lengths: [1.0.try_into()?; 3],
};
assert_eq!(unit_cube.volume(), 1.0);

let min_extents = unit_cube.minimal_extents();
let max_extents = unit_cube.maximal_extents();
assert_eq!(min_extents, [-0.5; 3]);
assert_eq!(max_extents, [0.5; 3]);

let rectangular_prism = Hypercuboid {
    edge_lengths: [1.0.try_into()?, 1.0.try_into()?, 9.0.try_into()?],
};

assert_eq!(rectangular_prism.volume(), 9.0);

Perform a fast AABB intersection tests:

use hoomd_geometry::shape::Hypercuboid;

let unit_cube = Hypercuboid {
    edge_lengths: [1.0.try_into()?; 3],
};
let rectangular_prism = Hypercuboid {
    edge_lengths: [1.0.try_into()?, 1.0.try_into()?, 9.0.try_into()?],
};

assert!(unit_cube.intersects_aligned(&rectangular_prism, &[1.0; 3].into()));
assert!(
    !unit_cube.intersects_aligned(&rectangular_prism, &[1.1; 3].into())
);

Wrap with Convex to check intersections of oriented cuboids:

use hoomd_geometry::{Convex, IntersectsAt, shape::Rectangle};
use hoomd_vector::Angle;
use std::f64::consts::PI;

let square = Convex(Rectangle {
    edge_lengths: [1.0.try_into()?; 2],
});

assert!(!square.intersects_at(
    &square,
    &[1.1, 0.0].into(),
    &Angle::default()
));
assert!(square.intersects_at(
    &square,
    &[1.1, 0.0].into(),
    &Angle::from(PI / 4.0)
));

Fields§

§edge_lengths: [PositiveReal; N]

The lengths of each edge of the cuboid.

Implementations§

Source§

impl Hypercuboid<3>

Source

pub fn a(&self) -> PositiveReal

Length of the Hypercuboid edge along the x axis

Source

pub fn b(&self) -> PositiveReal

Length of the Hypercuboid edge along the y axis

Source

pub fn c(&self) -> PositiveReal

Length of the Hypercuboid edge along the z axis

Source§

impl<const N: usize> Hypercuboid<N>

Source

pub fn with_equal_edges(l: PositiveReal) -> Self

Construct a cuboid with all edge lengths equal.

§Example
use hoomd_geometry::shape::Rectangle;

let square = Rectangle::with_equal_edges(10.0.try_into()?);
Source

pub fn intersects_aligned( &self, other: &Hypercuboid<N>, v_ij: &Cartesian<N>, ) -> bool

Test for intersections between two axis-aligned cuboids.

This test is much faster than a general oriented cuboid (OBB) intersection, which can be achieved by wrapping with the Convex newtype.

§Example
use hoomd_geometry::shape::Hypercuboid;

let unit_cube = Hypercuboid {
    edge_lengths: [1.0.try_into()?; 3],
};
let rectangular_prism = Hypercuboid {
    edge_lengths: [1.0.try_into()?, 1.0.try_into()?, 9.0.try_into()?],
};

assert!(unit_cube.intersects_aligned(&rectangular_prism, &[1.0; 3].into()));
assert!(
    !unit_cube.intersects_aligned(&rectangular_prism, &[1.1; 3].into())
);
Source§

impl<const N: usize> Hypercuboid<N>

Source

pub fn maximal_extents(&self) -> [f64; N]

Determine the maximal extents of the cuboid along each Cartesian axis.

§Example
use hoomd_geometry::shape::Hypercuboid;

let unit_cube = Hypercuboid {
    edge_lengths: [1.0.try_into()?; 3],
};

let max_extents = unit_cube.maximal_extents();
assert_eq!(max_extents, [0.5; 3]);
Source

pub fn minimal_extents(&self) -> [f64; N]

Determine the minimal extents of the cuboid along each Cartesian axis.

§Example
use hoomd_geometry::shape::Hypercuboid;

let unit_cube = Hypercuboid {
    edge_lengths: [1.0.try_into()?; 3],
};

let min_extents = unit_cube.minimal_extents();
assert_eq!(min_extents, [-0.5; 3]);
Source§

impl Hypercuboid<2>

Source

pub fn to_gsd_box(&self) -> [f64; 6]

Represent the shape in the GSD box format.

§Example
use hoomd_geometry::shape::Rectangle;

let rectangle = Rectangle {
    edge_lengths: [10.0.try_into()?, 15.0.try_into()?],
};

let gsd_box = rectangle.to_gsd_box();
assert_eq!(gsd_box, [10.0, 15.0, 0.0, 0.0, 0.0, 0.0]);
Source§

impl Hypercuboid<3>

Source

pub fn to_gsd_box(&self) -> [f64; 6]

Represent the shape in the GSD box format.

§Example
use hoomd_geometry::shape::Cuboid;

let rectangle = Cuboid {
    edge_lengths: [10.0.try_into()?, 15.0.try_into()?, 20.0.try_into()?],
};

let gsd_box = rectangle.to_gsd_box();
assert_eq!(gsd_box, [10.0, 15.0, 20.0, 0.0, 0.0, 0.0]);

Trait Implementations§

Source§

impl<const N: usize> BoundingSphereRadius for Hypercuboid<N>

Source§

fn bounding_sphere_radius(&self) -> PositiveReal

Get the bounding radius.
Source§

impl<const N: usize> Clone for Hypercuboid<N>

Source§

fn clone(&self) -> Hypercuboid<N>

Returns a duplicate 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<const N: usize> Debug for Hypercuboid<N>

Source§

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

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

impl<'de, const N: usize> Deserialize<'de> for Hypercuboid<N>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Distribution<Cartesian<N>> for Hypercuboid<N>

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cartesian<N>

Generate points uniformly distributed in the cuboid.

§Example
use rand::{SeedableRng, distr::Distribution, rngs::StdRng};

use hoomd_geometry::{IsPointInside, shape::Hypercuboid};

let cuboid = Hypercuboid {
    edge_lengths: [6.0.try_into()?, 8.0.try_into()?],
};
let mut rng = StdRng::seed_from_u64(1);

let point = cuboid.sample(&mut rng);
assert!(cuboid.is_point_inside(&point));
Source§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl<const N: usize> IsPointInside<Cartesian<N>> for Hypercuboid<N>

Source§

fn is_point_inside(&self, point: &Cartesian<N>) -> bool

Check if a cartesian vector is inside a cuboid.

By conventions typically used in periodic boundary conditions, points exactly at the minimal extent are inside the shape but points exactly on the maximal extent are not:

-\frac{L_x}{2} \le x \lt \frac{L_x}{2}
-\frac{L_y}{2} \le y \lt \frac{L_y}{2}

… and so on

use hoomd_geometry::{IsPointInside, shape::Hypercuboid};

let cuboid = Hypercuboid {
    edge_lengths: [6.0.try_into()?, 8.0.try_into()?],
};

assert!(cuboid.is_point_inside(&[2.5, -3.5].into()));
assert!(!cuboid.is_point_inside(&[4.0, -3.5].into()));
Source§

impl<const N: usize> MapPoint<Cartesian<N>> for Hypercuboid<N>

Source§

fn map_point( &self, point: Cartesian<N>, other: &Self, ) -> Result<Cartesian<N>, Error>

Map a point from one hypercuboid to another.

Given a point P inside self, map it to the other shape by scaling.

§Errors

Returns Error::PointOutsideShape when point is outside the shape self.

§Example
use hoomd_geometry::{MapPoint, shape::Rectangle};
use hoomd_vector::Cartesian;

let rectangle_a = Rectangle::with_equal_edges(10.0.try_into()?);
let rectangle_b = Rectangle::with_equal_edges(20.0.try_into()?);

let mapped_point =
    rectangle_a.map_point(Cartesian::from([-1.0, 1.0]), &rectangle_b);

assert_eq!(mapped_point, Ok(Cartesian::from([-2.0, 2.0])));
assert_eq!(
    rectangle_a.map_point(Cartesian::from([-100.0, 1.0]), &rectangle_b),
    Err(hoomd_geometry::Error::PointOutsideShape)
);
Source§

impl<const N: usize> PartialEq for Hypercuboid<N>

Source§

fn eq(&self, other: &Hypercuboid<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> Scale for Hypercuboid<N>

Source§

fn scale_length(&self, v: PositiveReal) -> Self

Construct a scaled hypercuboid.

The resulting hypercuboid’s edge lengths $L_\mathrm{new}$ are the original’s $L$ scaled by $v$:

L_\mathrm{new} = v L

The centroid remains at the origin.

§Example
use hoomd_geometry::{Scale, shape::Rectangle};

let rectangle = Rectangle::with_equal_edges(10.0.try_into()?);

let scaled_rectangle = rectangle.scale_length(0.5.try_into()?);

assert_eq!(scaled_rectangle.edge_lengths[0].get(), 5.0);
Source§

fn scale_volume(&self, v: PositiveReal) -> Self

Construct a scaled hypercuboid.

The resulting hypercuboid’s edge lengths $L_\mathrm{new}$ are the original’s $L$ scaled by $v^\frac{1}{N}$:

L_\mathrm{new} = v^\frac{1}{N} L

The centroid remains at the origin.

§Examples
use hoomd_geometry::{Scale, shape::Rectangle};

let rectangle = Rectangle::with_equal_edges(10.0.try_into()?);

let scaled_rectangle = rectangle.scale_volume(4.0.try_into()?);

assert_eq!(scaled_rectangle.edge_lengths[0].get(), 20.0);
Source§

impl<const N: usize> Serialize for Hypercuboid<N>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const N: usize> SupportMapping<Cartesian<N>> for Hypercuboid<N>

Source§

fn support_mapping(&self, n: &Cartesian<N>) -> Cartesian<N>

Return the furthest extent of a shape in the direction of n.
Source§

impl<const N: usize> Volume for Hypercuboid<N>

Source§

fn volume(&self) -> f64

The N-hypervolume of a geometry.
Source§

impl<const N: usize> StructuralPartialEq for Hypercuboid<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Hypercuboid<N>

§

impl<const N: usize> RefUnwindSafe for Hypercuboid<N>

§

impl<const N: usize> Send for Hypercuboid<N>

§

impl<const N: usize> Sync for Hypercuboid<N>

§

impl<const N: usize> Unpin for Hypercuboid<N>

§

impl<const N: usize> UnsafeUnpin for Hypercuboid<N>

§

impl<const N: usize> UnwindSafe for Hypercuboid<N>

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> 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> 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, 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,