diff --git a/src/lib.rs b/src/lib.rs index a1f7b45..b840cb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,7 +80,7 @@ pub use vector::{dot, Vector1, Vector2, Vector3, Vector4, vec1, vec2, vec3, vec4 pub use angle::{Deg, Rad}; pub use euler::Euler; -pub use point::{Point1, Point2, Point3}; +pub use point::{Point1, Point2, Point3, point1, point2, point3}; pub use rotation::*; pub use transform::*; diff --git a/src/point.rs b/src/point.rs index a50c92f..7789b66 100644 --- a/src/point.rs +++ b/src/point.rs @@ -78,7 +78,7 @@ impl Point3 { } macro_rules! impl_point { - ($PointN:ident { $($field:ident),+ }, $VectorN:ident, $n:expr) => { + ($PointN:ident { $($field:ident),+ }, $VectorN:ident, $n:expr, $constructor:ident) => { impl $PointN { /// Construct a new point, using the provided values. #[inline] @@ -96,6 +96,12 @@ macro_rules! impl_point { } } + /// The short constructor. + #[inline] + pub const fn $constructor($($field: S),+) -> $PointN { + $PointN::new($($field),+) + } + impl Array for $PointN { type Element = S; @@ -323,9 +329,9 @@ macro_rules! impl_scalar_ops { }; } -impl_point!(Point1 { x }, Vector1, 1); -impl_point!(Point2 { x, y }, Vector2, 2); -impl_point!(Point3 { x, y, z }, Vector3, 3); +impl_point!(Point1 { x }, Vector1, 1, point1); +impl_point!(Point2 { x, y }, Vector2, 2, point2); +impl_point!(Point3 { x, y, z }, Vector3, 3, point3); impl Point1 { impl_swizzle_functions!(Point1, Point2, Point3, S, x); diff --git a/src/vector.rs b/src/vector.rs index 16b31d1..ad97329 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -365,7 +365,7 @@ macro_rules! impl_vector_default { /// The short constructor. #[inline] - pub fn $constructor($($field: S),+) -> $VectorN { + pub const fn $constructor($($field: S),+) -> $VectorN { $VectorN::new($($field),+) } diff --git a/tests/point.rs b/tests/point.rs index 83fd168..b397bef 100644 --- a/tests/point.rs +++ b/tests/point.rs @@ -17,7 +17,14 @@ extern crate approx; extern crate cgmath; -use cgmath::{Point1, Point2, Point3}; +use cgmath::*; + +#[test] +fn test_constructor() { + assert_eq!(point1(1f32), Point1::new(1f32)); + assert_eq!(point2(1f32, 2f32), Point2::new(1f32, 2f32)); + assert_eq!(point3(1f64, 2f64, 3f64), Point3::new(1f64, 2f64, 3f64)); +} macro_rules! impl_test_mul { ($PointN:ident { $($field:ident),+ }, $s:expr, $v:expr) => ( diff --git a/tests/vector.rs b/tests/vector.rs index 325838a..458f6b3 100644 --- a/tests/vector.rs +++ b/tests/vector.rs @@ -23,6 +23,7 @@ use std::iter; #[test] fn test_constructor() { + assert_eq!(vec1(1f32), Vector1::new(1f32)); assert_eq!(vec2(1f32, 2f32), Vector2::new(1f32, 2f32)); assert_eq!(vec3(1f64, 2f64, 3f64), Vector3::new(1f64, 2f64, 3f64)); assert_eq!(