use crate::prelude::Orientation2D;
use num_traits::Num;
pub trait RuleBase {
type LayerId: Eq + Clone;
}
pub trait DistanceRuleBase: RuleBase {
type Distance: Num + Copy + PartialOrd;
type Area: Num + Copy + PartialOrd;
}
pub trait MinimumSpacing: DistanceRuleBase {
fn min_spacing_absolute(&self, layer: &Self::LayerId) -> Option<Self::Distance>;
fn min_spacing(
&self,
layer: &Self::LayerId,
run_length: Self::Distance,
width: Self::Distance,
) -> Option<Self::Distance>;
}
pub trait MinimumWidth: DistanceRuleBase {
fn min_width(
&self,
layer: &Self::LayerId,
shape_length: Option<Self::Distance>,
) -> Option<Self::Distance>;
}
pub trait DefaultWidth: DistanceRuleBase {
fn default_width(
&self,
layer: &Self::LayerId,
shape_length: Option<Self::Distance>,
) -> Option<Self::Distance>;
}
pub trait PreferredRoutingDirection: RuleBase {
fn preferred_routing_direction(&self, layer: &Self::LayerId) -> Option<Orientation2D>;
}
pub trait RoutingRules:
PreferredRoutingDirection + DefaultWidth + MinimumSpacing + MinimumWidth
{
fn default_pitch(&self, layer: &Self::LayerId) -> Option<(Self::Distance, Self::Distance)>;
fn default_pitch_preferred_direction(&self, layer: &Self::LayerId) -> Option<Self::Distance> {
let pitch = self.default_pitch(layer)?;
let preferred_direction = self.preferred_routing_direction(layer)?;
match preferred_direction {
Orientation2D::Horizontal => Some(pitch.1),
Orientation2D::Vertical => Some(pitch.0),
}
}
}