1#![no_main]
2#![allow(warnings)]
3#[macro_use]
4extern crate mech_core;
5extern crate libm;
6extern crate nalgebra as na;
7extern crate paste;
8extern crate simba;
9
10use paste::paste;
11use na::{Vector3, DVector, Vector2, Vector4, RowDVector, Matrix1, Matrix3, Matrix4, RowVector3, RowVector4, RowVector2, DMatrix, Rotation3, Matrix2x3, Matrix3x2, Matrix6, Matrix2};
12use std::ops::*;
13use num_traits::*;
14use std::fmt::Debug;
15use simba::scalar::ClosedNeg;
16use num_traits::Pow;
17use mech_core::matrix::Matrix;
18
19static PI: f64 = 3.14159265358979323846264338327950288;
23
24pub mod atan2;
25pub mod cos;
26pub mod sin;
27
28pub use self::atan2::*;
29pub use self::cos::*;
30pub use self::sin::*;
31
32#[macro_export]
37macro_rules! impl_math_fxns {
38 ($lib:ident) => {
39 impl_fxns!($lib,T,T,impl_binop);
40 }}
41
42#[macro_export]
43macro_rules! impl_urnop_match_arms2 {
44 ($lib:ident, $arg:expr, $($lhs_type:ident => $($matrix_kind:ident, $target_type:ident, $default:expr, $value_string:tt),+);+ $(;)?) => {
45 paste!{
46 match $arg {
47 $(
48 $(
49 (Value::$lhs_type(arg)) => Ok(Box::new([<$lib $lhs_type S>]{arg: arg.clone(), out: new_ref($default) })),
50 #[cfg(all(feature = $value_string, feature = "Matrix1"))]
51 (Value::$matrix_kind(Matrix::Matrix1(arg))) => Ok(Box::new([<$lib $lhs_type M1>]{arg, out: new_ref(Matrix1::from_element($default))})),
52 #[cfg(all(feature = $value_string, feature = "Matrix2"))]
53 (Value::$matrix_kind(Matrix::Matrix2(arg))) => Ok(Box::new([<$lib $lhs_type M2>]{arg, out: new_ref(Matrix2::from_element($default))})),
54 #[cfg(all(feature = $value_string, feature = "Matrix3"))]
55 (Value::$matrix_kind(Matrix::Matrix3(arg))) => Ok(Box::new([<$lib $lhs_type M3>]{arg, out: new_ref(Matrix3::from_element($default))})),
56 #[cfg(all(feature = $value_string, feature = "Matrix4"))]
57 (Value::$matrix_kind(Matrix::Matrix4(arg))) => Ok(Box::new([<$lib $lhs_type M4>]{arg, out: new_ref(Matrix4::from_element($default))})),
58 #[cfg(all(feature = $value_string, feature = "Matrix2x3"))]
59 (Value::$matrix_kind(Matrix::Matrix2x3(arg))) => Ok(Box::new([<$lib $lhs_type M2x3>]{arg, out: new_ref(Matrix2x3::from_element($default))})),
60 #[cfg(all(feature = $value_string, feature = "Matrix3x2"))]
61 (Value::$matrix_kind(Matrix::Matrix3x2(arg))) => Ok(Box::new([<$lib $lhs_type M3x2>]{arg, out: new_ref(Matrix3x2::from_element($default))})),
62 #[cfg(all(feature = $value_string, feature = "RowVector2"))]
63 (Value::$matrix_kind(Matrix::RowVector2(arg))) => Ok(Box::new([<$lib $lhs_type R2>]{arg: arg.clone(), out: new_ref(RowVector2::from_element($default)) })),
64 #[cfg(all(feature = $value_string, feature = "RowVector3"))]
65 (Value::$matrix_kind(Matrix::RowVector3(arg))) => Ok(Box::new([<$lib $lhs_type R3>]{arg: arg.clone(), out: new_ref(RowVector3::from_element($default)) })),
66 #[cfg(all(feature = $value_string, feature = "RowVector4"))]
67 (Value::$matrix_kind(Matrix::RowVector4(arg))) => Ok(Box::new([<$lib $lhs_type R4>]{arg: arg.clone(), out: new_ref(RowVector4::from_element($default)) })),
68 #[cfg(all(feature = $value_string, feature = "RowVectorD"))]
69 (Value::$matrix_kind(Matrix::RowDVector(arg))) => Ok(Box::new([<$lib $lhs_type RD>]{arg: arg.clone(), out: new_ref(RowDVector::from_element(arg.borrow().len(),$default))})),
70 #[cfg(all(feature = $value_string, feature = "Vector2"))]
71 (Value::$matrix_kind(Matrix::Vector2(arg))) => Ok(Box::new([<$lib $lhs_type V2>]{arg: arg.clone(), out: new_ref(Vector2::from_element($default)) })),
72 #[cfg(all(feature = $value_string, feature = "Vector3"))]
73 (Value::$matrix_kind(Matrix::Vector3(arg))) => Ok(Box::new([<$lib $lhs_type V3>]{arg: arg.clone(), out: new_ref(Vector3::from_element($default)) })),
74 #[cfg(all(feature = $value_string, feature = "Vector4"))]
75 (Value::$matrix_kind(Matrix::Vector4(arg))) => Ok(Box::new([<$lib $lhs_type V4>]{arg: arg.clone(), out: new_ref(Vector4::from_element($default)) })),
76 #[cfg(all(feature = $value_string, feature = "VectorD"))]
77 (Value::$matrix_kind(Matrix::DVector(arg))) => Ok(Box::new([<$lib $lhs_type VD>]{arg: arg.clone(), out: new_ref(DVector::from_element(arg.borrow().len(),$default))})),
78 #[cfg(all(feature = $value_string, feature = "MatrixD"))]
79 (Value::$matrix_kind(Matrix::DMatrix(arg))) => {
80 let (rows,cols) = {arg.borrow().shape()};
81 Ok(Box::new([<$lib $lhs_type MD>]{arg, out: new_ref(DMatrix::from_element(rows,cols,$default))}))},
82 )+
83 )+
84 x => Err(MechError{file: file!().to_string(), tokens: vec![], msg: format!("{:?}", x).to_string(), id: line!(), kind: MechErrorKind::UnhandledFunctionArgumentKind }),
85 }}}}
86
87#[macro_export]
88macro_rules! impl_math_urop {
89 ($fxn_name:ident, $type:ident, $op_fxn:ident) => {
90 paste!{
91 impl_urop!([<$fxn_name $type S>], $type, $type, [<$op_fxn _op>]);
92 #[cfg(feature = "Matrix1")]
93 impl_urop!([<$fxn_name $type M1>], Matrix1<$type>, Matrix1<$type>, [<$op_fxn _vec_op>]);
94 #[cfg(feature = "Matrix2")]
95 impl_urop!([<$fxn_name $type M2>], Matrix2<$type>, Matrix2<$type>, [<$op_fxn _vec_op>]);
96 #[cfg(feature = "Matrix3")]
97 impl_urop!([<$fxn_name $type M3>], Matrix3<$type>, Matrix3<$type>, [<$op_fxn _vec_op>]);
98 #[cfg(feature = "Matrix4")]
99 impl_urop!([<$fxn_name $type M4>], Matrix4<$type>, Matrix4<$type>, [<$op_fxn _vec_op>]);
100 #[cfg(feature = "Matrix2x3")]
101 impl_urop!([<$fxn_name $type M2x3>], Matrix2x3<$type>, Matrix2x3<$type>, [<$op_fxn _vec_op>]);
102 #[cfg(feature = "Matrix3x2")]
103 impl_urop!([<$fxn_name $type M3x2>], Matrix3x2<$type>, Matrix3x2<$type>, [<$op_fxn _vec_op>]);
104 #[cfg(feature = "MatrixD")]
105 impl_urop!([<$fxn_name $type MD>], DMatrix<$type>, DMatrix<$type>, [<$op_fxn _vec_op>]);
106 #[cfg(feature = "RowVector2")]
107 impl_urop!([<$fxn_name $type R2>], RowVector2<$type>, RowVector2<$type>, [<$op_fxn _vec_op>]);
108 #[cfg(feature = "RowVector3")]
109 impl_urop!([<$fxn_name $type R3>], RowVector3<$type>, RowVector3<$type>, [<$op_fxn _vec_op>]);
110 #[cfg(feature = "RowVector4")]
111 impl_urop!([<$fxn_name $type R4>], RowVector4<$type>, RowVector4<$type>, [<$op_fxn _vec_op>]);
112 #[cfg(feature = "RowVectorD")]
113 impl_urop!([<$fxn_name $type RD>], RowDVector<$type>, RowDVector<$type>, [<$op_fxn _vec_op>]);
114 #[cfg(feature = "Vector2")]
115 impl_urop!([<$fxn_name $type V2>], Vector2<$type>, Vector2<$type>, [<$op_fxn _vec_op>]);
116 #[cfg(feature = "Vector3")]
117 impl_urop!([<$fxn_name $type V3>], Vector3<$type>, Vector3<$type>, [<$op_fxn _vec_op>]);
118 #[cfg(feature = "Vector4")]
119 impl_urop!([<$fxn_name $type V4>], Vector4<$type>, Vector4<$type>, [<$op_fxn _vec_op>]);
120 #[cfg(feature = "VectorD")]
121 impl_urop!([<$fxn_name $type VD>], DVector<$type>, DVector<$type>, [<$op_fxn _vec_op>]);
122 }}}