mathml_rs/structs/
cn.rs

1use super::math_node::NodeIndex;
2use super::numbers::{NumType, Number};
3use std::fmt;
4
5#[derive(Default, Debug, Clone)]
6pub struct Cn {
7    pub r#type: Option<NumType>,
8    pub value: Option<Number>,
9    pub parent: Option<NodeIndex>,
10}
11
12impl fmt::Display for Cn {
13    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14        match &self.value {
15            Some(Number::Integer(i)) => write!(f, "integer: {}", i),
16            Some(Number::Real(r)) => write!(f, "real: {}", r),
17            Some(Number::Rational(n, d)) => write!(f, "rational: {} / {}", n, d),
18            Some(Number::ComplexPolar(a, b)) | Some(Number::ComplexCartesian(a, b)) => {
19                write!(f, "complex: {}, {}", a, b)
20            }
21            Some(Number::Constant(s)) => write!(f, "complex: {}", s),
22            Some(Number::ENotation(a, b)) => write!(f, "exp: {} ^ {}", a, b),
23            None => write!(f, "type is None"),
24        }
25    }
26}
27
28//impl PartialEq for Cn {
29//fn eq(&self, other: &Self) -> bool {
30//match (self, other) {
31//(Real(r), Real(r2)) => approx::abs_diff_eq!(r, r2),
32//(Integer(r1), Integer(r2)) => r1 == r2,
33//(Rational(a, b), Rational(c, d)) => (a == c) && (b == d),
34//(ComplexPolar(a, b), ComplexPolar(c, d))
35//| (ComplexCartesian(a, b), ComplexCartesian(c, d)) => {
36//approx::abs_diff_eq!(a, c) && approx::abs_diff_eq!(b, d)
37//}
38//(Constant(a), Constant(b)) => a == b,
39//(ENotation(a, b), ENotation(c, d)) => a == c && b == d,
40//_ => false,
41//}
42//}
43//}