assimp/math/
vector2.rs

1#[cfg(feature = "cgmath")]
2use cgmath::{Point2, Vector2};
3use ffi::AiVector2D;
4
5define_type! {
6    /// Vector2D docs
7    #[derive(Clone, Copy, Debug, PartialEq)]
8    struct Vector2D(AiVector2D)
9}
10
11impl Vector2D {
12    pub fn new(x: f32, y: f32) -> Vector2D {
13        Vector2D(AiVector2D { x: x, y: y })
14    }
15}
16
17impl From<[f32; 2]> for Vector2D {
18    fn from(v: [f32; 2]) -> Vector2D {
19        Vector2D::new(v[0], v[1])
20    }
21}
22
23impl From<Vector2D> for [f32; 2] {
24    fn from(v: Vector2D) -> [f32; 2] {
25        [v.x, v.y]
26    }
27}
28
29#[cfg(feature = "cgmath")]
30impl From<Point2<f32>> for Vector2D {
31    fn from(p: Point2<f32>) -> Vector2D {
32        Vector2D::new(p[0], p[1])
33    }
34}
35
36#[cfg(feature = "cgmath")]
37impl From<Vector2D> for Point2<f32> {
38    fn from(v: Vector2D) -> Point2<f32> {
39        Point2::new(v.x, v.y)
40    }
41}
42
43#[cfg(feature = "cgmath")]
44impl From<Vector2<f32>> for Vector2D {
45    fn from(v: Vector2<f32>) -> Vector2D {
46        Vector2D::new(v[0], v[1])
47    }
48}
49
50#[cfg(feature = "cgmath")]
51impl From<Vector2D> for Vector2<f32> {
52    fn from(v: Vector2D) -> Vector2<f32> {
53        Vector2::new(v.x, v.y)
54    }
55}