mech_compare/
lib.rs

1#![no_main]
2#![allow(warnings)]
3#[macro_use]
4extern crate mech_core;
5extern crate nalgebra as na;
6extern crate paste;
7
8use mech_core::*;
9use na::{Vector3, DVector, Vector2, Vector4, RowDVector, Matrix1, Matrix3, Matrix4, RowVector3, RowVector4, RowVector2, DMatrix, Rotation3, Matrix2x3, Matrix3x2, Matrix6, Matrix2};
10use paste::paste;
11use mech_core::matrix::Matrix;
12
13pub mod gt;
14pub mod lt;
15pub mod lte;
16pub mod gte;
17pub mod eq;
18pub mod neq;
19
20pub use self::gt::*;
21pub use self::lt::*;
22pub use self::lte::*;
23pub use self::gte::*;
24pub use self::eq::*;
25pub use self::neq::*;
26
27// ----------------------------------------------------------------------------
28// Compare Library
29// ----------------------------------------------------------------------------
30
31#[macro_export]
32macro_rules! impl_compare_binop {
33  ($struct_name:ident, $arg1_type:ty, $arg2_type:ty, $out_type:ty, $op:ident) => {
34    #[derive(Debug)]
35    struct $struct_name<T> {
36    lhs: Ref<$arg1_type>,
37    rhs: Ref<$arg2_type>,
38    out: Ref<$out_type>,
39    }
40    impl<T> MechFunction for $struct_name<T>
41    where
42    T: std::fmt::Debug + Clone + Sync + Send + 'static + 
43    PartialEq + PartialOrd,
44    Ref<$out_type>: ToValue
45    {
46    fn solve(&self) {
47      let lhs_ptr = self.lhs.as_ptr();
48      let rhs_ptr = self.rhs.as_ptr();
49      let out_ptr = self.out.as_ptr();
50      $op!(lhs_ptr,rhs_ptr,out_ptr);
51    }
52    fn out(&self) -> Value { self.out.to_value() }
53    fn to_string(&self) -> String { format!("{:#?}", self) }
54    }};}
55
56#[macro_export]
57macro_rules! impl_compare_fxns {
58  ($lib:ident) => {
59    impl_fxns!($lib,T,bool,impl_compare_binop);
60  }
61}
62
63#[macro_export]
64macro_rules! impl_compare_fxns_bool {
65  ($lib:ident) => {
66    impl_fxns!($lib,T,bool,impl_compare_binop);
67  }
68}