Skip to content

Commit

Permalink
Upgrade non-integration dependencies.
Browse files Browse the repository at this point in the history
This change updates core dependencies to their latest versions at time
of writing. This includes `ndarray`, which now provides more stable
LAPACK builds on a larger variety of targets.
  • Loading branch information
olson-sean-k committed Nov 22, 2024
1 parent 810587b commit 9e3bd9b
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 82 deletions.
23 changes: 10 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ lapack = [
]

[dependencies]
approx = "^0.3.0"
decorum = "^0.3.0"
itertools = "^0.9.0"
num = "^0.3.0"
typenum = "^1.10.0"
approx = "^0.5.0"
decorum = "^0.4.0"
itertools = "^0.13.0"
num = "^0.4.0"
typenum = "^1.17.0"

# Integrations.

Expand All @@ -68,16 +68,13 @@ optional = true

# Platform-specific features.

[target.'cfg(target_os = "linux")'.dependencies.ndarray]
version = "^0.13.0"
[target.'cfg(target_arch = "x86_64")'.dependencies.ndarray]
version = "^0.15.0"
optional = true

# LAPACK packages are difficult to distribute. MKL appears to build reliably on
# Linux, but does not support Windows and yields strange results on MacOS. The
# other supported packages require a more complex build environment.
[target.'cfg(target_os = "linux")'.dependencies.ndarray-linalg]
version = "^0.12.0"
features = ["intel-mkl"]
[target.'cfg(target_arch = "x86_64")'.dependencies.ndarray-linalg]
version = "^0.16.0"
features = ["intel-mkl-static"]
optional = true

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ To support these queries, the `lapack` feature depends on [`ndarray`] and
`lapack` feature and computes a best-fit plane using a singular value
decomposition.

The `lapack` feature only supports Linux at this time.
The `lapack` feature can only be used with the `x86_64` architecture on Linux,
MacOS, and Windows.

[space]: https://en.wikipedia.org/wiki/euclidean_space
[lapack]: https://en.wikipedia.org/wiki/lapack
Expand Down
28 changes: 14 additions & 14 deletions src/adjunct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//! and other traits are provided for `nalgebra` types when the
//! `geometry-nalgebra` feature is enabled.
use decorum::cmp::{self, IntrinsicOrd};
use num::{Bounded, One, Zero};
use decorum::cmp::{self, EmptyOrd};
use num::traits::{Bounded, One, Zero};
use std::ops::{Add, Mul};

pub trait Adjunct: Sized {
Expand Down Expand Up @@ -85,20 +85,20 @@ pub trait ZipMap<T = <Self as Adjunct>::Item>: Adjunct {
self.zip_map(other, |a, b| a * b)
}

fn per_item_min_or_undefined(self, other: Self) -> Self::Output
fn per_item_min_or_empty(self, other: Self) -> Self::Output
where
Self: Adjunct<Item = T>,
T: IntrinsicOrd,
T: EmptyOrd,
{
self.zip_map(other, cmp::min_or_undefined)
self.zip_map(other, cmp::min_or_empty)
}

fn per_item_max_or_undefined(self, other: Self) -> Self::Output
fn per_item_max_or_empty(self, other: Self) -> Self::Output
where
Self: Adjunct<Item = T>,
T: IntrinsicOrd,
T: EmptyOrd,
{
self.zip_map(other, cmp::max_or_undefined)
self.zip_map(other, cmp::max_or_empty)
}
}

Expand All @@ -121,18 +121,18 @@ pub trait Fold: Adjunct {
self.fold(One::one(), |product, n| product * n)
}

fn min_or_undefined(self) -> Self::Item
fn min_or_empty(self) -> Self::Item
where
Self::Item: Bounded + IntrinsicOrd,
Self::Item: Bounded + EmptyOrd,
{
self.fold(Bounded::max_value(), cmp::min_or_undefined)
self.fold(Bounded::max_value(), cmp::min_or_empty)
}

fn max_or_undefined(self) -> Self::Item
fn max_or_empty(self) -> Self::Item
where
Self::Item: Bounded + IntrinsicOrd,
Self::Item: Bounded + EmptyOrd,
{
self.fold(Bounded::min_value(), cmp::max_or_undefined)
self.fold(Bounded::min_value(), cmp::max_or_empty)
}

fn any<F>(self, mut f: F) -> bool
Expand Down
15 changes: 8 additions & 7 deletions src/integration/cgmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use approx::AbsDiffEq;
use cgmath::{BaseFloat, BaseNum, Point2, Point3, Vector2, Vector3, Vector4};
use decorum::{Real, R64};
use num::{Num, NumCast};
use decorum::R64;
use num::traits::real::Real;
use num::traits::{Num, NumCast};
use typenum::consts::{U2, U3, U4};

use crate::adjunct::{
Expand Down Expand Up @@ -319,11 +320,11 @@ where
type ProjectiveSpace = Vector4<T>;
}

impl<T> InnerSpace for Vector2<T> where T: BaseFloat + Real {}
impl<T> InnerSpace for Vector2<T> where T: AbsDiffEq + BaseFloat + Real {}

