Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// except according to those terms.
//! A one-dimensional length, tagged with its units.

use scale_factor::ScaleFactor;
use scale::TypedScale;
use num::Zero;

use heapsize::HeapSizeOf;
Expand All @@ -30,8 +30,8 @@ use std::fmt;
/// expression that requires a different unit. It may be a type without values, such as an empty
/// enum.
///
/// You can multiply a `Length` by a `scale_factor::ScaleFactor` to convert it from one unit to
/// another. See the `ScaleFactor` docs for an example.
/// You can multiply a `Length` by a `scale::TypedScale` to convert it from one unit to
/// another. See the `TypedScale` docs for an example.
// Uncomment the derive, and remove the macro call, once heapsize gets
// PhantomData<T> support.
#[repr(C)]
Expand Down Expand Up @@ -131,10 +131,10 @@ impl<U, T: Clone + Saturating> Saturating for Length<T, U> {

// length / length
impl<Src, Dst, T: Clone + Div<T, Output=T>> Div<Length<T, Src>> for Length<T, Dst> {
type Output = ScaleFactor<T, Src, Dst>;
type Output = TypedScale<T, Src, Dst>;
#[inline]
fn div(self, other: Length<T, Src>) -> ScaleFactor<T, Src, Dst> {
ScaleFactor::new(self.get() / other.get())
fn div(self, other: Length<T, Src>) -> TypedScale<T, Src, Dst> {
TypedScale::new(self.get() / other.get())
}
}

Expand Down Expand Up @@ -173,19 +173,19 @@ impl<T: Copy + Div<T, Output=T>, U> DivAssign<T> for Length<T, U> {
}

// length * scaleFactor
impl<Src, Dst, T: Clone + Mul<T, Output=T>> Mul<ScaleFactor<T, Src, Dst>> for Length<T, Src> {
impl<Src, Dst, T: Clone + Mul<T, Output=T>> Mul<TypedScale<T, Src, Dst>> for Length<T, Src> {
type Output = Length<T, Dst>;
#[inline]
fn mul(self, scale: ScaleFactor<T, Src, Dst>) -> Length<T, Dst> {
fn mul(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Dst> {
Length::new(self.get() * scale.get())
}
}

// length / scaleFactor
impl<Src, Dst, T: Clone + Div<T, Output=T>> Div<ScaleFactor<T, Src, Dst>> for Length<T, Dst> {
impl<Src, Dst, T: Clone + Div<T, Output=T>> Div<TypedScale<T, Src, Dst>> for Length<T, Dst> {
type Output = Length<T, Src>;
#[inline]
fn div(self, scale: ScaleFactor<T, Src, Dst>) -> Length<T, Src> {
fn div(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Src> {
Length::new(self.get() / scale.get())
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ mod tests {

use heapsize::HeapSizeOf;
use num_traits::Saturating;
use scale_factor::ScaleFactor;
use scale::TypedScale;
use std::f32::INFINITY;

extern crate serde_test;
Expand Down Expand Up @@ -394,21 +394,21 @@ mod tests {

#[test]
fn test_division_by_length() {
// Division results in a ScaleFactor from denominator units
// Division results in a TypedScale from denominator units
// to numerator units.
let length: Length<f32, Cm> = Length::new(5.0);
let duration: Length<f32, Second> = Length::new(10.0);

let result = length / duration;

let expected: ScaleFactor<f32, Second, Cm> = ScaleFactor::new(0.5);
let expected: TypedScale<f32, Second, Cm> = TypedScale::new(0.5);
assert_eq!(result, expected);
}

#[test]
fn test_multiplication() {
let length_mm: Length<f32, Mm> = Length::new(10.0);
let cm_per_mm: ScaleFactor<f32, Mm, Cm> = ScaleFactor::new(0.1);
let cm_per_mm: TypedScale<f32, Mm, Cm> = TypedScale::new(0.1);

let result = length_mm * cm_per_mm;

Expand Down Expand Up @@ -439,7 +439,7 @@ mod tests {
#[test]
fn test_division_by_scalefactor() {
let length: Length<f32, Cm> = Length::new(5.0);
let cm_per_second: ScaleFactor<f32, Second, Cm> = ScaleFactor::new(10.0);
let cm_per_second: TypedScale<f32, Second, Cm> = TypedScale::new(10.0);

let result = length / cm_per_second;

Expand Down Expand Up @@ -529,7 +529,7 @@ mod tests {

let result = length / length_zero;

let expected: ScaleFactor<f32, Cm, Cm> = ScaleFactor::new(INFINITY);
let expected: TypedScale<f32, Cm, Cm> = TypedScale::new(INFINITY);
assert_eq!(result, expected);
}
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern crate test;
extern crate num_traits;

pub use length::Length;
pub use scale_factor::ScaleFactor;
pub use scale::TypedScale;
pub use transform2d::{Transform2D, TypedTransform2D};
pub use transform3d::{Transform3D, TypedTransform3D};
pub use point::{
Expand Down Expand Up @@ -97,7 +97,7 @@ mod transform3d;
mod point;
mod rect;
mod rotation;
mod scale_factor;
mod scale;
mod side_offsets;
mod size;
mod trig;
Expand Down Expand Up @@ -134,3 +134,7 @@ pub type Matrix4D<T> = Transform3D<T>;
/// Temporary alias to facilitate the transition to the new naming scheme
#[deprecated]
pub type TypedMatrix4D<T, Src, Dst> = TypedTransform3D<T, Src, Dst>;

/// Temporary alias to facilitate the transition to the new naming scheme
#[deprecated]
pub type ScaleFactor<T, Src, Dst> = TypedScale<T, Src, Dst>;
14 changes: 7 additions & 7 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use super::UnknownUnit;
use approxeq::ApproxEq;
use length::Length;
use scale_factor::ScaleFactor;
use scale::TypedScale;
use size::TypedSize2D;
use num::*;
use num_traits::{Float, NumCast};
Expand Down Expand Up @@ -217,18 +217,18 @@ impl<T: Copy + Div<T, Output=T>, U> DivAssign<T> for TypedPoint2D<T, U> {
}
}

impl<T: Copy + Mul<T, Output=T>, U1, U2> Mul<ScaleFactor<T, U1, U2>> for TypedPoint2D<T, U1> {
impl<T: Copy + Mul<T, Output=T>, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint2D<T, U1> {
type Output = TypedPoint2D<T, U2>;
#[inline]
fn mul(self, scale: ScaleFactor<T, U1, U2>) -> TypedPoint2D<T, U2> {
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U2> {
point2(self.x * scale.get(), self.y * scale.get())
}
}

impl<T: Copy + Div<T, Output=T>, U1, U2> Div<ScaleFactor<T, U1, U2>> for TypedPoint2D<T, U2> {
impl<T: Copy + Div<T, Output=T>, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint2D<T, U2> {
type Output = TypedPoint2D<T, U1>;
#[inline]
fn div(self, scale: ScaleFactor<T, U1, U2>) -> TypedPoint2D<T, U1> {
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U1> {
point2(self.x / scale.get(), self.y / scale.get())
}
}
Expand Down Expand Up @@ -742,7 +742,7 @@ mod point2d {
#[cfg(test)]
mod typedpoint2d {
use super::{TypedPoint2D, Point2D, point2};
use scale_factor::ScaleFactor;
use scale::TypedScale;
use vector::vec2;

pub enum Mm {}
Expand Down Expand Up @@ -772,7 +772,7 @@ mod typedpoint2d {
#[test]
pub fn test_scalar_mul() {
let p1 = Point2DMm::new(1.0, 2.0);
let cm_per_mm: ScaleFactor<f32, Mm, Cm> = ScaleFactor::new(0.1);
let cm_per_mm: TypedScale<f32, Mm, Cm> = TypedScale::new(0.1);

let result = p1 * cm_per_mm;

Expand Down
15 changes: 8 additions & 7 deletions src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use super::UnknownUnit;
use length::Length;
use scale_factor::ScaleFactor;
use scale::TypedScale;
use num::*;
use point::TypedPoint2D;
use vector::TypedVector2D;
Expand Down Expand Up @@ -293,8 +293,9 @@ where T: Copy + Clone + PartialOrd + Add<T, Output=T> + Sub<T, Output=T> + Zero

impl<T, U> TypedRect<T, U> {
#[inline]
pub fn scale<Scale: Copy>(&self, x: Scale, y: Scale) -> Self
where T: Copy + Clone + Mul<Scale, Output=T> {
pub fn scale<S: Copy>(&self, x: S, y: S) -> Self
where T: Copy + Clone + Mul<S, Output=T>
{
TypedRect::new(
TypedPoint2D::new(self.origin.x * x, self.origin.y * y),
TypedSize2D::new(self.size.width * x, self.size.height * y)
Expand Down Expand Up @@ -342,18 +343,18 @@ impl<T: Copy + Div<T, Output=T>, U> Div<T> for TypedRect<T, U> {
}
}

impl<T: Copy + Mul<T, Output=T>, U1, U2> Mul<ScaleFactor<T, U1, U2>> for TypedRect<T, U1> {
impl<T: Copy + Mul<T, Output=T>, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedRect<T, U1> {
type Output = TypedRect<T, U2>;
#[inline]
fn mul(self, scale: ScaleFactor<T, U1, U2>) -> TypedRect<T, U2> {
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedRect<T, U2> {
TypedRect::new(self.origin * scale, self.size * scale)
}
}

impl<T: Copy + Div<T, Output=T>, U1, U2> Div<ScaleFactor<T, U1, U2>> for TypedRect<T, U2> {
impl<T: Copy + Div<T, Output=T>, U1, U2> Div<TypedScale<T, U1, U2>> for TypedRect<T, U2> {
type Output = TypedRect<T, U1>;
#[inline]
fn div(self, scale: ScaleFactor<T, U1, U2>) -> TypedRect<T, U1> {
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedRect<T, U1> {
TypedRect::new(self.origin / scale, self.size / scale)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use trig::Trig;
use {TypedPoint2D, TypedPoint3D, TypedVector2D, TypedVector3D, Vector3D, point2, point3, vec3};
use {TypedTransform3D, TypedTransform2D, UnknownUnit, Radians};


define_matrix! {
/// A transform that can represent rotations in 2d, represented as an angle in radians.
pub struct TypedRotation2D<T, Src, Dst> {
Expand Down
Loading