Skip to content

experiment with removing 'Real' from popular types #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/parry2d/examples/point_in_poly2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ async fn main() {
.iter_mut()
.for_each(|pt| *pt = animation_rotation * *pt);

draw_polygon(&polygon, RENDER_SCALE, polygon_render_pos, BLUE);
draw_polygon(polygon, RENDER_SCALE, polygon_render_pos, BLUE);

/*
* Compute polygon intersections.
*/
for point in &test_points {
if point_in_poly2d(point, &polygon) {
if point_in_poly2d(point, polygon) {
draw_point(*point, RENDER_SCALE, polygon_render_pos, RED);
} else {
draw_point(*point, RENDER_SCALE, polygon_render_pos, GREEN);
Expand Down
2 changes: 1 addition & 1 deletion crates/parry2d/examples/raycasts_animated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn main() {

fn draw_polygon(
polygon: &[Point2<f32>],
pose: &Isometry<f32>,
pose: &Isometry,
scale: f32,
shift: Point2<f32>,
color: Color,
Expand Down
10 changes: 5 additions & 5 deletions crates/parry2d/tests/geometry/epa_convergence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use na::Vector2;
use parry2d::{
math::{Isometry, Point, Real},
math::{Isometry, Point},
query,
shape::{Capsule, ConvexPolygon, SharedShape},
};
Expand All @@ -9,10 +9,10 @@ use parry2d::{
#[test]
fn capsule_convergence() {
let shape1 = Capsule::new_y(5.0, 10.0);
let mut vec = Vec::<Point<Real>>::with_capacity(3);
vec.push(Point::<Real>::new(64.0, 507.0));
vec.push(Point::<Real>::new(440.0, 326.0));
vec.push(Point::<Real>::new(1072.0, 507.0));
let mut vec = Vec::<Point>::with_capacity(3);
vec.push(Point::new(64.0, 507.0));
vec.push(Point::new(440.0, 326.0));
vec.push(Point::new(1072.0, 507.0));
let shape2 = ConvexPolygon::from_convex_polyline(vec);
let shape2 = shape2.unwrap();
let transform1 = Isometry::new(Vector2::new(381.592, 348.491), 0.0);
Expand Down
20 changes: 10 additions & 10 deletions crates/parry3d/benches/common/default_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ where

impl DefaultGen for Cuboid
where
Standard: Distribution<Vector<Real>>,
Standard: Distribution<Vector>,
{
fn generate<R: Rng>(rng: &mut R) -> Cuboid {
Cuboid::new(rng.gen::<Vector<Real>>().abs())
Cuboid::new(rng.gen::<Vector>().abs())
}
}

Expand All @@ -77,8 +77,8 @@ where
{
fn generate<R: Rng>(rng: &mut R) -> Capsule {
Capsule::new(
rng.gen::<Point<Real>>(),
rng.gen::<Point<Real>>(),
rng.gen::<Point>(),
rng.gen::<Point>(),
rng.gen::<Real>().abs(),
)
}
Expand All @@ -104,7 +104,7 @@ where

impl DefaultGen for Segment
where
Standard: Distribution<Point<Real>>,
Standard: Distribution<Point>,
{
fn generate<R: Rng>(rng: &mut R) -> Segment {
Segment::new(rng.gen(), rng.gen())
Expand All @@ -113,7 +113,7 @@ where

impl DefaultGen for Triangle
where
Standard: Distribution<Point<Real>>,
Standard: Distribution<Point>,
{
fn generate<R: Rng>(rng: &mut R) -> Triangle {
Triangle::new(rng.gen(), rng.gen(), rng.gen())
Expand All @@ -134,22 +134,22 @@ where

impl DefaultGen for Ray
where
Standard: Distribution<Vector<Real>>,
Standard: Distribution<Vector>,
{
fn generate<R: Rng>(rng: &mut R) -> Ray {
// The generate ray will always point to the origin.
let shift = rng.gen::<Vector<Real>>() * na::convert::<_, Real>(10.0f64);
let shift = rng.gen::<Vector>() * na::convert::<_, Real>(10.0f64);
Ray::new(Point::origin() + shift, -shift)
}
}

impl DefaultGen for Aabb
where
Standard: Distribution<Vector<Real>>,
Standard: Distribution<Vector>,
{
fn generate<R: Rng>(rng: &mut R) -> Aabb {
// an Aabb centered at the origin.
let half_extents = rng.gen::<Vector<Real>>().abs();
let half_extents = rng.gen::<Vector>().abs();
Aabb::new(
Point::origin() + (-half_extents),
Point::origin() + half_extents,
Expand Down
13 changes: 5 additions & 8 deletions crates/parry3d/examples/common_macroquad3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,13 @@ pub fn mquad_mesh_from_points(
let vertices: Vec<Vertex> =
mquad_compute_normals_and_bake_light(&mquad_points, &mquad_indices, light_pos);
// Regenerate the index for each vertex.
let indices: Vec<u16> = (0..vertices.len() * 3)
.into_iter()
.map(|i| i as u16)
.collect();
let mesh = Mesh {
let indices: Vec<u16> = (0..vertices.len() * 3).map(|i| i as u16).collect();

Mesh {
vertices,
indices,
texture: None,
};
mesh
}
}

/// Bakes light into vertices, using an hardcoded light strength.
Expand Down Expand Up @@ -158,7 +155,7 @@ pub fn mquad_compute_normals_and_bake_light(
vertices.push(Vertex {
position: points[i as usize].position,
uv: Vec2::ZERO,
color: color,
color,
normal: Vec4::ZERO,
});
}
Expand Down
10 changes: 6 additions & 4 deletions crates/parry3d/tests/geometry/cuboid_ray_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ where

let intersection = shape
.cast_ray_and_get_normal(&position, &ray, std::f32::MAX, true)
.expect(&format!(
"Ray {:?} did not hit Shape {} rotated with {:?}",
ray, name, rotation
));
.unwrap_or_else(|| {
panic!(
"Ray {:?} did not hit Shape {} rotated with {:?}",
ray, name, rotation
)
});

let point = ray.origin + ray.dir * intersection.time_of_impact;
let point_nudged_in = point + intersection.normal * -0.001;
Expand Down
2 changes: 1 addition & 1 deletion crates/parry3d/tests/geometry/epa3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn triangle_vertex_touches_triangle_edge_epa() {
&Isometry3::identity(),
&mesh1,
&mesh2,
0.00999999977,
0.01,
&mut VoronoiSimplex::new(),
None,
);
Expand Down
3 changes: 1 addition & 2 deletions crates/parry3d/tests/geometry/time_of_impact3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use na::{self, Isometry3, Vector3};
use parry3d::math::Real;
use parry3d::query::{self, ShapeCastOptions};
use parry3d::shape::{Ball, Cuboid};

Expand Down Expand Up @@ -56,7 +55,7 @@ fn ball_cuboid_toi() {
assert_eq!(toi_intersecting, Some(0.0));
assert!(relative_eq!(
toi_will_touch.unwrap(),
((3.0 as Real).sqrt() - 1.0) / (ball_vel2 - cuboid_vel2).norm()
(3.0_f32.sqrt() - 1.0) / (ball_vel2 - cuboid_vel2).norm()
));
assert_eq!(toi_wont_touch, None);
}
4 changes: 2 additions & 2 deletions crates/parry3d/tests/geometry/trimesh_intersection.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use na::{Point3, Vector3};
use parry3d::math::{Isometry, Real};
use parry3d::math::Isometry;
use parry3d::query::IntersectResult;
use parry3d::shape::TriMesh;

fn build_diamond(position: &Isometry<Real>) -> TriMesh {
fn build_diamond(position: &Isometry) -> TriMesh {
// Two tetrahedrons sharing a face
let points = vec![
position * Point3::new(0.0, 2.0, 0.0),
Expand Down
54 changes: 27 additions & 27 deletions src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use rkyv::{bytecheck, CheckBytes};
#[derive(Debug, PartialEq, Copy, Clone)]
#[repr(C)]
pub struct Aabb {
pub mins: Point<Real>,
pub maxs: Point<Real>,
pub mins: Point,
pub maxs: Point,
}

impl Aabb {
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Aabb {
/// * `maxs` - position of the point with the highest coordinates. Each component of `mins`
/// must be smaller than the related components of `maxs`.
#[inline]
pub fn new(mins: Point<Real>, maxs: Point<Real>) -> Aabb {
pub fn new(mins: Point, maxs: Point) -> Aabb {
Aabb { mins, maxs }
}

Expand All @@ -109,27 +109,27 @@ impl Aabb {

/// 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 {
pub fn from_half_extents(center: Point, half_extents: Vector) -> Self {
Self::new(center - half_extents, center + half_extents)
}

/// 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>>,
I: IntoIterator<Item = &'a Point>,
{
super::aabb_utils::local_point_cloud_aabb(pts)
}

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

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

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

/// Enlarges this `Aabb` so it also contains the point `pt`.
pub fn take_point(&mut self, pt: Point<Real>) {
pub fn take_point(&mut self, pt: Point) {
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`.
#[inline]
pub fn transform_by(&self, m: &Isometry<Real>) -> Self {
pub fn transform_by(&self, m: &Isometry) -> Self {
let ls_center = self.center();
let center = m * ls_center;
let ws_half_extents = m.absolute_transform_vector(&self.half_extents());
Expand All @@ -167,7 +167,7 @@ impl Aabb {
}

#[inline]
pub fn scaled(self, scale: &Vector<Real>) -> Self {
pub fn scaled(self, scale: &Vector) -> Self {
let a = self.mins.coords.component_mul(scale);
let b = self.maxs.coords.component_mul(scale);
Self {
Expand All @@ -184,7 +184,7 @@ impl Aabb {
/// by its absolute value.
#[inline]
#[must_use]
pub fn scaled_wrt_center(self, scale: &Vector<Real>) -> Self {
pub fn scaled_wrt_center(self, scale: &Vector) -> Self {
let center = self.center();
// Multiply the extents by the scale. Negative scaling might modify the half-extent
// sign, so we take the absolute value. The AABB being symmetric that absolute value
Expand All @@ -203,7 +203,7 @@ impl Aabb {

/// Does this AABB contains a point expressed in the same coordinate frame as `self`?
#[inline]
pub fn contains_local_point(&self, point: &Point<Real>) -> bool {
pub fn contains_local_point(&self, point: &Point) -> bool {
for i in 0..DIM {
if point[i] < self.mins[i] || point[i] > self.maxs[i] {
return false;
Expand All @@ -215,7 +215,7 @@ impl Aabb {

/// Does this AABB intersects an AABB `aabb2` moving at velocity `vel12` relative to `self`?
#[inline]
pub fn intersects_moving_aabb(&self, aabb2: &Self, vel12: Vector<Real>) -> bool {
pub fn intersects_moving_aabb(&self, aabb2: &Self, vel12: Vector) -> bool {
// Minkowski sum.
let msum = Aabb {
mins: self.mins - aabb2.maxs.coords,
Expand Down Expand Up @@ -311,7 +311,7 @@ impl Aabb {
/// Computes the vertices of this `Aabb`.
#[inline]
#[cfg(feature = "dim2")]
pub fn vertices(&self) -> [Point<Real>; 4] {
pub fn vertices(&self) -> [Point; 4] {
[
Point::new(self.mins.x, self.mins.y),
Point::new(self.mins.x, self.maxs.y),
Expand All @@ -323,7 +323,7 @@ impl Aabb {
/// Computes the vertices of this `Aabb`.
#[inline]
#[cfg(feature = "dim3")]
pub fn vertices(&self) -> [Point<Real>; 8] {
pub fn vertices(&self) -> [Point; 8] {
[
Point::new(self.mins.x, self.mins.y, self.mins.z),
Point::new(self.maxs.x, self.mins.y, self.mins.z),
Expand Down Expand Up @@ -399,7 +399,7 @@ impl Aabb {
}

/// Projects every point of `Aabb` on an arbitrary axis.
pub fn project_on_axis(&self, axis: &UnitVector<Real>) -> (Real, Real) {
pub fn project_on_axis(&self, axis: &UnitVector) -> (Real, Real) {
let cuboid = Cuboid::new(self.half_extents());
let shift = cuboid
.local_support_point_toward(axis)
Expand All @@ -414,27 +414,27 @@ impl Aabb {
#[cfg(feature = "std")]
pub fn intersects_spiral(
&self,
point: &Point<Real>,
center: &Point<Real>,
axis: &UnitVector<Real>,
linvel: &Vector<Real>,
point: &Point,
center: &Point,
axis: &UnitVector,
linvel: &Vector,
angvel: Real,
) -> bool {
use crate::utils::WBasis;
use crate::utils::{Interval, IntervalFunction};

struct SpiralPlaneDistance {
center: Point<Real>,
tangents: [Vector<Real>; 2],
linvel: Vector<Real>,
center: Point,
tangents: [Vector; 2],
linvel: Vector,
angvel: Real,
point: na::Vector2<Real>,
plane: Vector<Real>,
plane: Vector,
bias: Real,
}

impl SpiralPlaneDistance {
fn spiral_pt_at(&self, t: Real) -> Point<Real> {
fn spiral_pt_at(&self, t: Real) -> Point {
let angle = t * self.angvel;

// NOTE: we construct the rotation matrix explicitly here instead
Expand Down Expand Up @@ -544,7 +544,7 @@ impl Aabb {

impl BoundingVolume for Aabb {
#[inline]
fn center(&self) -> Point<Real> {
fn center(&self) -> Point {
self.center()
}

Expand Down
Loading