Skip to content
Merged
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
12 changes: 6 additions & 6 deletions crates/mapping-algorithms/src/geo/haversine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*/

use nalgebra::{Point2, RealField, Scalar};
use num_traits::Float;
use num_traits::{ConstOne, Float};

#[inline]
fn half_angle_sine_squared<T>(input: T) -> T
where
T: Float,
T: ConstOne + Float,
{
(input.to_radians() / (T::one() + T::one())).sin().powi(2)
(input.to_radians() / (T::ONE + T::ONE)).sin().powi(2)
}

/// Calculates the Haversine distance between two points on a sphere using floating-point arithmetic.
Expand All @@ -54,7 +54,7 @@ pub fn calculate_haversine_distance<T>(
sphere_radius: T,
) -> T
where
T: Scalar + Float,
T: ConstOne + Scalar + Float,
{
let delta_lat = point_b.x - point_a.x;
let delta_lon = point_b.y - point_a.y;
Expand All @@ -65,10 +65,10 @@ where
let basic_haversine = half_angle_sine_squared(delta_lat)
+ half_angle_sine_squared(delta_lon) * lat1_radians.cos() * lat2_radians.cos();

let inverse_haversine = (T::one() + T::one())
let inverse_haversine = (T::ONE + T::ONE)
* basic_haversine
.sqrt()
.atan2((T::one() - basic_haversine).sqrt());
.atan2((T::ONE - basic_haversine).sqrt());

sphere_radius * inverse_haversine
}
Expand Down
29 changes: 15 additions & 14 deletions crates/mapping-algorithms/src/lines/bresenham.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

use nalgebra::{ComplexField, Point, RealField, Scalar};
use num_traits::AsPrimitive;
use num_traits::{AsPrimitive, ConstOne, ConstZero};

use crate::{FusedIterator, Vec, array, fmt, marker::PhantomData};

Expand Down Expand Up @@ -76,7 +76,8 @@ pub struct BresenhamLine<F: RealField, T, const N: usize> {
_output: PhantomData<fn() -> T>,
}

impl<F: RealField + Copy + AsPrimitive<usize>, T, const N: usize> BresenhamLine<F, T, N>
impl<F: ConstOne + ConstZero + RealField + Copy + AsPrimitive<usize>, T, const N: usize>
BresenhamLine<F, T, N>
where
usize: AsPrimitive<F>,
{
Expand Down Expand Up @@ -115,16 +116,16 @@ where

let steps: [F; N] = array::from_fn(|idx| {
if end_point[idx] > start_point[idx] {
F::one()
F::ONE
} else {
-F::one()
-F::ONE
}
});

// Deltas are absolute, so zero is a valid starting maximum.
// comparing with `>=` lets the last of several equal axes win.
let (primary_axis, primary_delta) = deltas.iter().enumerate().fold(
(0, F::zero()),
(0, F::ZERO),
|(primary_axis, primary_delta), (idx, &delta)| {
if delta >= primary_delta {
(idx, delta)
Expand All @@ -135,7 +136,7 @@ where
);

let increments: [F; N] = if primary_delta.is_zero() {
[F::zero(); N]
[F::ZERO; N]
} else {
array::from_fn(|idx| deltas[idx] / primary_delta)
};
Expand All @@ -145,16 +146,16 @@ where
end: end_point,
increments,
steps,
errors: [F::zero(); N],
errors: [F::ZERO; N],
primary_axis,
threshold: F::one() - (F::one() / <usize as AsPrimitive<F>>::as_(N + 1)),
remaining: <F as AsPrimitive<usize>>::as_(primary_delta + F::one()),
threshold: F::ONE - (F::ONE / <usize as AsPrimitive<F>>::as_(N + 1)),
remaining: <F as AsPrimitive<usize>>::as_(primary_delta + F::ONE),
_output: PhantomData,
})
}
}

impl<F: RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> Iterator
impl<F: ConstOne + RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> Iterator
for BresenhamLine<F, T, N>
{
type Item = Point<T, N>;
Expand All @@ -176,7 +177,7 @@ impl<F: RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> Iterator
self.errors[axis] += self.increments[axis];
if self.errors[axis] >= self.threshold {
self.current[axis] += self.steps[axis];
self.errors[axis] -= F::one();
self.errors[axis] -= F::ONE;
}
}

Expand All @@ -191,12 +192,12 @@ impl<F: RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> Iterator
}
}

impl<F: RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> ExactSizeIterator
impl<F: ConstOne + RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> ExactSizeIterator
for BresenhamLine<F, T, N>
{
}

impl<F: RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> FusedIterator
impl<F: ConstOne + RealField + AsPrimitive<T>, T: Scalar + Copy, const N: usize> FusedIterator
for BresenhamLine<F, T, N>
{
}
Expand Down Expand Up @@ -232,7 +233,7 @@ pub fn plot_bresenham_line<F, T, const N: usize>(
end_point: Point<F, N>,
) -> Result<Vec<Point<T, N>>, BresenhamError>
where
F: RealField + AsPrimitive<usize> + AsPrimitive<T>,
F: ConstOne + ConstZero + RealField + AsPrimitive<usize> + AsPrimitive<T>,
usize: AsPrimitive<F>,
T: Scalar + Copy,
{
Expand Down
6 changes: 3 additions & 3 deletions crates/mapping-algorithms/src/point_clouds/icp/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use nalgebra::{
ArrayStorage, ClosedAddAssign, ClosedDivAssign, ClosedSubAssign, Const, Matrix, Point, SMatrix,
Scalar, Vector,
};
use num_traits::{AsPrimitive, NumOps, Zero};
use num_traits::{AsPrimitive, ConstZero, NumOps};

use crate::{Sum, array, point_clouds::calculate_point_cloud_center, utils::distance_squared};

Expand Down Expand Up @@ -119,7 +119,7 @@ pub(crate) fn get_rotation_matrix_and_centroids<T, const N: usize>(
closest_points: &[Point<T, N>],
) -> (SMatrix<T, N, N>, Point<T, N>, Point<T, N>)
where
T: ClosedAddAssign + ClosedDivAssign + ClosedSubAssign + Copy + NumOps + Scalar + Zero,
T: ClosedAddAssign + ClosedDivAssign + ClosedSubAssign + ConstZero + Copy + NumOps + Scalar,
usize: AsPrimitive<T>,
{
let (mean_transformed_a, mean_closest) = (
Expand All @@ -128,7 +128,7 @@ where
);

let rot_mat = transformed_points_a.iter().zip(closest_points.iter()).fold(
Matrix::from_array_storage(ArrayStorage([[T::zero(); N]; N])),
Matrix::from_array_storage(ArrayStorage([[T::ZERO; N]; N])),
|rot_mat, (transformed_point_a, closest_point)| {
let a_distance_from_centroid = transformed_point_a - mean_transformed_a;
let closest_point_distance_from_centroid = closest_point - mean_closest;
Expand Down
6 changes: 3 additions & 3 deletions crates/mapping-algorithms/src/point_clouds/icp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
pub use types::{ICPConfiguration, ICPConfigurationBuilder, ICPError, ICPResult, ICPSuccess};

use nalgebra::{ComplexField, Isometry, Point, RealField, SimdRealField};
use num_traits::{AsPrimitive, Bounded};
use num_traits::{AsPrimitive, Bounded, ConstZero};

use crate::{
Sum, Vec,
Expand Down Expand Up @@ -76,7 +76,7 @@ pub fn icp_iteration<T, const N: usize>(
config: &ICPConfiguration<T>,
) -> Result<T, ICPError<T, N>>
where
T: Bounded + Copy + Default + RealField + Sum + SimdRealField,
T: Bounded + ConstZero + Copy + Default + RealField + Sum + SimdRealField,
usize: AsPrimitive<T>,
IsometryAbstractor<T, N>: AbstractIsometry<T, N>,
{
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn icp<T, const N: usize>(
config: ICPConfiguration<T>,
) -> ICPResult<T, <IsometryAbstractor<T, N> as AbstractIsometry<T, N>>::RotType, N>
where
T: Bounded + Copy + Default + IsNan + RealField + Sum,
T: Bounded + ConstZero + Copy + Default + IsNan + RealField + Sum,
usize: AsPrimitive<T>,
IsometryAbstractor<T, N>: AbstractIsometry<T, N>,
{
Expand Down
6 changes: 3 additions & 3 deletions crates/mapping-algorithms/src/point_clouds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{Vec, array};
use nalgebra::{
AbstractRotation, ClosedAddAssign, ClosedDivAssign, Isometry, Point, RealField, Scalar,
};
use num_traits::{AsPrimitive, Zero};
use num_traits::{AsPrimitive, ConstZero};
use rand::distr::uniform::SampleUniform;
use rand::{RngExt, SeedableRng};

Expand Down Expand Up @@ -60,7 +60,7 @@ mod nearest_neighbour;
)]
pub fn calculate_point_cloud_center<T, const N: usize>(points: &[Point<T, N>]) -> Point<T, N>
where
T: ClosedAddAssign + ClosedDivAssign + Copy + Scalar + Zero,
T: ClosedAddAssign + ClosedDivAssign + ConstZero + Copy + Scalar,
usize: AsPrimitive<T>,
{
if points.is_empty() {
Expand All @@ -69,7 +69,7 @@ where

points
.iter()
.fold(Point::<T, N>::from([T::zero(); N]), |acc, it| {
.fold(Point::<T, N>::from([T::ZERO; N]), |acc, it| {
Point::from(acc.coords + it.coords)
})
/ points.len().as_()
Expand Down
8 changes: 4 additions & 4 deletions crates/mapping-algorithms/src/polygons/graham_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use core::fmt::Debug;
use nalgebra::{ComplexField, Point2};
use num_traits::{AsPrimitive, NumAssign};
use num_traits::{AsPrimitive, ConstZero, NumAssign};

use crate::{
ToOwned, Vec, VecDeque,
Expand All @@ -39,7 +39,7 @@ use super::calculate_determinant;
)]
fn build_hull_segment<
'a,
O: ComplexField + Copy + PartialOrd,
O: ComplexField + ConstZero + Copy + PartialOrd,
T: AsPrimitive<O> + Debug + IsNan + NumAssign + PartialOrd,
>(
mut accumulator: VecDeque<&'a Point2<T>>,
Expand All @@ -50,7 +50,7 @@ fn build_hull_segment<
accumulator[accumulator.len() - 2],
accumulator[accumulator.len() - 1],
current_point,
) <= O::zero()
) <= O::ZERO
{
accumulator.pop_back();
}
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn graham_scan<O, T>(
voxel_size: Option<O>,
) -> Option<Vec<Point2<T>>>
where
O: AsPrimitive<isize> + ComplexField + Copy + PartialOrd,
O: AsPrimitive<isize> + ComplexField + ConstZero + Copy + PartialOrd,
T: AsPrimitive<O> + Debug + IsNan + NumAssign + PartialOrd,
usize: AsPrimitive<T>,
{
Expand Down
6 changes: 3 additions & 3 deletions crates/mapping-algorithms/src/polygons/jarvis_march.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

use nalgebra::{ComplexField, Point2, Scalar};
use num_traits::{AsPrimitive, NumAssign, real::Real};
use num_traits::{AsPrimitive, ConstZero, NumAssign, real::Real};

use crate::{Ordering, Vec, point_clouds::downsample_point_cloud_voxel};

Expand All @@ -47,7 +47,7 @@ use super::calculate_determinant;
)]
pub fn jarvis_march<O, T>(points: &[Point2<T>], voxel_size: Option<O>) -> Option<Vec<Point2<T>>>
where
O: AsPrimitive<isize> + ComplexField + Copy + Real,
O: AsPrimitive<isize> + ComplexField + ConstZero + Copy + Real,
T: AsPrimitive<O> + NumAssign + PartialOrd + Scalar,
usize: AsPrimitive<T>,
{
Expand Down Expand Up @@ -80,7 +80,7 @@ where
let mut endpoint = &points_downsampled_slice[0];
for point in points_downsampled_slice {
if endpoint == current_vertex
|| calculate_determinant(hull.last().unwrap(), endpoint, point) < O::zero()
|| calculate_determinant(hull.last().unwrap(), endpoint, point) < O::ZERO
{
endpoint = point;
}
Expand Down
5 changes: 3 additions & 2 deletions crates/mapping-algorithms/src/types/isometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use nalgebra::{
AbstractRotation, Isometry, Point, RealField, SMatrix, UnitComplex, UnitQuaternion,
};
use num_traits::{ConstOne, ConstZero};

use crate::{marker::PhantomData, utils::verify_rotation_matrix_determinant};

Expand Down Expand Up @@ -52,7 +53,7 @@ pub trait AbstractIsometry<T: RealField, const N: usize> {

impl<T> AbstractIsometry<T, 2> for IsometryAbstractor<T, 2>
where
T: Copy + RealField,
T: ConstOne + ConstZero + Copy + RealField,
{
type RotType = UnitComplex<T>;

Expand All @@ -77,7 +78,7 @@ where

impl<T> AbstractIsometry<T, 3> for IsometryAbstractor<T, 3>
where
T: Copy + RealField,
T: ConstOne + ConstZero + Copy + RealField,
{
type RotType = UnitQuaternion<T>;

Expand Down
8 changes: 4 additions & 4 deletions crates/mapping-algorithms/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

use nalgebra::{Const, DimMin, Point, RealField, SMatrix, Scalar};
use num_traits::NumOps;
use num_traits::{ConstOne, ConstZero, NumOps};

#[cfg_attr(
feature = "tracing",
Expand Down Expand Up @@ -51,13 +51,13 @@ pub(crate) fn verify_rotation_matrix_determinant<T, const N: usize>(
v_t: SMatrix<T, N, N>,
) -> SMatrix<T, N, N>
where
T: Copy + RealField,
T: ConstOne + ConstZero + Copy + RealField,
Const<N>: DimMin<Const<N>, Output = Const<N>>,
{
if (u * v_t).determinant() < T::zero() {
if (u * v_t).determinant() < T::ZERO {
u.column_mut(N - 1)
.iter_mut()
.for_each(|element| *element *= T::one().neg()); // Reverse the last column
.for_each(|element| *element *= T::ONE.neg()); // Reverse the last column
}
u * v_t
}
Expand Down
Loading