use std::hash::Hash;
use std::collections::{HashMap, HashSet};
pub struct BroadcastLeafPatternIntermediateInformation<LifelineIdentifier : Eq + Hash + Copy + Clone> {
pub y_space_top_to_bottom : f32,
pub y_space_top_to_midline : f32,
pub message_drawing_location : (MessageDrawingLocation<LifelineIdentifier>,f32),
pub involved_lifelines : HashSet<LifelineIdentifier>,
pub lifelines_horizontal_requirements : HashMap<LifelineIdentifier,LifelineRequiredHorizontalSpaceInDiagram>,
pub required_space_under_emission : Option<(LifelineIdentifier, f32)>,
pub input_gate_width : f32,
pub output_gates_max_width : f32,
pub y_shift_above_midline_for_output_gates : f32
}
impl<LifelineIdentifier : Eq + Hash + Copy + Clone> BroadcastLeafPatternIntermediateInformation<LifelineIdentifier> {
pub fn new(
y_space_top_to_bottom : f32,
y_space_top_to_midline : f32,
message_drawing_location : (MessageDrawingLocation<LifelineIdentifier>,f32),
involved_lifelines : HashSet<LifelineIdentifier>,
lifelines_horizontal_requirements : HashMap<LifelineIdentifier,LifelineRequiredHorizontalSpaceInDiagram>,
required_space_under_emission : Option<(LifelineIdentifier, f32)>,
input_gate_width : f32,
output_gates_max_width : f32,
y_shift_above_midline_for_output_gates : f32
) -> BroadcastLeafPatternIntermediateInformation<LifelineIdentifier> {
BroadcastLeafPatternIntermediateInformation{
y_space_top_to_bottom,
y_space_top_to_midline,
message_drawing_location,
involved_lifelines,
lifelines_horizontal_requirements,
required_space_under_emission,
input_gate_width,
output_gates_max_width,
y_shift_above_midline_for_output_gates
}
}
}
pub struct MessageDrawingLocation<LifelineIdentifier : Eq + Hash + Copy + Clone> {
pub anchor_lifeline : LifelineIdentifier,
pub draw_message_on_left : bool
}
impl<LifelineIdentifier : Eq + Hash + Copy + Clone> MessageDrawingLocation<LifelineIdentifier> {
pub fn new(anchor_lifeline : LifelineIdentifier,draw_message_on_left : bool) -> MessageDrawingLocation<LifelineIdentifier> {
MessageDrawingLocation{anchor_lifeline,draw_message_on_left}
}
}
#[derive(Clone)]
pub struct LifelineRequiredHorizontalSpaceInDiagram {
pub on_the_left : f32,
pub on_the_right : f32
}
impl LifelineRequiredHorizontalSpaceInDiagram {
pub fn new(on_the_left : f32,on_the_right : f32) -> LifelineRequiredHorizontalSpaceInDiagram {
LifelineRequiredHorizontalSpaceInDiagram{on_the_left,on_the_right}
}
pub fn new_empty() -> LifelineRequiredHorizontalSpaceInDiagram {
LifelineRequiredHorizontalSpaceInDiagram::new(0.0,0.0)
}
pub fn update_to_max(&mut self, other : Self) {
self.on_the_left = f32::max(self.on_the_left, other.on_the_left);
self.on_the_right = f32::max(self.on_the_right, other.on_the_right);
}
pub fn update_all_to_max<LI : Eq + Hash>(
req1 : &mut HashMap<LI,LifelineRequiredHorizontalSpaceInDiagram>,
req2 : HashMap<LI,LifelineRequiredHorizontalSpaceInDiagram>) {
for (lf,r2) in req2 {
match req1.get_mut(&lf) {
None => {
req1.insert(lf,r2);
},
Some(r1) => {
r1.update_to_max(r2);
}
}
}
}
}