Skip to content

Commit a50aa2e

Browse files
committed
Impl Default for SphericalVec and PolarVec
This sets the r component to 1, which is a more reasonable default. Make the existing Default for Vector only apply to those with Real basis to avoid overlapping impls.
1 parent 77d371a commit a50aa2e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

core/src/math/angle.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,17 @@ impl ZDiv for Angle {}
477477
// Foreign trait impls
478478
//
479479

480+
impl<B> Default for SphericalVec<B> {
481+
fn default() -> Self {
482+
Self::new([1.0, 0.0, 0.0])
483+
}
484+
}
485+
impl<B> Default for PolarVec<B> {
486+
fn default() -> Self {
487+
Self::new([1.0, 0.0])
488+
}
489+
}
490+
480491
impl Display for Angle {
481492
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
482493
let (val, unit) = if f.alternate() {

core/src/math/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ impl<Sc: ApproxEq, Sp, const N: usize> ApproxEq<Self, Sc>
505505
// Foreign trait impls
506506
//
507507

508-
// Manual impls of Copy, Clone, Eq, and PartialEq to avoid
509-
// superfluous where S: Trait bound
508+
// Manual impls of Copy, Clone, Default, Eq, and PartialEq
509+
// to avoid superfluous where S: Trait bound
510510

511511
impl<R: Copy, S> Copy for Vector<R, S> {}
512512

@@ -516,7 +516,7 @@ impl<R: Clone, S> Clone for Vector<R, S> {
516516
}
517517
}
518518

519-
impl<R: Default, S> Default for Vector<R, S> {
519+
impl<R: Default, B, const DIM: usize> Default for Vector<R, Real<DIM, B>> {
520520
fn default() -> Self {
521521
Self(R::default(), Pd)
522522
}

0 commit comments

Comments
 (0)