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
#![doc(html_root_url = "https://docs.rs/quaternion-matrix/0.0.1")]
//! quaternion matrix for Rust
//!

pub mod q;
pub mod m;
pub mod v;

/// test with [-- --nocapture] or [-- --show-output]
#[cfg(test)]
mod tests {
  // use super::*;
  use crate::v::{TVector, v3::Vector3, v4::Vector4};
  use crate::q::{TQuaternion, Quaternion};
  use crate::m::{TMatrix, m3::Matrix3, m4::Matrix4};

  /// test Vector3
  #[test]
  fn test_vector3() {
    assert_eq!(Vector3::<f32>::new(
      &[1.0, 2.0, 3.0]),
      [1.0, 2.0, 3.0]);
    assert_eq!(Vector3::<f64>::new(
      &[1.0, 2.0, 3.0]),
      [1.0, 2.0, 3.0]);
  }

  /// test Vector4
  #[test]
  fn test_vector4() {
    assert_eq!(Vector4::<f32>::new(
      &[1.0, 2.0, 3.0, 4.0]),
      [1.0, 2.0, 3.0, 4.0]);
    assert_eq!(Vector4::<f64>::new(
      &[1.0, 2.0, 3.0, 4.0]),
      [1.0, 2.0, 3.0, 4.0]);
  }

  /// test Quaternion
  #[test]
  fn test_quaternion() {
    assert_eq!(Quaternion::<f32>::new(
      &[1.0, 0.0, 0.0, 0.0]),
      [1.0, 0.0, 0.0, 0.0]);
    assert_eq!(Quaternion::<f64>::new(
      &[1.0, 0.0, 0.0, 0.0]),
      [1.0, 0.0, 0.0, 0.0]);
    assert_eq!(Quaternion::<f32>::identity(),
      [1.0, 0.0, 0.0, 0.0]);
    assert_eq!(Quaternion::<f64>::identity(),
      [1.0, 0.0, 0.0, 0.0]);
  }

  /// test Matrix3
  #[test]
  fn test_matrix3() {
    assert_eq!(Matrix3::<f32>::new(&[
      &[1.0, 0.0, 0.0],
      &[0.0, 1.0, 0.0],
      &[0.0, 0.0, 1.0]]), [
      [1.0, 0.0, 0.0],
      [0.0, 1.0, 0.0],
      [0.0, 0.0, 1.0]]);
    assert_eq!(Matrix3::<f64>::new(&[
      &[1.0, 0.0, 0.0],
      &[0.0, 1.0, 0.0],
      &[0.0, 0.0, 1.0]]), [
      [1.0, 0.0, 0.0],
      [0.0, 1.0, 0.0],
      [0.0, 0.0, 1.0]]);
  }

  /// test Matrix4
  #[test]
  fn test_matrix4() {
    assert_eq!(Matrix4::<f32>::new(&[
      &[1.0, 0.0, 0.0, 0.0],
      &[0.0, 1.0, 0.0, 0.0],
      &[0.0, 0.0, 1.0, 0.0],
      &[0.0, 0.0, 0.0, 1.0]]), [
      [1.0, 0.0, 0.0, 0.0],
      [0.0, 1.0, 0.0, 0.0],
      [0.0, 0.0, 1.0, 0.0],
      [0.0, 0.0, 0.0, 1.0]]);
    assert_eq!(Matrix4::<f64>::new(&[
      &[1.0, 0.0, 0.0, 0.0],
      &[0.0, 1.0, 0.0, 0.0],
      &[0.0, 0.0, 1.0, 0.0],
      &[0.0, 0.0, 0.0, 1.0]]), [
      [1.0, 0.0, 0.0, 0.0],
      [0.0, 1.0, 0.0, 0.0],
      [0.0, 0.0, 1.0, 0.0],
      [0.0, 0.0, 0.0, 1.0]]);
  }
}