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

efficacious #[must_use] methods for nightly, fix warnings #225

Merged
merged 1 commit into from
Sep 13, 2017
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
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![cfg_attr(feature = "unstable", feature(asm, repr_simd, test))]
#![cfg_attr(feature = "unstable", feature(asm, repr_simd, test, fn_must_use))]

//! A collection of strongly typed math tools for computer graphics with an inclination
//! towards 2d graphics and layout.
Expand Down Expand Up @@ -132,4 +132,3 @@ 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>;

12 changes: 6 additions & 6 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<T: Round, U> TypedPoint2D<T, U> {
/// This behavior is preserved for negative values (unlike the basic cast).
/// For example `{ -0.1, -0.8 }.round() == { 0.0, -1.0 }`.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round(&self) -> Self {
point2(self.x.round(), self.y.round())
}
Expand All @@ -251,7 +251,7 @@ impl<T: Ceil, U> TypedPoint2D<T, U> {
/// This behavior is preserved for negative values (unlike the basic cast).
/// For example `{ -0.1, -0.8 }.ceil() == { 0.0, 0.0 }`.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn ceil(&self) -> Self {
point2(self.x.ceil(), self.y.ceil())
}
Expand All @@ -263,7 +263,7 @@ impl<T: Floor, U> TypedPoint2D<T, U> {
/// This behavior is preserved for negative values (unlike the basic cast).
/// For example `{ -0.1, -0.8 }.floor() == { -1.0, -1.0 }`.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn floor(&self) -> Self {
point2(self.x.floor(), self.y.floor())
}
Expand Down Expand Up @@ -568,7 +568,7 @@ impl<T: Round, U> TypedPoint3D<T, U> {
///
/// This behavior is preserved for negative values (unlike the basic cast).
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round(&self) -> Self {
point3(self.x.round(), self.y.round(), self.z.round())
}
Expand All @@ -579,7 +579,7 @@ impl<T: Ceil, U> TypedPoint3D<T, U> {
///
/// This behavior is preserved for negative values (unlike the basic cast).
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn ceil(&self) -> Self {
point3(self.x.ceil(), self.y.ceil(), self.z.ceil())
}
Expand All @@ -590,7 +590,7 @@ impl<T: Floor, U> TypedPoint3D<T, U> {
///
/// This behavior is preserved for negative values (unlike the basic cast).
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn floor(&self) -> Self {
point3(self.x.floor(), self.y.floor(), self.z.floor())
}
Expand Down
14 changes: 7 additions & 7 deletions src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add<T, Output=T> + Sub<T

/// Returns the same rectangle, translated by a vector.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn translate(&self, by: &TypedVector2D<T, U>) -> Self {
Self::new(self.origin + *by, self.size)
}
Expand All @@ -192,7 +192,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add<T, Output=T> + Sub<T
}

#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn inflate(&self, width: T, height: T) -> Self {
TypedRect::new(
TypedPoint2D::new(self.origin.x - width, self.origin.y - height),
Expand All @@ -201,7 +201,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add<T, Output=T> + Sub<T
}

#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn inflate_typed(&self, width: Length<T, U>, height: Length<T, U>) -> Self {
self.inflate(width.get(), height.get())
}
Expand All @@ -222,7 +222,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add<T, Output=T> + Sub<T
}

