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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#![doc(html_root_url = "https://docs.rs/drawstuff/0.1.9")]
//! ODE drawstuff bindings for Rust
//!
//! # Requirements
//!
//! - [ https://github.com/nomissbowling/asciiz ]( https://github.com/nomissbowling/asciiz )
//! - [ drawstuff ]( https://ode.org/ )
//!
//! to build dll
//!
//! - premake4 --with-demos --only-double --with-libccd --cc=gcc --platform--x64 --os=windows codeblocks
//! - premake4 --with-demos --only-double --with-libccd --platform--x64 --os=windows vs2010
//!
//! in the running directory
//!
//! - drawstuff.dll
//! - libgcc_s_seh-1.dll
//! - libwinpthread-1.dll
//!
//! # Examples
//!
//! see also
//!
//! - [ https://github.com/nomissbowling/drawstuff ]( https://github.com/nomissbowling/drawstuff )
//!

pub mod drawstuff;

pub mod minimum;

#[cfg(test)]
mod tests {
  use super::drawstuff::{dReal, _dDot};
  use super::minimum::simple_test;

  /// with [-- --nocapture] or with [-- --show-output]
  #[test]
  fn test_drawstuff() {
    assert_eq!(simple_test(), ());
  }

  #[test]
  fn test_bridge() {
    let a: [dReal; 4] = [0.1, 0.2, 0.3, 0.4];
    let b: [dReal; 4] = [0.1, 0.2, 0.3, 0.4];
    let d = unsafe { _dDot(
      &a as *const [dReal; 4] as *const dReal,
      &b as *const [dReal; 4] as *const dReal,
      4) };
    assert_eq!(d - 0.3 < 0.000001, true);
  }

/*
  #[test]
  fn check_quaternion_matrix() {
    let q = dQuaternion::from_axis_and_angle([1.0, 0.0, 0.0], PIh);
    let p = dQuaternion::from_axis_and_angle([0.0, 1.0, 0.0], PIh);
    let o = dQuaternion::from_axis_and_angle([0.0, 0.0, 1.0], PIh);
    println!("q, p, o");
    println!("{}", q.as_vec());
    println!("{}", p.as_vec());
    println!("{}", o.as_vec());
    assert!(q.prec_eq(1e-15, [PIq.cos(), PIq.sin(), 0.0, 0.0]));
    assert!(p.prec_eq(1e-15, [PIq.cos(), 0.0, PIq.sin(), 0.0]));
    assert!(o.prec_eq(1e-15, [PIq.cos(), 0.0, 0.0, PIq.sin()]));

    let oq = dQuaternion::multiply0(o, q);
    let po = dQuaternion::multiply0(p, o);
    let pq = dQuaternion::multiply0(p, q);
    println!("oq, po, pq");
    println!("{}", oq.as_vec());
    println!("{}", po.as_vec());
    println!("{}", pq.as_vec());
    assert!(oq.prec_eq(1e-15, [0.5, 0.5, 0.5, 0.5])); // j
    assert!(po.prec_eq(1e-15, [0.5, 0.5, 0.5, 0.5])); // i
    assert!(pq.prec_eq(1e-15, [0.5, 0.5, 0.5, -0.5])); // k
    assert!(oq.prec_eq(1e-15, po));

    let nq = dMatrix4::from_P(q);
    let np = dMatrix4::from_P(p);
    let no = dMatrix4::from_P(o);
    println!("nq, np, no");
    println!("{}", nq.as_mat());
    println!("{}", np.as_mat());
    println!("{}", no.as_mat());
    assert!(dQuaternion::multiply0_441(nq, o).prec_eq(1e-15, oq));
    assert!(dQuaternion::multiply0_441(no, p).prec_eq(1e-15, po));
    assert!(dQuaternion::multiply0_441(nq, p).prec_eq(1e-15, pq));

    let nqno = dMatrix4::multiply0_444(nq, no);
    let nonp = dMatrix4::multiply0_444(no, np);
    let nqnp = dMatrix4::multiply0_444(nq, np);
    println!("nqno, nonp, nqnp");
    println!("{}", nqno.as_mat());
    println!("{}", nonp.as_mat());
    println!("{}", nqnp.as_mat());
    assert!(nqno.is_quaternion());
    assert!(nqno.to_Q().prec_eq(1e-15, oq));
    assert!(nonp.is_quaternion());
    assert!(nonp.to_Q().prec_eq(1e-15, po));
    assert!(nqnp.is_quaternion());
    assert!(nqnp.to_Q().prec_eq(1e-15, pq));
    assert!(nqno.prec_eq(1e-15, nonp));

    let mq = dMatrix4::from_Q(q);
    let mp = dMatrix4::from_Q(p);
    let mo = dMatrix4::from_Q(o);
    println!("mq, mp, mo");
    println!("{}", mq.as_mat());
    println!("{}", mp.as_mat());
    println!("{}", mo.as_mat());
    assert!(dQuaternion::multiply0_441(mo, q).prec_eq(1e-15, oq));
    assert!(dQuaternion::multiply0_441(mp, o).prec_eq(1e-15, po));
    assert!(dQuaternion::multiply0_441(mp, q).prec_eq(1e-15, pq));

    let momq = dMatrix4::multiply0_444(mo, mq);
    let mpmo = dMatrix4::multiply0_444(mp, mo);
    let mpmq = dMatrix4::multiply0_444(mp, mq);
    println!("momq, mpmo, mpmq");
    println!("{}", momq.as_mat());
    println!("{}", mpmo.as_mat());
    println!("{}", mpmq.as_mat());
    assert!(momq.is_quaternion());
    assert!(momq.to_Q().prec_eq(1e-15, oq));
    assert!(mpmo.is_quaternion());
    assert!(mpmo.to_Q().prec_eq(1e-15, po));
    assert!(mpmq.is_quaternion());
    assert!(mpmq.to_Q().prec_eq(1e-15, pq));
    assert!(momq.prec_eq(1e-15, mpmo));
  }
*/
}

