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 acos;
25pub mod acosh;
26pub mod acot;
27pub mod acsc;
28pub mod asec;
29pub mod asin;
30pub mod asinh;
31pub mod atan;
32pub mod atan2;
33pub mod cos;
34pub mod cosh;
35pub mod cot;
36pub mod csc;
37pub mod sec;
38pub mod sin;
39pub mod sinh;
40pub mod tan;
41pub mod tanh;
42
43pub use self::acos::*;
44pub use self::acosh::*;
45pub use self::acot::*;
46pub use self::acsc::*;
47pub use self::asec::*;
48pub use self::asin::*;
49pub use self::asinh::*;
50pub use self::atan::*;
51pub use self::atan2::*;
52pub use self::cos::*;
53pub use self::cosh::*;
54pub use self::cot::*;
55pub use self::csc::*;
56pub use self::sec::*;
57pub use self::sin::*;
58pub use self::sinh::*;
59pub use self::tan::*;
60pub use self::tanh::*;
61
62#[macro_export]
67macro_rules! impl_math_fxns {
68 ($lib:ident) => {
69 impl_fxns!($lib,T,T,impl_binop);
70 }}
71
72#[macro_export]
73macro_rules! impl_urnop_match_arms2 {
74 ($lib:ident, $arg:expr, $($lhs_type:ident => $($matrix_kind:ident, $target_type:ident, $default:expr, $value_string:tt),+);+ $(;)?) => {
75 paste!{
76 match $arg {
77 $(
78 $(
79 (Value::$lhs_type(arg)) => Ok(Box::new([<$lib $lhs_type S>]{arg: arg.clone(), out: new_ref($default) })),
80 #[cfg(all(feature = $value_string, feature = "Matrix1"))]
81 (Value::$matrix_kind(Matrix::Matrix1(arg))) => Ok(Box::new([<$lib $lhs_type M1>]{arg, out: new_ref(Matrix1::from_element($default))})),
82 #[cfg(all(feature = $value_string, feature = "Matrix2"))]
83 (Value::$matrix_kind(Matrix::Matrix2(arg))) => Ok(Box::new([<$lib $lhs_type M2>]{arg, out: new_ref(Matrix2::from_element($default))})),
84 #[cfg(all(feature = $value_string, feature = "Matrix3"))]
85 (Value::$matrix_kind(Matrix::Matrix3(arg))) => Ok(Box::new([<$lib $lhs_type M3>]{arg, out: new_ref(Matrix3::from_element($default))})),
86 #[cfg(all(feature = $value_string, feature = "Matrix4"))]
87 (Value::$matrix_kind(Matrix::Matrix4(arg))) => Ok(Box::new([<$lib $lhs_type M4>]{arg, out: new_ref(Matrix4::from_element($default))})),
88 #[cfg(all(feature = $value_string, feature = "Matrix2x3"))]
89 (Value::$matrix_kind(Matrix::Matrix2x3(arg))) => Ok(Box::new([<$lib $lhs_type M2x3>]{arg, out: new_ref(Matrix2x3::from_element($default))})),
90 #[cfg(all(feature = $value_string, feature = "Matrix3x2"))]
91 (Value::$matrix_kind(Matrix::Matrix3x2(arg))) => Ok(Box::new([<$lib $lhs_type M3x2>]{arg, out: new_ref(Matrix3x2::from_element($default))})),
92 #[cfg(all(feature = $value_string, feature = "RowVector2"))]
93 (Value::$matrix_kind(Matrix::RowVector2(arg))) => Ok(Box::new([<$lib $lhs_type R2>]{arg: arg.clone(), out: new_ref(RowVector2::from_element($default)) })),
94 #[cfg(all(feature = $value_string, feature = "RowVector3"))]
95 (Value::$matrix_kind(Matrix::RowVector3(arg))) => Ok(Box::new([<$lib $lhs_type R3>]{arg: arg.clone(), out: new_ref(RowVector3::from_element($default)) })),
96 #[cfg(all(feature = $value_string, feature = "RowVector4"))]
97 (Value::$matrix_kind(Matrix::RowVector4(arg))) => Ok(Box::new([<$lib $lhs_type R4>]{arg: arg.clone(), out: new_ref(RowVector4::from_element($default)) })),
98 #[cfg(all(feature = $value_string, feature = "RowVectorD"))]
99 (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))})),
100 #[cfg(all(feature = $value_string, feature = "Vector2"))]
101 (Value::$matrix_kind(Matrix::Vector2(arg))) => Ok(Box::new([<$lib $lhs_type V2>]{arg: arg.clone(), out: new_ref(Vector2::from_element($default)) })),
102 #[cfg(all(feature = $value_string, feature = "Vector3"))]
103 (Value::$matrix_kind(Matrix::Vector3(arg))) => Ok(Box::new([<$lib $lhs_type V3>]{arg: arg.clone(), out: new_ref(Vector3::from_element($default)) })),
104 #[cfg(all(feature = $value_string, feature = "Vector4"))]
105 (Value::$matrix_kind(Matrix::Vector4(arg))) => Ok(Box::new([<$lib $lhs_type V4>]{arg: arg.clone(), out: new_ref(Vector4::from_element($default)) })),
106 #[cfg(all(feature = $value_string, feature = "VectorD"))]
107 (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))})),
108 #[cfg(all(feature = $value_string, feature = "MatrixD"))]
109 (Value::$matrix_kind(Matrix::DMatrix(arg))) => {
110 let (rows,cols) = {arg.borrow().shape()};
111 Ok(Box::new([<$lib $lhs_type MD>]{arg, out: new_ref(DMatrix::from_element(rows,cols,$default))}))},
112 )+
113 )+
114 x => Err(MechError{file: file!().to_string(), tokens: vec![], msg: format!("{:?}", x).to_string(), id: line!(), kind: MechErrorKind::UnhandledFunctionArgumentKind }),
115 }}}}
116
117#[macro_export]
118macro_rules! impl_math_urop {
119 ($fxn_name:ident, $type:ident, $op_fxn:ident) => {
120 paste!{
121 impl_urop!([<$fxn_name $type S>], $type, $type, [<$op_fxn _op>]);
122 #[cfg(feature = "Matrix1")]
123 impl_urop!([<$fxn_name $type M1>], Matrix1<$type>, Matrix1<$type>, [<$op_fxn _vec_op>]);
124 #[cfg(feature = "Matrix2")]
125 impl_urop!([<$fxn_name $type M2>], Matrix2<$type>, Matrix2<$type>, [<$op_fxn _vec_op>]);
126 #[cfg(feature = "Matrix3")]
127 impl_urop!([<$fxn_name $type M3>], Matrix3<$type>, Matrix3<$type>, [<$op_fxn _vec_op>]);
128 #[cfg(feature = "Matrix4")]
129 impl_urop!([<$fxn_name $type M4>], Matrix4<$type>, Matrix4<$type>, [<$op_fxn _vec_op>]);
130 #[cfg(feature = "Matrix2x3")]
131 impl_urop!([<$fxn_name $type M2x3>], Matrix2x3<$type>, Matrix2x3<$type>, [<$op_fxn _vec_op>]);
132 #[cfg(feature = "Matrix3x2")]
133 impl_urop!([<$fxn_name $type M3x2>], Matrix3x2<$type>, Matrix3x2<$type>, [<$op_fxn _vec_op>]);
134 #[cfg(feature = "MatrixD")]
135 impl_urop!([<$fxn_name $type MD>], DMatrix<$type>, DMatrix<$type>, [<$op_fxn _vec_op>]);
136 #[cfg(feature = "RowVector2")]
137 impl_urop!([<$fxn_name $type R2>], RowVector2<$type>, RowVector2<$type>, [<$op_fxn _vec_op>]);
138 #[cfg(feature = "RowVector3")]
139 impl_urop!([<$fxn_name $type R3>], RowVector3<$type>, RowVector3<$type>, [<$op_fxn _vec_op>]);
140 #[cfg(feature = "RowVector4")]
141 impl_urop!([<$fxn_name $type R4>], RowVector4<$type>, RowVector4<$type>, [<$op_fxn _vec_op>]);
142 #[cfg(feature = "RowVectorD")]
143 impl_urop!([<$fxn_name $type RD>], RowDVector<$type>, RowDVector<$type>, [<$op_fxn _vec_op>]);
144 #[cfg(feature = "Vector2")]
145 impl_urop!([<$fxn_name $type V2>], Vector2<$type>, Vector2<$type>, [<$op_fxn _vec_op>]);
146 #[cfg(feature = "Vector3")]
147 impl_urop!([<$fxn_name $type V3>], Vector3<$type>, Vector3<$type>, [<$op_fxn _vec_op>]);
148 #[cfg(feature = "Vector4")]
149 impl_urop!([<$fxn_name $type V4>], Vector4<$type>, Vector4<$type>, [<$op_fxn _vec_op>]);
150 #[cfg(feature = "VectorD")]
151 impl_urop!([<$fxn_name $type VD>], DVector<$type>, DVector<$type>, [<$op_fxn _vec_op>]);
152 }}}