pub struct Obb2<S> { /* private fields */ }
Expand description
2D oriented bounding box
Implementations§
Source§impl<S> Obb2<S>where
S: Ring,
impl<S> Obb2<S>where
S: Ring,
Sourcepub fn new(
center: Point2<S>,
half_extent_x: Positive<S>,
half_extent_y: Positive<S>,
orientation: AngleWrapped<S>,
) -> Obb2<S>
pub fn new( center: Point2<S>, half_extent_x: Positive<S>, half_extent_y: Positive<S>, orientation: AngleWrapped<S>, ) -> Obb2<S>
Construct a new OBB
Sourcepub fn containing_points(points: &[Point2<S>]) -> Option<Obb2<S>>where
S: Real,
pub fn containing_points(points: &[Point2<S>]) -> Option<Obb2<S>>where
S: Real,
Construct the minimum OBB containing the convex hull of a given set of
points using rotating calipers algorithm. To construct the OBB containing
a convex hull directoy use the Obb2::containing
method.
Returns None if fewer than 3 points are given or if points span an empty set:
assert!(Obb2::containing_points (
&[[0.0, 1.0], [1.0, 0.0]].map (Point2::from)
).is_none());
assert!(Obb2::containing_points (
&[[1.0, 1.0], [0.0, 0.0], [-1.0, -1.0]].map (Point2::from)
).is_none());
Sourcepub fn containing(hull: &Hull2<S>) -> Option<Obb2<S>>where
S: Real,
pub fn containing(hull: &Hull2<S>) -> Option<Obb2<S>>where
S: Real,
Construct the minimum OBB containing the given convex hull of points using rotating calipers algorithm.
Returns None if if points span an empty set:
let hull = Hull2::from_points (
&[[1.0, 1.0], [0.0, 0.0], [-1.0, -1.0]].map (Point2::from)).unwrap();
assert!(Obb2::containing (&hull).is_none());
pub fn center(&self) -> Point2<S>
pub fn half_extent_x(&self) -> Positive<S>
pub fn half_extent_y(&self) -> Positive<S>
pub fn orientation(&self) -> AngleWrapped<S>
pub fn dimensions(&self) -> Vec2<S>where
S: Field,
pub fn extents(&self) -> Vec2<S>
pub fn area(&self) -> Positive<S>where
S: Field,
pub fn corners(&self) -> [Point2<S>; 4]
Sourcepub fn contains(&self, point: &Point2<S>) -> bool
pub fn contains(&self, point: &Point2<S>) -> bool
Check if point is contained by the bounding box.
let x = Obb2::new (
[3.0, 6.0].into(),
Positive::unchecked (2.0),
Positive::unchecked (0.75),
AngleWrapped::wrap (Rad (std::f32::consts::FRAC_PI_4)));
assert!(x.contains (&[2.0f32, 5.0].into()));
assert!(!x.contains (&[3.0f32, 2.0].into()));
Sourcepub fn dilate(self, amount: S) -> Obb2<S>where
S: Field,
pub fn dilate(self, amount: S) -> Obb2<S>where
S: Field,
Increase or decrease each dimension by the given amount.
Panics if any dimension would become zero or negative:
ⓘ
let x = Obb2::new (
Point2::origin(),
Positive::unchecked (0.5),
Positive::unchecked (0.5),
AngleWrapped::zero()
);
let y = x.dilate (-1.0); // panic!
Trait Implementations§
Source§impl<'de, S> Deserialize<'de> for Obb2<S>where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for Obb2<S>where
S: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Obb2<S>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Obb2<S>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<S> Serialize for Obb2<S>where
S: Serialize,
impl<S> Serialize for Obb2<S>where
S: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<S> Copy for Obb2<S>where
S: Copy,
impl<S> StructuralPartialEq for Obb2<S>
Auto Trait Implementations§
impl<S> Freeze for Obb2<S>where
S: Freeze,
impl<S> RefUnwindSafe for Obb2<S>where
S: RefUnwindSafe,
impl<S> Send for Obb2<S>where
S: Send,
impl<S> Sync for Obb2<S>where
S: Sync,
impl<S> Unpin for Obb2<S>where
S: Unpin,
impl<S> UnwindSafe for Obb2<S>where
S: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
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>
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 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>
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 moreSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.