Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement some missing functionalities that would be useful in WebRender. #170

Merged
merged 4 commits into from Dec 9, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Add shorthands to construct point, size, rect objects.

  • Loading branch information
nical committed Dec 9, 2016
commit 48096cd867935141d6a30fe09c94a8ddfbd52167
@@ -760,6 +760,18 @@ impl<T: ApproxEq<T>, U> ApproxEq<T> for TypedPoint4D<T, U> {
}
}

pub fn point2<T: Copy, U>(x: T, y: T) -> TypedPoint2D<T, U> {

This comment has been minimized.

@Ms2ger

Ms2ger Dec 9, 2016

Contributor

Meh.

TypedPoint2D::new(x, y)
}

pub fn point3<T: Copy, U>(x: T, y: T, z: T) -> TypedPoint3D<T, U> {
TypedPoint3D::new(x, y, z)
}

pub fn point4<T: Copy, U>(x: T, y: T, z: T, w: T) -> TypedPoint4D<T, U> {
TypedPoint4D::new(x, y, z, w)
}

#[cfg(test)]
mod point2d {
use super::Point2D;
@@ -427,6 +427,10 @@ impl<T: NumCast + Copy, Unit> TypedRect<T, Unit> {
}
}

/// Shorthand for TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h)).
pub fn rect<T: Copy, U>(x: T, y: T, w: T, h: T) -> TypedRect<T, U> {
TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h))
}

#[cfg(test)]
mod tests {
@@ -44,7 +44,7 @@ impl<T: fmt::Display, U> fmt::Display for TypedSize2D<T, U> {
}

impl<T, U> TypedSize2D<T, U> {
/// Constructor taing scalar values.
/// Constructor taking scalar values.
pub fn new(width: T, height: T) -> TypedSize2D<T, U> {
TypedSize2D {
width: width,
@@ -55,7 +55,7 @@ impl<T, U> TypedSize2D<T, U> {
}

impl<T: Clone, U> TypedSize2D<T, U> {
/// Constructor taing scalar stronlgy typed lengths.
/// Constructor taking scalar stronlgy typed lengths.
pub fn from_lengths(width: Length<T, U>, height: Length<T, U>) -> TypedSize2D<T, U> {
TypedSize2D::new(width.get(), height.get())
}
@@ -227,6 +227,11 @@ impl<T: NumCast + Copy, Unit> TypedSize2D<T, Unit> {
}
}

/// Shorthand for TypedSize2D::new(w, h).
pub fn size2<T, U>(w: T, h: T) -> TypedSize2D<T, U> {
TypedSize2D::new(w, h)
}

#[cfg(test)]
mod size2d {
use super::Size2D;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.