1pub type NodeIndex = usize;
2use crate::{
3 Apply, BVar, Ci, Cn, Constant, ConstantNode, Lambda, Op, OpNode, Otherwise, Piece, Piecewise,
4 Root,
5};
6
7use std::fmt;
8
9#[derive(Debug, Clone)]
10pub enum MathNode {
11 Apply(Apply),
12 Op(OpNode),
13 Constant(ConstantNode),
14 Root(Root),
15 Ci(Ci),
16 Cn(Cn),
17 Lambda(Lambda),
18 BVar(BVar),
19 Piecewise(Piecewise),
20 Piece(Piece),
21 Otherwise(Otherwise),
22}
23
24impl MathNode {
25 pub fn new_op(op: Op) -> Self {
26 MathNode::Op(OpNode {
27 op: Some(op),
28 parent: None,
29 })
30 }
31 pub fn new_constant(constant: Constant) -> Self {
32 MathNode::Constant(ConstantNode {
33 constant: Some(constant),
34 parent: None,
35 })
36 }
37}
38
39impl Default for MathNode {
40 fn default() -> Self {
41 MathNode::Root(Root::default())
42 }
43}
44
45impl fmt::Display for MathNode {
46 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47 match self {
48 MathNode::Apply(apply) => write!(f, "Apply: {}", apply),
49 MathNode::Root(root) => write!(f, "Root: {}", root),
50 MathNode::Ci(ci) => write!(f, "Ci: {}", ci),
51 MathNode::Op(opnode) => write!(f, "Op: {}", opnode),
52 MathNode::Cn(cn) => write!(f, "Cn: {}", cn),
53 MathNode::Lambda(lambda) => write!(f, "Lambda: {}", lambda),
54 MathNode::BVar(bvar) => write!(f, "BVar: {}", bvar),
55 MathNode::Piecewise(piecewise) => write!(f, "Piecewise: {}", piecewise),
56 MathNode::Piece(piece) => write!(f, "Piece: {}", piece),
57 MathNode::Otherwise(otherwise) => write!(f, "Otherwise: {}", otherwise),
58 MathNode::Constant(constantnode) => write!(f, "Constant: {}", constantnode),
59 }
60 }
61}
62
63pub enum MathNodeType {
64 Apply,
65 Op,
66 Root,
67 Ci,
68 Cn,
69 Lambda,
70 BVar,
71 Piecewise,
72 Piece,
73 Otherwise,
74 Constant,
75}
76
77impl fmt::Display for MathNodeType {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79 match self {
80 MathNodeType::Apply => write!(f, "Apply"),
81 MathNodeType::Root => write!(f, "Root"),
82 MathNodeType::Ci => write!(f, "Ci"),
83 MathNodeType::Op => write!(f, "Op"),
84 MathNodeType::Constant => write!(f, "Constant"),
85 MathNodeType::Cn => write!(f, "Cn"),
86 MathNodeType::Lambda => write!(f, "Lambda"),
87 MathNodeType::BVar => write!(f, "BVar"),
88 MathNodeType::Piecewise => write!(f, "Piecewise"),
89 MathNodeType::Piece => write!(f, "Piece"),
90 MathNodeType::Otherwise => write!(f, "Otherwise"),
91 }
92 }
93}