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>
impl Hypercuboid<3>
Sourcepub fn a(&self) -> PositiveReal
pub fn a(&self) -> PositiveReal
Length of the Hypercuboid edge along the x axis
Sourcepub fn b(&self) -> PositiveReal
pub fn b(&self) -> PositiveReal
Length of the Hypercuboid edge along the y axis
Sourcepub fn c(&self) -> PositiveReal
pub fn c(&self) -> PositiveReal
Length of the Hypercuboid edge along the z axis
Source§impl<const N: usize> Hypercuboid<N>
impl<const N: usize> Hypercuboid<N>
Sourcepub fn with_equal_edges(l: PositiveReal) -> Self
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()?);Sourcepub fn intersects_aligned(
&self,
other: &Hypercuboid<N>,
v_ij: &Cartesian<N>,
) -> bool
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>
impl<const N: usize> Hypercuboid<N>
Sourcepub fn maximal_extents(&self) -> [f64; N]
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]);Sourcepub fn minimal_extents(&self) -> [f64; N]
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>
impl Hypercuboid<2>
Sourcepub fn to_gsd_box(&self) -> [f64; 6]
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>
impl Hypercuboid<3>
Sourcepub fn to_gsd_box(&self) -> [f64; 6]
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>
impl<const N: usize> BoundingSphereRadius for Hypercuboid<N>
Source§fn bounding_sphere_radius(&self) -> PositiveReal
fn bounding_sphere_radius(&self) -> PositiveReal
Source§impl<const N: usize> Clone for Hypercuboid<N>
impl<const N: usize> Clone for Hypercuboid<N>
Source§fn clone(&self) -> Hypercuboid<N>
fn clone(&self) -> Hypercuboid<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize> Debug for Hypercuboid<N>
impl<const N: usize> Debug for Hypercuboid<N>
Source§impl<'de, const N: usize> Deserialize<'de> for Hypercuboid<N>
impl<'de, const N: usize> Deserialize<'de> for Hypercuboid<N>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<const N: usize> Distribution<Cartesian<N>> for Hypercuboid<N>
impl<const N: usize> Distribution<Cartesian<N>> for Hypercuboid<N>
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cartesian<N>
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>
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
T, using rng as
the source of randomness. Read moreSource§impl<const N: usize> IsPointInside<Cartesian<N>> for Hypercuboid<N>
impl<const N: usize> IsPointInside<Cartesian<N>> for Hypercuboid<N>
Source§fn is_point_inside(&self, point: &Cartesian<N>) -> bool
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>
impl<const N: usize> MapPoint<Cartesian<N>> for Hypercuboid<N>
Source§fn map_point(
&self,
point: Cartesian<N>,
other: &Self,
) -> Result<Cartesian<N>, Error>
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>
impl<const N: usize> PartialEq for Hypercuboid<N>
Source§impl<const N: usize> Scale for Hypercuboid<N>
impl<const N: usize> Scale for Hypercuboid<N>
Source§fn scale_length(&self, v: PositiveReal) -> Self
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 LThe 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
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} LThe 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>
impl<const N: usize> Serialize for Hypercuboid<N>
Source§impl<const N: usize> SupportMapping<Cartesian<N>> for Hypercuboid<N>
impl<const N: usize> SupportMapping<Cartesian<N>> for Hypercuboid<N>
Source§fn support_mapping(&self, n: &Cartesian<N>) -> Cartesian<N>
fn support_mapping(&self, n: &Cartesian<N>) -> Cartesian<N>
n.Source§impl<const N: usize> Volume for Hypercuboid<N>
impl<const N: usize> Volume for Hypercuboid<N>
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> 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> 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 more