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