Merge pull request #304 from bjz/repr-c
Mark some types as #[repr(C, packed)]
This commit is contained in:
commit
4200b75c6d
6 changed files with 84 additions and 10 deletions
|
@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||
- Improves the `fmt::Debug` impls for `Vector`, `Matrix`, `Point`, `Decomposed`,
|
||||
`Quaternion` and `Angle` to make them easier to derive, and have clearer
|
||||
formatting.
|
||||
- Marks vectors, points, matrices, and angles as `#[repr(C, packed)]`.
|
||||
|
||||
## [v0.7.0] - 2015-12-23
|
||||
|
||||
|
|
10
src/angle.rs
10
src/angle.rs
|
@ -28,10 +28,16 @@ use rust_num::traits::cast;
|
|||
use approx::ApproxEq;
|
||||
use num::BaseFloat;
|
||||
|
||||
/// An angle, in radians
|
||||
/// An angle, in radians.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, PartialEq, PartialOrd, RustcEncodable, RustcDecodable)]
|
||||
pub struct Rad<S> { pub s: S }
|
||||
/// An angle, in degrees
|
||||
/// An angle, in degrees.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, PartialEq, PartialOrd, RustcEncodable, RustcDecodable)]
|
||||
pub struct Deg<S> { pub s: S }
|
||||
|
||||
|
|
|
@ -35,16 +35,37 @@ use vector::{Vector, EuclideanVector};
|
|||
use vector::{Vector2, Vector3, Vector4};
|
||||
|
||||
/// A 2 x 2, column major matrix
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
pub struct Matrix2<S> { pub x: Vector2<S>, pub y: Vector2<S> }
|
||||
pub struct Matrix2<S> {
|
||||
pub x: Vector2<S>,
|
||||
pub y: Vector2<S>,
|
||||
}
|
||||
|
||||
/// A 3 x 3, column major matrix
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S> }
|
||||
pub struct Matrix3<S> {
|
||||
pub x: Vector3<S>,
|
||||
pub y: Vector3<S>,
|
||||
pub z: Vector3<S>,
|
||||
}
|
||||
|
||||
/// A 4 x 4, column major matrix
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> }
|
||||
pub struct Matrix4<S> {
|
||||
pub x: Vector4<S>,
|
||||
pub y: Vector4<S>,
|
||||
pub z: Vector4<S>,
|
||||
pub w: Vector4<S>,
|
||||
}
|
||||
|
||||
|
||||
impl<S: BaseFloat> Matrix2<S> {
|
||||
|
|
17
src/point.rs
17
src/point.rs
|
@ -30,12 +30,25 @@ use num::{BaseNum, BaseFloat};
|
|||
use vector::*;
|
||||
|
||||
/// A point in 2-dimensional space.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct Point2<S> { pub x: S, pub y: S }
|
||||
pub struct Point2<S> {
|
||||
pub x: S,
|
||||
pub y: S,
|
||||
}
|
||||
|
||||
/// A point in 3-dimensional space.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct Point3<S> { pub x: S, pub y: S, pub z: S }
|
||||
pub struct Point3<S> {
|
||||
pub x: S,
|
||||
pub y: S,
|
||||
pub z: S,
|
||||
}
|
||||
|
||||
|
||||
impl<S: BaseNum> Point2<S> {
|
||||
|
|
|
@ -31,6 +31,9 @@ use vector::{Vector3, Vector, EuclideanVector};
|
|||
|
||||
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
|
||||
/// form.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
pub struct Quaternion<S> {
|
||||
pub s: S,
|
||||
|
|
|
@ -136,12 +136,42 @@ pub trait Vector: Copy + Clone where
|
|||
/// Dot product of two vectors.
|
||||
#[inline] pub fn dot<V: Vector>(a: V, b: V) -> V::Scalar { a.dot(b) }
|
||||
|
||||
/// A 2-dimensional vector.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct Vector2<S> {
|
||||
pub x: S,
|
||||
pub y: S,
|
||||
}
|
||||
|
||||
/// A 3-dimensional vector.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct Vector3<S> {
|
||||
pub x: S,
|
||||
pub y: S,
|
||||
pub z: S,
|
||||
}
|
||||
|
||||
/// A 4-dimensional vector.
|
||||
///
|
||||
/// This type is marked as `#[repr(C, packed)]`.
|
||||
#[repr(C, packed)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct Vector4<S> {
|
||||
pub x: S,
|
||||
pub y: S,
|
||||
pub z: S,
|
||||
pub w: S,
|
||||
}
|
||||
|
||||
// Utility macro for generating associated functions for the vectors
|
||||
macro_rules! impl_vector {
|
||||
($VectorN:ident <$S:ident> { $($field:ident),+ }, $n:expr, $constructor:ident) => {
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct $VectorN<S> { $(pub $field: S),+ }
|
||||
|
||||
impl<$S> $VectorN<$S> {
|
||||
/// Construct a new vector, using the provided values.
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue