use crate::diagram::ColorBits;
use crate::prelude::*;
impl EdgeIndex {
pub const INVALID: Self = Self(u32::MAX);
pub fn usize(self) -> usize {
self.0 as usize
}
pub fn u32(self) -> u32 {
self.0
}
}
impl Edge {
const BIT_IS_LINEAR: ColorType = 0x1; const BIT_IS_PRIMARY: ColorType = 0x2;
pub(super) fn new_(id: EdgeIndex, cell: CellIndex, is_linear: bool, is_primary: bool) -> Edge {
let mut rv = Self {
id_: id,
cell_: Some(cell),
vertex_: None,
twin_: None,
next_ccw_: None,
prev_ccw_: None,
color_: 0,
};
if is_linear {
rv.color_ |= Self::BIT_IS_LINEAR;
}
if is_primary {
rv.color_ |= Self::BIT_IS_PRIMARY;
}
rv
}
#[inline(always)]
pub fn id(&self) -> EdgeIndex {
self.id_
}
#[inline(always)]
pub(crate) fn cell_(&self) -> Option<CellIndex> {
self.cell_
}
#[inline(always)]
pub fn cell(&self) -> Result<CellIndex, BvError> {
self.cell_.ok_or_else(|| {
BvError::ValueError("Edge didn't have any valid cell associated to it.".to_string())
})
}
#[inline(always)]
pub fn vertex0(&self) -> Option<VertexIndex> {
self.vertex_
}
#[inline(always)]
pub(crate) fn twin_(&self) -> Option<EdgeIndex> {
self.twin_
}
#[inline(always)]
pub fn twin(&self) -> Result<EdgeIndex, BvError> {
self.twin_.ok_or_else(|| {
BvError::ValueError(
"Edge didn't have any valid twin edge associated to it.".to_string(),
)
})
}
#[inline(always)]
pub(crate) fn next_(&self) -> Option<EdgeIndex> {
self.next_ccw_
}
#[inline(always)]
pub fn next(&self) -> Result<EdgeIndex, BvError> {
self.next_ccw_.ok_or_else(|| {
BvError::ValueError(format!(
"Edge {} didn't have any valid next edge associated to it. {}:{}",
self.id_.0,
file!(),
line!()
))
})
}
#[inline(always)]
pub(crate) fn prev_(&self) -> Option<EdgeIndex> {
self.prev_ccw_
}
#[inline(always)]
pub fn prev(&self) -> Result<EdgeIndex, BvError> {
self.prev_().ok_or_else(|| {
BvError::InternalError("The edge does not have a previous edge".to_string())
})
}
#[inline]
pub fn is_linear(&self) -> bool {
(self.color_ & Self::BIT_IS_LINEAR) != 0
}
#[inline]
pub fn is_curved(&self) -> bool {
!self.is_linear()
}
#[inline]
pub fn is_primary(&self) -> bool {
(self.color_ & Self::BIT_IS_PRIMARY) != 0
}
#[inline]
pub fn is_secondary(&self) -> bool {
!self.is_primary()
}
#[inline(always)]
pub fn get_color(&self) -> ColorType {
self.color_ >> ColorBits::RESERVED_BITS__SHIFT.0
}
#[inline(always)]
pub fn set_color(&mut self, color: ColorType) -> ColorType {
self.color_ &= ColorBits::RESERVED__MASK.0;
self.color_ |= color << ColorBits::RESERVED_BITS__SHIFT.0;
self.color_
}
#[inline(always)]
pub fn or_color(&mut self, color: ColorType) -> ColorType {
self.set_color(self.get_color() | color)
}
}