1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::node::Node;
use mcai_types::Coordinates;
use std::cell::Ref;

#[derive(Clone, Debug, PartialEq)]
pub enum LinkType {
  Parentage,
  Requirement,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Link {
  start_node_id: u32,
  end_node_id: u32,
  start: Coordinates,
  end: Coordinates,
}

impl Link {
  pub fn new(start_node_id: u32, end_node_id: u32, start: Coordinates, end: Coordinates) -> Self {
    Self {
      start_node_id,
      end_node_id,
      start,
      end,
    }
  }

  pub fn start_node_id(&self) -> u32 {
    self.start_node_id
  }
  pub fn end_node_id(&self) -> u32 {
    self.end_node_id
  }
  pub fn start(&self) -> Coordinates {
    self.start.clone()
  }
  pub fn end(&self) -> Coordinates {
    self.end.clone()
  }
}

impl From<(&Node, Ref<'_, Node>)> for Link {
  fn from((from, to): (&Node, Ref<Node>)) -> Self {
    Link {
      start_node_id: from.id(),
      end_node_id: to.id(),
      start: from.get_input_coordinates(),
      end: to.get_output_coordinates(),
    }
  }
}