Added Debug, Display, and Default to Vectors and Quaternions.
This also adds an example for Vectors and Quaternions.
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
//!
|
||||
//! [1]: https://en.wikipedia.org/wiki/Quaternion
|
||||
//! [2]: https://en.wikipedia.org/wiki/Dual_quaternion
|
||||
use std::fmt::{Error, Formatter, Debug, Display};
|
||||
use std::ops::{Add, Sub, Mul, Div, Neg};
|
||||
|
||||
use ::zero::Zero;
|
||||
@ -275,6 +276,34 @@ impl<T> Quaternion<T> where T: Real
|
||||
// TODO: Add binary operations for editing self.
|
||||
}
|
||||
|
||||
// Implement the Debug trait for the Quaternion.
|
||||
impl<T> Debug for Quaternion<T> where T: Real
|
||||
{
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
|
||||
{
|
||||
write!(formatter, "[{:?}, {:?}]", self.scalar, self.vector)
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the Display trait for the Quaternion.
|
||||
impl<T> Display for Quaternion<T> where T: Real
|
||||
{
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>
|
||||
{
|
||||
write!(formatter, "[{}, {}]", self.scalar, self.vector)
|
||||
}
|
||||
}
|
||||
|
||||
// Implement a default value for Quaternions which
|
||||
// returns the identity quaternion.
|
||||
impl<T> Default for Quaternion<T> where T: Real
|
||||
{
|
||||
fn default() -> Quaternion<T>
|
||||
{
|
||||
Quaternion::identity()
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the Zero and One traits for the Quaternion.
|
||||
impl<T> Zero for Quaternion<T> where T: Real
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user