Skip to content

Commit

Permalink
Remove arrayvec dependency.
Browse files Browse the repository at this point in the history
The `arrayvec` crate was used to provide a stack-allocated and
fixed-sized `Bases` type, which requires `IntoIterator`. In prior
versions of Rust, primitive arrays did not implement `IntoIterator`, but
they now do. This change replaces `ArrayVec` with primitive arrays.
  • Loading branch information
olson-sean-k committed Nov 22, 2024
1 parent 5af45d7 commit 810587b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 63 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ lapack = [

[dependencies]
approx = "^0.3.0"
arrayvec = "^0.5.1"
decorum = "^0.3.0"
itertools = "^0.9.0"
num = "^0.3.0"
Expand Down
9 changes: 4 additions & 5 deletions src/adjunct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! and other traits are provided for `nalgebra` types when the
//! `geometry-nalgebra` feature is enabled.
use arrayvec::ArrayVec;
use decorum::cmp::{self, IntrinsicOrd};
use num::{Bounded, One, Zero};
use std::ops::{Add, Mul};
Expand Down Expand Up @@ -235,18 +234,18 @@ impl<T> FromItems for (T, T, T) {
}

impl<T> IntoItems for (T, T) {
type Output = ArrayVec<[T; 2]>;
type Output = [T; 2];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.0, self.1])
[self.0, self.1]
}
}

impl<T> IntoItems for (T, T, T) {
type Output = ArrayVec<[T; 3]>;
type Output = [T; 3];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.0, self.1, self.2])
[self.0, self.1, self.2]
}
}

Expand Down
35 changes: 17 additions & 18 deletions src/integration/cgmath.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![cfg(feature = "geometry-cgmath")]

use approx::AbsDiffEq;
use arrayvec::ArrayVec;
use cgmath::{BaseFloat, BaseNum, Point2, Point3, Vector2, Vector3, Vector4};
use decorum::{Real, R64};
use num::{Num, NumCast};
Expand Down Expand Up @@ -33,13 +32,13 @@ impl<T> Basis for Vector2<T>
where
T: BaseNum,
{
type Bases = ArrayVec<[Self; 2]>;
type Bases = [Self; 2];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -55,14 +54,14 @@ impl<T> Basis for Vector3<T>
where
T: BaseNum,
{
type Bases = ArrayVec<[Self; 3]>;
type Bases = [Self; 3];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -79,15 +78,15 @@ impl<T> Basis for Vector4<T>
where
T: BaseNum,
{
type Bases = ArrayVec<[Self; 4]>;
type Bases = [Self; 4];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
Self::canonical_basis_component(3).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand Down Expand Up @@ -360,18 +359,18 @@ where
}

impl<T> IntoItems for Vector2<T> {
type Output = ArrayVec<[T; 2]>;
type Output = [T; 2];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.x, self.y])
[self.x, self.y]
}
}

impl<T> IntoItems for Vector3<T> {
type Output = ArrayVec<[T; 3]>;
type Output = [T; 3];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.x, self.y, self.z])
[self.x, self.y, self.z]
}
}

Expand Down Expand Up @@ -709,18 +708,18 @@ where
}

impl<T> IntoItems for Point2<T> {
type Output = ArrayVec<[T; 2]>;
type Output = [T; 2];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.x, self.y])
[self.x, self.y]
}
}

impl<T> IntoItems for Point3<T> {
type Output = ArrayVec<[T; 3]>;
type Output = [T; 3];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.x, self.y, self.z])
[self.x, self.y, self.z]
}
}

Expand Down
25 changes: 12 additions & 13 deletions src/integration/glam.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg(feature = "geometry-glam")]

use arrayvec::ArrayVec;
use decorum::R64;
use glam::{Vec2, Vec3, Vec3A, Vec4};
use typenum::consts::{U2, U3, U4};
Expand Down Expand Up @@ -84,13 +83,13 @@ impl AsPositionMut for Vec3A {
}