#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn translate_by_size(&self, size: &TypedSize2D<T, U>) -> Self {
self.translate(&size.to_vector())
}
Expand Down Expand Up @@ -394,7 +394,7 @@ impl<T: Floor + Ceil + Round + Add<T, Output=T> + Sub<T, Output=T>, U> TypedRect
/// avoid pixel rounding errors.
/// Note that this is *not* rounding to nearest integer if the values are negative.
/// They are always rounding as floor(n + 0.5).
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round(&self) -> Self {
let origin = self.origin.round();
let size = self.origin.add_size(&self.size).round() - origin;
Expand All @@ -403,7 +403,7 @@ impl<T: Floor + Ceil + Round + Add<T, Output=T> + Sub<T, Output=T>, U> TypedRect

/// Return a rectangle with edges rounded to integer coordinates, such that
/// the original rectangle contains the resulting rectangle.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round_in(&self) -> Self {
let origin = self.origin.ceil();
let size = self.origin.add_size(&self.size).floor() - origin;
Expand All @@ -412,7 +412,7 @@ impl<T: Floor + Ceil + Round + Add<T, Output=T> + Sub<T, Output=T>, U> TypedRect

/// Return a rectangle with edges rounded to integer coordinates, such that
/// the original rectangle is contained in the resulting rectangle.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round_out(&self) -> Self {
let origin = self.origin.floor();
let size = self.origin.add_size(&self.size).ceil() - origin;
Expand Down
24 changes: 12 additions & 12 deletions src/transform2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ where T: Copy + Clone +

/// Returns the multiplication of the two matrices such that mat's transformation
/// applies after self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_mul<NewDst>(&self, mat: &TypedTransform2D<T, Dst, NewDst>) -> TypedTransform2D<T, Src, NewDst> {
TypedTransform2D::row_major(
self.m11 * mat.m11 + self.m12 * mat.m21,
Expand All @@ -175,7 +175,7 @@ where T: Copy + Clone +

/// Returns the multiplication of the two matrices such that mat's transformation
/// applies before self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_mul<NewSrc>(&self, mat: &TypedTransform2D<T, NewSrc, Src>) -> TypedTransform2D<T, NewSrc, Dst> {
mat.post_mul(self)
}
Expand All @@ -191,13 +191,13 @@ where T: Copy + Clone +
}

/// Applies a translation after self's transformation and returns the resulting transform.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_translate(&self, v: TypedVector2D<T, Dst>) -> Self {
self.post_mul(&TypedTransform2D::create_translation(v.x, v.y))
}

/// Applies a translation before self's transformation and returns the resulting transform.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_translate(&self, v: TypedVector2D<T, Src>) -> Self {
self.pre_mul(&TypedTransform2D::create_translation(v.x, v.y))
}
Expand All @@ -213,13 +213,13 @@ where T: Copy + Clone +
}

/// Applies a scale after self's transformation and returns the resulting transform.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_scale(&self, x: T, y: T) -> Self {
self.post_mul(&TypedTransform2D::create_scale(x, y))
}

/// Applies a scale before self's transformation and returns the resulting transform.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_scale(&self, x: T, y: T) -> Self {
TypedTransform2D::row_major(
self.m11 * x, self.m12,
Expand All @@ -241,28 +241,28 @@ where T: Copy + Clone +
}

/// Applies a rotation after self's transformation and returns the resulting transform.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_rotate(&self, theta: Radians<T>) -> Self {
self.post_mul(&TypedTransform2D::create_rotation(theta))
}

/// Applies a rotation after self's transformation and returns the resulting transform.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_rotate(&self, theta: Radians<T>) -> Self {
self.pre_mul(&TypedTransform2D::create_rotation(theta))
}

/// Returns the given point transformed by this transform.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn transform_point(&self, point: &TypedPoint2D<T, Src>) -> TypedPoint2D<T, Dst> {
TypedPoint2D::new(point.x * self.m11 + point.y * self.m21 + self.m31,
point.x * self.m12 + point.y * self.m22 + self.m32)
}

/// Returns the given vector transformed by this matrix.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn transform_vector(&self, vec: &TypedVector2D<T, Src>) -> TypedVector2D<T, Dst> {
vec2(vec.x * self.m11 + vec.y * self.m21,
vec.x * self.m12 + vec.y * self.m22)
Expand All @@ -271,7 +271,7 @@ where T: Copy + Clone +
/// Returns a rectangle that encompasses the result of transforming the given rectangle by this
/// transform.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn transform_rect(&self, rect: &TypedRect<T, Src>) -> TypedRect<T, Dst> {
TypedRect::from_points(&[
self.transform_point(&rect.origin),
Expand All @@ -287,7 +287,7 @@ where T: Copy + Clone +
}

/// Returns the inverse transform if possible.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn inverse(&self) -> Option<TypedTransform2D<T, Dst, Src>> {
let det = self.determinant();

Expand Down
14 changes: 7 additions & 7 deletions src/transform3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ where T: Copy + Clone +
}

