Skip to content

Commit

Permalink
Merge pull request #149 from waywardmonkeys/doc-improvements
Browse files Browse the repository at this point in the history
Doc improvements
  • Loading branch information
sebcrozet authored Aug 27, 2023
2 parents 97fd1b2 + b973958 commit 7155e57
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 78 deletions.
4 changes: 2 additions & 2 deletions crates/parry2d/tests/geometry/ray_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn collinear_raycast_starting_on_segment() {
}

#[test]
fn collinear_raycast_starting_bellow_segment() {
fn collinear_raycast_starting_below_segment() {
let m1 = Isometry2::identity();
let ray = Ray::new(Point2::new(0.0, -2.0), Vector2::new(0.0, 1.0));
let seg = Segment::new(Point2::new(0.0, 1.0), Point2::new(0.0, -1.0));
Expand Down Expand Up @@ -84,7 +84,7 @@ fn perpendicular_raycast_starting_above_segment() {
}

#[test]
fn perpendicular_raycast_starting_bellow_segment() {
fn perpendicular_raycast_starting_below_segment() {
let segment = Segment::new(Point2::new(0.0f32, -10.0), Point2::new(0.0, 10.0));
let ray = Ray::new(Point2::new(0.0, -11.0), Vector2::new(1.0, 0.0));
assert!(!segment.intersects_local_ray(&ray, std::f32::MAX));
Expand Down
62 changes: 33 additions & 29 deletions src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ pub struct Aabb {
}

impl Aabb {
/// The vertex indices of each edge of this Aabb.
/// The vertex indices of each edge of this `Aabb`.
///
/// This gives, for each edge of this Aabb, the indices of its
/// This gives, for each edge of this `Aabb`, the indices of its
/// vertices when taken from the `self.vertices()` array.
/// Here is how the faces are numbered, assuming
/// a right-handed coordinate system:
///
/// ```text
/// y 3 - 2
/// | 7 − 6 |
/// ___ x | | 1 (the zero is bellow 3 and on the left of 1, hidden by the 4-5-6-7 face.)
/// / 4 - 5
/// ___ x | | 1 (the zero is below 3 and on the left of 1,
/// / 4 - 5 hidden by the 4-5-6-7 face.)
/// z
/// ```
#[cfg(feature = "dim3")]
pub const EDGES_VERTEX_IDS: [(usize, usize); 12] = [
(0, 1),
Expand All @@ -59,18 +61,20 @@ impl Aabb {
(3, 7),
];

/// The vertex indices of each face of this Aabb.
/// The vertex indices of each face of this `Aabb`.
///
/// This gives, for each face of this Aabb, the indices of its
/// This gives, for each face of this `Aabb`, the indices of its
/// vertices when taken from the `self.vertices()` array.
/// Here is how the faces are numbered, assuming
/// a right-handed coordinate system:
///
/// ```text
/// y 3 - 2
/// | 7 − 6 |
/// ___ x | | 1 (the zero is bellow 3 and on the left of 1, hidden by the 4-5-6-7 face.)
/// / 4 - 5
/// ___ x | | 1 (the zero is below 3 and on the left of 1,
/// / 4 - 5 hidden by the 4-5-6-7 face.)
/// z
/// ```
#[cfg(feature = "dim3")]
pub const FACES_VERTEX_IDS: [(usize, usize, usize, usize); 6] = [
(1, 2, 6, 5),
Expand All @@ -92,9 +96,9 @@ impl Aabb {
Aabb { mins, maxs }
}

/// Creates an invalid Aabb with `mins` components set to `Real::max_values` and `maxs`components set to `-Real::max_values`.
/// Creates an invalid `Aabb` with `mins` components set to `Real::max_values` and `maxs`components set to `-Real::max_values`.
///
/// This is often used as the initial values of some Aabb merging algorithms.
/// This is often used as the initial values of some `Aabb` merging algorithms.
#[inline]
pub fn new_invalid() -> Self {
Self::new(
Expand All @@ -103,34 +107,34 @@ impl Aabb {
)
}

/// Creates a new Aabb from its center and its half-extents.
/// Creates a new `Aabb` from its center and its half-extents.
#[inline]
pub fn from_half_extents(center: Point<Real>, half_extents: Vector<Real>) -> Self {
Self::new(center - half_extents, center + half_extents)
}

/// Creates a new Aabb from a set of points.
/// Creates a new `Aabb` from a set of points.
pub fn from_points<'a, I>(pts: I) -> Self
where
I: IntoIterator<Item = &'a Point<Real>>,
{
super::aabb_utils::local_point_cloud_aabb(pts)
}

/// The center of this Aabb.
/// The center of this `Aabb`.
#[inline]
pub fn center(&self) -> Point<Real> {
na::center(&self.mins, &self.maxs)
}

/// The half extents of this Aabb.
/// The half extents of this `Aabb`.
#[inline]
pub fn half_extents(&self) -> Vector<Real> {
let half: Real = na::convert::<f64, Real>(0.5);
(self.maxs - self.mins) * half
}

/// The volume of this Aabb.
/// The volume of this `Aabb`.
#[inline]
pub fn volume(&self) -> Real {
let extents = self.extents();
Expand All @@ -140,19 +144,19 @@ impl Aabb {
return extents.x * extents.y * extents.z;
}

/// The extents of this Aabb.
/// The extents of this `Aabb`.
#[inline]
pub fn extents(&self) -> Vector<Real> {
self.maxs - self.mins
}

/// Enlarges this Aabb so it also contains the point `pt`.
/// Enlarges this `Aabb` so it also contains the point `pt`.
pub fn take_point(&mut self, pt: Point<Real>) {
self.mins = self.mins.coords.inf(&pt.coords).into();
self.maxs = self.maxs.coords.sup(&pt.coords).into();
}

/// Computes the Aabb bounding `self` transformed by `m`.
/// Computes the `Aabb` bounding `self` transformed by `m`.
#[inline]
pub fn transform_by(&self, m: &Isometry<Real>) -> Self {
let ls_center = self.center();
Expand All @@ -172,7 +176,7 @@ impl Aabb {
}
}

/// The smallest bounding sphere containing this Aabb.
/// The smallest bounding sphere containing this `Aabb`.
#[inline]
pub fn bounding_sphere(&self) -> BoundingSphere {
let center = self.center();
Expand All @@ -191,7 +195,7 @@ impl Aabb {
true
}

/// Computes the intersection of this Aabb and another one.
/// Computes the intersection of this `Aabb` and another one.
pub fn intersection(&self, other: &Aabb) -> Option<Aabb> {
let result = Aabb {
mins: Point::from(self.mins.coords.sup(&other.mins.coords)),
Expand All @@ -207,17 +211,17 @@ impl Aabb {
Some(result)
}

/// Returns the difference between this Aabb and `rhs`.
/// Returns the difference between this `Aabb` and `rhs`.
///
/// Removing another Aabb from `self` will result in zero, one, or up to 4 (in 2D) or 8 (in 3D)
/// Removing another `Aabb` from `self` will result in zero, one, or up to 4 (in 2D) or 8 (in 3D)
/// new smaller Aabbs.
pub fn difference(&self, rhs: &Aabb) -> ArrayVec<Self, TWO_DIM> {
self.difference_with_cut_sequence(rhs).0
}

/// Returns the difference between this Aabb and `rhs`.
/// Returns the difference between this `Aabb` and `rhs`.
///
/// Removing another Aabb from `self` will result in zero, one, or up to 4 (in 2D) or 8 (in 3D)
/// Removing another `Aabb` from `self` will result in zero, one, or up to 4 (in 2D) or 8 (in 3D)
/// new smaller Aabbs.
///
/// # Return
Expand Down Expand Up @@ -272,7 +276,7 @@ impl Aabb {
(result, cut_sequence)
}

/// Computes the vertices of this Aabb.
/// Computes the vertices of this `Aabb`.
#[inline]
#[cfg(feature = "dim2")]
pub fn vertices(&self) -> [Point<Real>; 4] {
Expand All @@ -284,7 +288,7 @@ impl Aabb {
]
}

/// Computes the vertices of this Aabb.
/// Computes the vertices of this `Aabb`.
#[inline]
#[cfg(feature = "dim3")]
pub fn vertices(&self) -> [Point<Real>; 8] {
Expand All @@ -300,7 +304,7 @@ impl Aabb {
]
}

/// Splits this Aabb at its center, into four parts (as in a quad-tree).
/// Splits this `Aabb` at its center, into four parts (as in a quad-tree).
#[inline]
#[cfg(feature = "dim2")]
pub fn split_at_center(&self) -> [Aabb; 4] {
Expand All @@ -320,7 +324,7 @@ impl Aabb {
]
}

/// Splits this Aabb at its center, into height parts (as in an octree).
/// Splits this `Aabb` at its center, into eight parts (as in an octree).
#[inline]
#[cfg(feature = "dim3")]
pub fn split_at_center(&self) -> [Aabb; 8] {
Expand Down Expand Up @@ -362,7 +366,7 @@ impl Aabb {
]
}

/// Projects every point of Aabb on an arbitrary axis.
/// Projects every point of `Aabb` on an arbitrary axis.
pub fn project_on_axis(&self, axis: &UnitVector<Real>) -> (Real, Real) {
let cuboid = Cuboid::new(self.half_extents());
let shift = cuboid
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub fn local_ball_aabb(radius: Real) -> Aabb {
}

impl Ball {
/// Computes the world-space Aabb of this ball transformed by `pos`.
/// Computes the world-space [`Aabb`] of this ball transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
ball_aabb(&Point::<Real>::from(pos.translation.vector), self.radius)
}

/// Computes the local-space Aabb of this ball.
/// Computes the local-space [`Aabb`] of this ball.
#[inline]
pub fn local_aabb(&self) -> Aabb {
local_ball_aabb(self.radius)
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_convex_polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::math::{Isometry, Real};
use crate::shape::ConvexPolygon;

impl ConvexPolygon {
/// Computes the world-space Aabb of this convex polygon, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this convex polygon, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
super::details::point_cloud_aabb(pos, self.points())
}

/// Computes the local-space Aabb of this convex polygon.
/// Computes the local-space [`Aabb`] of this convex polygon.
#[inline]
pub fn local_aabb(&self) -> Aabb {
super::details::local_point_cloud_aabb(self.points())
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_convex_polyhedron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::math::{Isometry, Real};
use crate::shape::ConvexPolyhedron;

impl ConvexPolyhedron {
/// Computes the world-space Aabb of this convex polyhedron, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this convex polyhedron, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
super::details::point_cloud_aabb(pos, self.points())
}

/// Computes the local-space Aabb of this convex polyhedron.
/// Computes the local-space [`Aabb`] of this convex polyhedron.
#[inline]
pub fn local_aabb(&self) -> Aabb {
super::details::local_point_cloud_aabb(self.points())
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_cuboid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::shape::Cuboid;
use crate::utils::IsometryOps;

impl Cuboid {
/// Computes the world-space Aabb of this cuboid, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this cuboid, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
let center = Point::from(pos.translation.vector);
Expand All @@ -13,7 +13,7 @@ impl Cuboid {
Aabb::from_half_extents(center, ws_half_extents)
}

/// Computes the local-space Aabb of this cuboid.
/// Computes the local-space [`Aabb`] of this cuboid.
#[inline]
pub fn local_aabb(&self) -> Aabb {
let half_extents = Point::from(self.half_extents);
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_halfspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use crate::shape::HalfSpace;
use na;

impl HalfSpace {
/// Computes the world-space Aabb of this half-space.
/// Computes the world-space [`Aabb`] of this half-space.
#[inline]
pub fn aabb(&self, _pos: &Isometry<Real>) -> Aabb {
self.local_aabb()
}

/// Computes the local-space Aabb of this half-space.
/// Computes the local-space [`Aabb`] of this half-space.
#[inline]
pub fn local_aabb(&self) -> Aabb {
// We divide by 2.0 so that we can still make some operations with it (like loosening)
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_heightfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::math::{Isometry, Real};
use crate::shape::{GenericHeightField, HeightFieldStorage};

impl<Storage: HeightFieldStorage> GenericHeightField<Storage> {
/// Computes the world-space Aabb of this heightfield, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this heightfield, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
self.root_aabb().transform_by(pos)
}

/// Computes the local-space Aabb of this heightfield.
/// Computes the local-space [`Aabb`] of this heightfield.
#[inline]
pub fn local_aabb(&self) -> Aabb {
self.root_aabb().clone()
Expand Down
12 changes: 6 additions & 6 deletions src/bounding_volume/aabb_support_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::shape::{Cone, Cylinder};

#[cfg(feature = "dim3")]
impl Cone {
/// Computes the world-space Aabb of this cone, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this cone, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
bounding_volume::details::support_map_aabb(pos, self)
}

/// Computes the local-space Aabb of this cone.
/// Computes the local-space [`Aabb`] of this cone.
#[inline]
pub fn local_aabb(&self) -> Aabb {
bounding_volume::details::local_support_map_aabb(self)
Expand All @@ -22,27 +22,27 @@ impl Cone {

#[cfg(feature = "dim3")]
impl Cylinder {
/// Computes the world-space Aabb of this cylinder, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this cylinder, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
bounding_volume::details::support_map_aabb(pos, self)
}

/// Computes the local-space Aabb of this cylinder.
/// Computes the local-space [`Aabb`] of this cylinder.
#[inline]
pub fn local_aabb(&self) -> Aabb {
bounding_volume::details::local_support_map_aabb(self)
}
}

impl Segment {
/// Computes the world-space Aabb of this segment, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this segment, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
self.transformed(pos).local_aabb()
}

/// Computes the local-space Aabb of this segment.
/// Computes the local-space [`Aabb`] of this segment.
#[inline]
pub fn local_aabb(&self) -> Aabb {
bounding_volume::details::local_support_map_aabb(self)
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use crate::{
};

impl Triangle {
/// Computes the world-space Aabb of this triangle, transformed by `pos`.
/// Computes the world-space [`Aabb`] of this triangle, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
self.transformed(pos).local_aabb()
}

/// Computes the local-space Aabb of this triangle.
/// Computes the local-space [`Aabb`] of this triangle.
#[inline]
pub fn local_aabb(&self) -> Aabb {
let a = self.a.coords;
Expand Down
Loading

0 comments on commit 7155e57

Please sign in to comment.