impl Basis for Vec2 {
type Bases = ArrayVec<[Self; 2]>;
type Bases = [Self; 2];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -103,14 +102,14 @@ impl Basis for Vec2 {
}

impl Basis for Vec3 {
type Bases = ArrayVec<[Self; 3]>;
type Bases = [Self; 3];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -124,14 +123,14 @@ impl Basis for Vec3 {
}

impl Basis for Vec3A {
type Bases = ArrayVec<[Self; 3]>;
type Bases = [Self; 3];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -145,15 +144,15 @@ impl Basis for Vec3A {
}

impl Basis for Vec4 {
type Bases = ArrayVec<[Self; 4]>;
type Bases = [Self; 4];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
Self::canonical_basis_component(3).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand Down
21 changes: 10 additions & 11 deletions src/integration/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// because they require foreign traits on foreign types.
// TODO: Implement as many traits as possible.

use arrayvec::ArrayVec;
use decorum::R64;
use mint::{Point2, Point3, Vector2, Vector3};
use num::{Num, NumCast, One, Zero};
Expand All @@ -27,13 +26,13 @@ impl<T> Basis for Vector2<T>
where
T: One + Zero,
{
type Bases = ArrayVec<[Self; 2]>;
type Bases = [Self; 2];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -55,14 +54,14 @@ impl<T> Basis for Vector3<T>
where
T: One + Zero,
{
type Bases = ArrayVec<[Self; 3]>;
type Bases = [Self; 3];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand Down Expand Up @@ -210,18 +209,18 @@ where
}

impl<T> IntoItems for Vector2<T> {
type Output = ArrayVec<[T; 2]>;
type Output = [T; 2];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.x, self.y])
[self.x, self.y]
}
}

impl<T> IntoItems for Vector3<T> {
type Output = ArrayVec<[T; 3]>;
type Output = [T; 3];

fn into_items(self) -> Self::Output {
ArrayVec::from([self.x, self.y, self.z])
[self.x, self.y, self.z]
}
}

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

use approx::AbsDiffEq;
use arrayvec::ArrayVec;
use decorum::{Real, R64};
use nalgebra::base::allocator::Allocator;
use nalgebra::base::default_allocator::DefaultAllocator;
Expand Down Expand Up @@ -225,7 +224,7 @@ impl<T> IntoItems for Vector2<T>
where
T: Scalar,
{
type Output = ArrayVec<[T; 2]>;
type Output = [T; 2];

fn into_items(self) -> Self::Output {
let array: [T; 2] = self.into();
Expand All @@ -237,7 +236,7 @@ impl<T> IntoItems for Vector3<T>
where
T: Scalar,
{
type Output = ArrayVec<[T; 3]>;
type Output = [T; 3];

fn into_items(self) -> Self::Output {
let array: [T; 3] = self.into();
Expand Down Expand Up @@ -560,7 +559,7 @@ impl<T> IntoItems for Point2<T>
where
T: Scalar,
{
type Output = ArrayVec<[T; 2]>;
type Output = [T; 2];

fn into_items(self) -> Self::Output {
let array: [T; 2] = self.coords.into();
Expand All @@ -572,7 +571,7 @@ impl<T> IntoItems for Point3<T>
where
T: Scalar,
{
type Output = ArrayVec<[T; 3]>;
type Output = [T; 3];

fn into_items(self) -> Self::Output {
let array: [T; 3] = self.coords.into();
Expand Down
19 changes: 9 additions & 10 deletions src/integration/ultraviolet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg(feature = "geometry-ultraviolet")]

use arrayvec::ArrayVec;
use decorum::R64;
use typenum::consts::{U2, U3, U4};
use ultraviolet::interp::Lerp;
Expand Down Expand Up @@ -63,13 +62,13 @@ impl AsPositionMut for Vec3 {
}

impl Basis for Vec2 {
type Bases = ArrayVec<[Self; 2]>;
type Bases = [Self; 2];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -82,14 +81,14 @@ impl Basis for Vec2 {
}

impl Basis for Vec3 {
type Bases = ArrayVec<[Self; 3]>;
type Bases = [Self; 3];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand All @@ -103,15 +102,15 @@ impl Basis for Vec3 {
}

impl Basis for Vec4 {
type Bases = ArrayVec<[Self; 4]>;
type Bases = [Self; 4];

fn canonical_basis() -> Self::Bases {
ArrayVec::from([
[
Self::canonical_basis_component(0).unwrap(),
Self::canonical_basis_component(1).unwrap(),
Self::canonical_basis_component(2).unwrap(),
Self::canonical_basis_component(3).unwrap(),
])
]
}

fn canonical_basis_component(index: usize) -> Option<Self> {
Expand Down

0 comments on commit 810587b

Please sign in to comment.