/// Multiplies all of the transform's component by a scalar and returns the result.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn mul_s(&self, x: T) -> Self {
TypedTransform3D::row_major(
self.m11 * x, self.m12 * x, self.m13 * x, self.m14 * x,
Expand Down Expand Up @@ -469,13 +469,13 @@ where T: Copy + Clone +
}

/// Returns a transform with a translation applied before self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_translate(&self, v: TypedVector3D<T, Src>) -> Self {
self.pre_mul(&TypedTransform3D::create_translation(v.x, v.y, v.z))
}

/// Returns a transform with a translation applied after self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_translate(&self, v: TypedVector3D<T, Dst>) -> Self {
self.post_mul(&TypedTransform3D::create_translation(v.x, v.y, v.z))
}
Expand All @@ -492,7 +492,7 @@ where T: Copy + Clone +
}

/// Returns a transform with a scale applied before self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_scale(&self, x: T, y: T, z: T) -> Self {
TypedTransform3D::row_major(
self.m11 * x, self.m12, self.m13, self.m14,
Expand All @@ -503,7 +503,7 @@ where T: Copy + Clone +
}

/// Returns a transform with a scale applied after self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_scale(&self, x: T, y: T, z: T) -> Self {
self.post_mul(&TypedTransform3D::create_scale(x, y, z))
}
Expand Down Expand Up @@ -546,13 +546,13 @@ where T: Copy + Clone +
}

/// Returns a transform with a rotation applied after self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn post_rotate(&self, x: T, y: T, z: T, theta: Radians<T>) -> Self {
self.post_mul(&TypedTransform3D::create_rotation(x, y, z, theta))
}

/// Returns a transform with a rotation applied before self's transformation.
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn pre_rotate(&self, x: T, y: T, z: T, theta: Radians<T>) -> Self {
self.pre_mul(&TypedTransform3D::create_rotation(x, y, z, theta))
}
Expand Down
12 changes: 6 additions & 6 deletions src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<T: Round, U> TypedVector2D<T, U> {
/// This behavior is preserved for negative values (unlike the basic cast).
/// For example `{ -0.1, -0.8 }.round() == { 0.0, -1.0 }`.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round(&self) -> Self {
vec2(self.x.round(), self.y.round())
}
Expand All @@ -284,7 +284,7 @@ impl<T: Ceil, U> TypedVector2D<T, U> {
/// This behavior is preserved for negative values (unlike the basic cast).
/// For example `{ -0.1, -0.8 }.ceil() == { 0.0, 0.0 }`.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn ceil(&self) -> Self {
vec2(self.x.ceil(), self.y.ceil())
}
Expand All @@ -296,7 +296,7 @@ impl<T: Floor, U> TypedVector2D<T, U> {
/// This behavior is preserved for negative values (unlike the basic cast).
/// For example `{ -0.1, -0.8 }.floor() == { -1.0, -1.0 }`.
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn floor(&self) -> Self {
vec2(self.x.floor(), self.y.floor())
}
Expand Down Expand Up @@ -637,7 +637,7 @@ impl<T: Round, U> TypedVector3D<T, U> {
///
/// This behavior is preserved for negative values (unlike the basic cast).
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn round(&self) -> Self {
vec3(self.x.round(), self.y.round(), self.z.round())
}
Expand All @@ -648,7 +648,7 @@ impl<T: Ceil, U> TypedVector3D<T, U> {
///
/// This behavior is preserved for negative values (unlike the basic cast).
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn ceil(&self) -> Self {
vec3(self.x.ceil(), self.y.ceil(), self.z.ceil())
}
Expand All @@ -659,7 +659,7 @@ impl<T: Floor, U> TypedVector3D<T, U> {
///
/// This behavior is preserved for negative values (unlike the basic cast).
#[inline]
#[must_use]
#[cfg_attr(feature = "unstable", must_use)]
pub fn floor(&self) -> Self {
vec3(self.x.floor(), self.y.floor(), self.z.floor())
}
Expand Down