/*
q, p, o
[        0.7071068,        0.7071068,        0.0000000,        0.0000000]
[        0.7071068,        0.0000000,        0.7071068,        0.0000000]
[        0.7071068,        0.0000000,        0.0000000,        0.7071068]
oq, po, pq
[        0.5000000,        0.5000000,        0.5000000,        0.5000000]
[        0.5000000,        0.5000000,        0.5000000,        0.5000000]
[        0.5000000,        0.5000000,        0.5000000,       -0.5000000]
nq, np, no
[
 [        0.7071068,       -0.7071068,       -0.0000000,       -0.0000000]
 [        0.7071068,        0.7071068,        0.0000000,       -0.0000000]
 [        0.0000000,       -0.0000000,        0.7071068,        0.7071068]
 [        0.0000000,        0.0000000,       -0.7071068,        0.7071068]]
[
 [        0.7071068,       -0.0000000,       -0.7071068,       -0.0000000]
 [        0.0000000,        0.7071068,        0.0000000,       -0.7071068]
 [        0.7071068,       -0.0000000,        0.7071068,        0.0000000]
 [        0.0000000,        0.7071068,       -0.0000000,        0.7071068]]
[
 [        0.7071068,       -0.0000000,       -0.0000000,       -0.7071068]
 [        0.0000000,        0.7071068,        0.7071068,       -0.0000000]
 [        0.0000000,       -0.7071068,        0.7071068,        0.0000000]
 [        0.7071068,        0.0000000,       -0.0000000,        0.7071068]]
nqno, nonp, nqnp
[
 [        0.5000000,       -0.5000000,       -0.5000000,       -0.5000000]
 [        0.5000000,        0.5000000,        0.5000000,       -0.5000000]
 [        0.5000000,       -0.5000000,        0.5000000,        0.5000000]
 [        0.5000000,        0.5000000,       -0.5000000,        0.5000000]]
[
 [        0.5000000,       -0.5000000,       -0.5000000,       -0.5000000]
 [        0.5000000,        0.5000000,        0.5000000,       -0.5000000]
 [        0.5000000,       -0.5000000,        0.5000000,        0.5000000]
 [        0.5000000,        0.5000000,       -0.5000000,        0.5000000]]
[
 [        0.5000000,       -0.5000000,       -0.5000000,        0.5000000]
 [        0.5000000,        0.5000000,       -0.5000000,       -0.5000000]
 [        0.5000000,        0.5000000,        0.5000000,        0.5000000]
 [       -0.5000000,        0.5000000,       -0.5000000,        0.5000000]]
mq, mp, mo
[
 [        0.7071068,       -0.7071068,       -0.0000000,       -0.0000000]
 [        0.7071068,        0.7071068,       -0.0000000,        0.0000000]
 [        0.0000000,        0.0000000,        0.7071068,       -0.7071068]
 [        0.0000000,       -0.0000000,        0.7071068,        0.7071068]]
[
 [        0.7071068,       -0.0000000,       -0.7071068,       -0.0000000]
 [        0.0000000,        0.7071068,       -0.0000000,        0.7071068]
 [        0.7071068,        0.0000000,        0.7071068,       -0.0000000]
 [        0.0000000,       -0.7071068,        0.0000000,        0.7071068]]
[
 [        0.7071068,       -0.0000000,       -0.0000000,       -0.7071068]
 [        0.0000000,        0.7071068,       -0.7071068,        0.0000000]
 [        0.0000000,        0.7071068,        0.7071068,       -0.0000000]
 [        0.7071068,       -0.0000000,        0.0000000,        0.7071068]]
momq, mpmo, mpmq
[
 [        0.5000000,       -0.5000000,       -0.5000000,       -0.5000000]
 [        0.5000000,        0.5000000,       -0.5000000,        0.5000000]
 [        0.5000000,        0.5000000,        0.5000000,       -0.5000000]
 [        0.5000000,       -0.5000000,        0.5000000,        0.5000000]]
[
 [        0.5000000,       -0.5000000,       -0.5000000,       -0.5000000]
 [        0.5000000,        0.5000000,       -0.5000000,        0.5000000]
 [        0.5000000,        0.5000000,        0.5000000,       -0.5000000]
 [        0.5000000,       -0.5000000,        0.5000000,        0.5000000]]
[
 [        0.5000000,       -0.5000000,       -0.5000000,        0.5000000]
 [        0.5000000,        0.5000000,        0.5000000,        0.5000000]
 [        0.5000000,       -0.5000000,        0.5000000,       -0.5000000]
 [       -0.5000000,       -0.5000000,        0.5000000,        0.5000000]]
*/