Move Angle::new to be implemented directly on angle types

This is more in keeping with most Rust APIs, and the other types in this library
This commit is contained in:
Brendan Zabarauskas 2016-04-03 13:36:12 +10:00
parent 40232ec063
commit aa6fd71ab8

View file

@ -34,6 +34,7 @@ use num::BaseFloat;
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Copy, Clone, PartialEq, PartialOrd, RustcEncodable, RustcDecodable)] #[derive(Copy, Clone, PartialEq, PartialOrd, RustcEncodable, RustcDecodable)]
pub struct Rad<S> { pub s: S } pub struct Rad<S> { pub s: S }
/// An angle, in degrees. /// An angle, in degrees.
/// ///
/// This type is marked as `#[repr(C, packed)]`. /// This type is marked as `#[repr(C, packed)]`.
@ -77,9 +78,6 @@ pub trait Angle where
{ {
type Unitless: BaseFloat; type Unitless: BaseFloat;
/// Create an angle from a unitless value.
fn new(value: Self::Unitless) -> Self;
/// Return the angle, normalized to the range `[0, full_turn)`. /// Return the angle, normalized to the range `[0, full_turn)`.
#[inline] #[inline]
fn normalize(self) -> Self { fn normalize(self) -> Self {
@ -124,13 +122,15 @@ pub trait Angle where
macro_rules! impl_angle { macro_rules! impl_angle {
($Angle:ident, $fmt:expr, $full_turn:expr, $hi:expr) => { ($Angle:ident, $fmt:expr, $full_turn:expr, $hi:expr) => {
impl<S: BaseFloat> Angle for $Angle<S> { impl<S: BaseFloat> $Angle<S> {
type Unitless = S;
#[inline] #[inline]
fn new(value: S) -> $Angle<S> { pub fn new(value: S) -> $Angle<S> {
$Angle { s: value } $Angle { s: value }
} }
}
impl<S: BaseFloat> Angle for $Angle<S> {
type Unitless = S;
#[inline] #[inline]
fn zero() -> $Angle<S> { fn zero() -> $Angle<S> {