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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
use nalgebra as na;

use crate::{Extent2Df, Offset2Df, Posef, Quaternionf, Vector2f, Vector3f, Vector4f};

impl Into<na::Vector2<f32>> for Vector2f {
    fn into(self) -> na::Vector2<f32> {
        na::Vector2::new(self.x, self.y)
    }
}

impl From<na::Vector2<f32>> for Vector2f {
    fn from(v: na::Vector2<f32>) -> Self {
        Self { x: v.x, y: v.y }
    }
}

impl Into<na::Vector3<f32>> for Vector3f {
    fn into(self) -> na::Vector3<f32> {
        na::Vector3::new(self.x, self.y, self.z)
    }
}

impl From<na::Vector3<f32>> for Vector3f {
    fn from(v: na::Vector3<f32>) -> Self {
        Self {
            x: v.x,
            y: v.y,
            z: v.z,
        }
    }
}

impl Into<na::Vector4<f32>> for Vector4f {
    fn into(self) -> na::Vector4<f32> {
        na::Vector4::new(self.x, self.y, self.z, self.w)
    }
}

impl From<na::Vector4<f32>> for Vector4f {
    fn from(v: na::Vector4<f32>) -> Self {
        Self {
            x: v.x,
            y: v.y,
            z: v.z,
            w: v.w,
        }
    }
}

impl Into<na::UnitQuaternion<f32>> for Quaternionf {
    fn into(self) -> na::UnitQuaternion<f32> {
        na::Unit::new_unchecked(na::Quaternion::new(self.w, self.x, self.y, self.z))
    }
}

impl From<na::UnitQuaternion<f32>> for Quaternionf {
    fn from(q: na::UnitQuaternion<f32>) -> Self {
        Self {
            x: q.i,
            y: q.j,
            z: q.k,
            w: q.w,
        }
    }
}

impl Into<na::Vector2<f32>> for Extent2Df {
    fn into(self) -> na::Vector2<f32> {
        na::Vector2::new(self.width, self.height)
    }
}

impl From<na::Vector2<f32>> for Extent2Df {
    fn from(v: na::Vector2<f32>) -> Self {
        Self { width: v.x, height: v.y }
    }
}

impl Into<na::Vector2<f32>> for Offset2Df {
    fn into(self) -> na::Vector2<f32> {
        na::Vector2::new(self.x, self.y)
    }
}

impl From<na::Vector2<f32>> for Offset2Df {
    fn from(v: na::Vector2<f32>) -> Self {
        Self { x: v.x, y: v.y }
    }
}

impl Into<na::Isometry3<f32>> for Posef {
    fn into(self) -> na::Isometry3<f32> {
        let position: na::Vector3<f32> = self.position.into();
        na::Isometry3::from_parts(na::Translation3::from(position), self.orientation.into())
    }
}

impl From<na::Isometry3<f32>> for Posef {
    fn from(x: na::Isometry3<f32>) -> Self {
        Self {
            orientation: x.rotation.into(),
            position: x.translation.vector.into(),
        }
    }
}