impl<T> InnerSpace for Vector3<T> where T: BaseFloat + Real {}
impl<T> InnerSpace for Vector3<T> where T: AbsDiffEq + BaseFloat + Real {}

impl<T> InnerSpace for Vector4<T> where T: BaseFloat + Real {}
impl<T> InnerSpace for Vector4<T> where T: AbsDiffEq + BaseFloat + Real {}

impl<T> Interpolate for Vector2<T>
where
Expand Down Expand Up @@ -612,7 +613,7 @@ impl<T> Extend<Point3<T>> for Point2<T> {

impl<T> EuclideanSpace for Point2<T>
where
T: BaseFloat + Real,
T: AbsDiffEq + BaseFloat + Real,
{
type CoordinateSpace = Vector2<T>;

Expand All @@ -623,7 +624,7 @@ where

impl<T> EuclideanSpace for Point3<T>
where
T: BaseFloat + Real,
T: AbsDiffEq + BaseFloat + Real,
{
type CoordinateSpace = Vector3<T>;

Expand Down
2 changes: 1 addition & 1 deletion src/integration/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use decorum::R64;
use mint::{Point2, Point3, Vector2, Vector3};
use num::{Num, NumCast, One, Zero};
use num::traits::{Num, NumCast, One, Zero};
use std::ops::Neg;
use typenum::{U2, U3};

Expand Down
5 changes: 3 additions & 2 deletions src/integration/nalgebra.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(feature = "geometry-nalgebra")]

use approx::AbsDiffEq;
use decorum::{Real, R64};
use decorum::R64;
use nalgebra::base::allocator::Allocator;
use nalgebra::base::default_allocator::DefaultAllocator;
use nalgebra::base::dimension::{
Expand All @@ -12,7 +12,8 @@ use nalgebra::base::{
Matrix2, Matrix3, MatrixMN, RowVector2, RowVector3, Scalar, Vector2, Vector3, Vector4, VectorN,
};
use nalgebra::geometry::{Point, Point2, Point3};
use num::{Num, NumCast, One, Zero};
use num::traits::real::Real;
use num::traits::{Num, NumCast, One, Zero};
use std::ops::{AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use typenum::NonZero;

Expand Down
5 changes: 4 additions & 1 deletion src/lapack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ where
let columns = columns.as_ref();
let n = columns.len();
convert::into_matrix(
MatrixLayout::F((n as i32, <U as FiniteDimensional>::N::USIZE as i32)),
MatrixLayout::F {
col: n as i32,
lda: <U as FiniteDimensional>::N::USIZE as i32,
},
columns
.iter()
.map(f)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod space;
mod integration;

use decorum::R64;
use num::{self, Num, NumCast, One, Zero};
use num::traits::{Num, NumCast, One, Zero};

use crate::space::EuclideanSpace;

Expand Down
2 changes: 1 addition & 1 deletion src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait Interpolate<T = Self>: Sized {
fn lerp(self, other: T, f: R64) -> Self::Output;

fn midpoint(self, other: T) -> Self::Output {
self.lerp(other, 0.5.into())
self.lerp(other, R64::assert(0.5))
}
}

Expand Down
71 changes: 33 additions & 38 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
//! This module provides types and traits for performing spatial queries.
use approx::abs_diff_eq;
use decorum::cmp::IntrinsicOrd;
use decorum::Infinite;
use num::{Bounded, Signed, Zero};
use decorum::cmp::EmptyOrd;
use decorum::InfinityEncoding;
use num::traits::real::Real;
use num::traits::{Bounded, Signed, Zero};
use std::fmt::{self, Debug, Formatter};
use std::ops::Neg;
use typenum::type_operators::Cmp;
Expand Down Expand Up @@ -642,13 +643,13 @@ where
pub fn from_points<I>(points: I) -> Self
where
I: IntoIterator<Item = S>,
Scalar<S>: IntrinsicOrd,
Scalar<S>: EmptyOrd,
{
let mut min = S::origin();
let mut max = S::origin();
for point in points {
min = min.per_item_min_or_undefined(point);
max = max.per_item_max_or_undefined(point);
min = min.per_item_min_or_empty(point);
max = max.per_item_max_or_empty(point);
}
Aabb {
origin: min,
Expand All @@ -662,16 +663,16 @@ where

pub fn upper_bound(&self) -> S
where
Scalar<S>: IntrinsicOrd,
Scalar<S>: EmptyOrd,
{
self.origin.per_item_max_or_undefined(self.endpoint())
self.origin.per_item_max_or_empty(self.endpoint())
}

pub fn lower_bound(&self) -> S
where
Scalar<S>: IntrinsicOrd,
Scalar<S>: EmptyOrd,
{
self.origin.per_item_min_or_undefined(self.endpoint())
self.origin.per_item_min_or_empty(self.endpoint())
}

/// Gets the Lebesgue measure ($n$-dimensional volume) of the bounding box.
Expand All @@ -686,15 +687,10 @@ where

pub fn union(&self, aabb: &Self) -> Self
where
Scalar<S>: IntrinsicOrd,
Scalar<S>: EmptyOrd,
{
let origin = self
.lower_bound()
.per_item_min_or_undefined(aabb.lower_bound());
let extent = self
.upper_bound()
.per_item_max_or_undefined(aabb.upper_bound())
- origin;
let origin = self.lower_bound().per_item_min_or_empty(aabb.lower_bound());
let extent = self.upper_bound().per_item_max_or_empty(aabb.upper_bound()) - origin;
Aabb { origin, extent }
}
}
Expand Down Expand Up @@ -729,14 +725,14 @@ where
impl<S> Intersection<S> for Aabb<S>
where
S: EuclideanSpace,
Scalar<S>: IntrinsicOrd + Signed,
Scalar<S>: EmptyOrd + Signed,
{
type Output = Vector<S>;

fn intersection(&self, point: &S) -> Option<Self::Output> {
let aabb = self;
let lower = aabb.lower_bound().per_item_max_or_undefined(*point);
let upper = aabb.upper_bound().per_item_min_or_undefined(*point);
let lower = aabb.lower_bound().per_item_max_or_empty(*point);
let upper = aabb.upper_bound().per_item_min_or_empty(*point);
if lower == upper {
Some(*point - aabb.lower_bound())
}
Expand All @@ -751,19 +747,19 @@ impl_symmetrical_intersection!(Aabb);
impl<S> Intersection<Aabb<S>> for Aabb<S>
where
S: EuclideanSpace,
Scalar<S>: IntrinsicOrd + Signed,
Scalar<S>: EmptyOrd + Signed,
{
type Output = Self;

fn intersection(&self, other: &Aabb<S>) -> Option<Self::Output> {
let max_lower_bound = self
.lower_bound()
.per_item_max_or_undefined(other.lower_bound());
.per_item_max_or_empty(other.lower_bound());
let min_upper_bound = self
.upper_bound()
.per_item_min_or_undefined(other.upper_bound());
.per_item_min_or_empty(other.upper_bound());
let difference = min_upper_bound - max_lower_bound;
if difference.all(|x| (!x.is_undefined()) && x.is_positive()) {
if difference.all(|x| (!x.is_empty()) && x.is_positive()) {
Some(Aabb {
origin: max_lower_bound,
extent: difference,
Expand All @@ -779,7 +775,7 @@ where
impl<S> Intersection<Ray<S>> for Aabb<S>
where
S: EuclideanSpace,
Scalar<S>: Bounded + Infinite + IntrinsicOrd + Signed,
Scalar<S>: Bounded + EmptyOrd + InfinityEncoding + Signed,
{
/// The minimum and maximum _times of impact_ of the intersection.
///
Expand Down Expand Up @@ -833,13 +829,9 @@ where
let direction = *ray.direction.get();
let origin = (aabb.origin - ray.origin).zip_map(direction, pdiv);
let endpoint = ((aabb.endpoint()) - ray.origin).zip_map(direction, pdiv);
let min = origin
.per_item_min_or_undefined(endpoint)
.max_or_undefined();
let max = origin
.per_item_max_or_undefined(endpoint)
.min_or_undefined();
if max.is_negative() || min > max || min.is_undefined() || max.is_undefined() {
let min = origin.per_item_min_or_empty(endpoint).max_or_empty();
let max = origin.per_item_max_or_empty(endpoint).min_or_empty();
if max.is_negative() || min > max || min.is_empty() || max.is_empty() {
None
}
else {
Expand Down Expand Up @@ -969,13 +961,16 @@ impl_symmetrical_intersection!(Plane, Ray);

#[cfg(all(test, feature = "geometry-nalgebra"))]
mod tests {
use decorum::N64;
use decorum::real::UnaryRealFunction;
use decorum::ExtendedReal;
use nalgebra::{Point2, Point3};

use crate::adjunct::Converged;
use crate::query::{Aabb, Intersection, Line, LineLine, Plane, PlaneRay, Ray, Unit};
use crate::space::{EuclideanSpace, Vector, VectorSpace};

type X64 = ExtendedReal<f64>;

type E2 = Point2<f64>;
type E3 = Point3<f64>;

Expand Down Expand Up @@ -1051,15 +1046,15 @@ mod tests {
// intersection of `Aabb` and `Ray`.
#[test]
fn aabb_ray_intersection_nan() {
let aabb = Aabb::<Point2<N64>> {
let aabb = Aabb::<Point2<X64>> {
origin: EuclideanSpace::origin(),
extent: Converged::converged(1.0.into()),
extent: Converged::converged(X64::ONE),
};
let ray = Ray::<Point2<N64>> {
let ray = Ray::<Point2<X64>> {
origin: EuclideanSpace::origin(),
direction: Unit::x(),
};
assert_eq!(Some((0.0.into(), 1.0.into())), ray.intersection(&aabb));
assert_eq!(Some((X64::ZERO, X64::ONE)), ray.intersection(&aabb));
}

#[test]
Expand Down
Loading

0 comments on commit 9e3bd9b

Please sign in to comment.