use crate::segm::segment::{BOTH_BOTTOM, BOTH_TOP, CLIP_TOP, NONE, SUBJ_TOP, SegmentFill};
use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum OverlayRule {
Subject,
Clip,
Intersect,
Union,
Difference,
InverseDifference,
Xor,
}
impl OverlayRule {
#[inline(always)]
pub(crate) fn is_fill_top(&self, fill: SegmentFill) -> bool {
match self {
OverlayRule::Subject => fill & SUBJ_TOP == SUBJ_TOP,
OverlayRule::Clip => fill & CLIP_TOP == CLIP_TOP,
OverlayRule::Intersect => fill & BOTH_TOP == BOTH_TOP,
OverlayRule::Union => fill & BOTH_BOTTOM == NONE,
OverlayRule::Difference => fill & BOTH_TOP == SUBJ_TOP,
OverlayRule::InverseDifference => fill & BOTH_TOP == CLIP_TOP,
OverlayRule::Xor => {
let is_subject = fill & BOTH_TOP == SUBJ_TOP;
let is_clip = fill & BOTH_TOP == CLIP_TOP;
is_subject || is_clip
}
}
}
}
impl fmt::Display for OverlayRule {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let text = match self {
OverlayRule::Subject => "Subject",
OverlayRule::Clip => "Clip",
OverlayRule::Intersect => "Intersect",
OverlayRule::Union => "Union",
OverlayRule::Difference => "Difference",
OverlayRule::InverseDifference => "InverseDifference",
OverlayRule::Xor => "Xor",
};
write!(f, "{}", text)
}
}