#![allow(non_upper_case_globals)]
use clipper2c_sys::{
ClipperClipType, ClipperClipType_DIFFERENCE, ClipperClipType_INTERSECTION,
ClipperClipType_NONE, ClipperClipType_UNION, ClipperClipType_XOR, ClipperEndType,
ClipperEndType_BUTT_END, ClipperEndType_JOINED_END, ClipperEndType_POLYGON_END,
ClipperEndType_ROUND_END, ClipperEndType_SQUARE_END, ClipperFillRule, ClipperFillRule_EVEN_ODD,
ClipperFillRule_NEGATIVE, ClipperFillRule_NON_ZERO, ClipperFillRule_POSITIVE, ClipperJoinType,
ClipperJoinType_BEVEL_JOIN, ClipperJoinType_MITER_JOIN, ClipperJoinType_ROUND_JOIN,
ClipperJoinType_SQUARE_JOIN, ClipperPointInPolygonResult,
ClipperPointInPolygonResult_IS_INSIDE, ClipperPointInPolygonResult_IS_ON,
ClipperPointInPolygonResult_IS_OUTSIDE,
};
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub enum FillRule {
#[default]
EvenOdd,
NonZero,
Positive,
Negative,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum ClipType {
#[allow(dead_code)]
None,
Intersection,
Union,
Difference,
Xor,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum JoinType {
Square,
Bevel,
Round,
Miter,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum EndType {
Polygon,
Joined,
Butt,
Square,
Round,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PointInPolygonResult {
IsOn,
IsInside,
IsOutside,
}
impl From<ClipType> for ClipperClipType {
fn from(value: ClipType) -> Self {
match value {
ClipType::None => ClipperClipType_NONE,
ClipType::Intersection => ClipperClipType_INTERSECTION,
ClipType::Union => ClipperClipType_UNION,
ClipType::Difference => ClipperClipType_DIFFERENCE,
ClipType::Xor => ClipperClipType_XOR,
}
}
}
impl From<FillRule> for ClipperFillRule {
fn from(value: FillRule) -> Self {
match value {
FillRule::EvenOdd => ClipperFillRule_EVEN_ODD,
FillRule::NonZero => ClipperFillRule_NON_ZERO,
FillRule::Positive => ClipperFillRule_POSITIVE,
FillRule::Negative => ClipperFillRule_NEGATIVE,
}
}
}
impl From<JoinType> for ClipperJoinType {
fn from(value: JoinType) -> Self {
match value {
JoinType::Square => ClipperJoinType_SQUARE_JOIN,
JoinType::Bevel => ClipperJoinType_BEVEL_JOIN,
JoinType::Round => ClipperJoinType_ROUND_JOIN,
JoinType::Miter => ClipperJoinType_MITER_JOIN,
}
}
}
impl From<EndType> for ClipperEndType {
fn from(value: EndType) -> Self {
match value {
EndType::Polygon => ClipperEndType_POLYGON_END,
EndType::Joined => ClipperEndType_JOINED_END,
EndType::Butt => ClipperEndType_BUTT_END,
EndType::Square => ClipperEndType_SQUARE_END,
EndType::Round => ClipperEndType_ROUND_END,
}
}
}
impl From<PointInPolygonResult> for ClipperPointInPolygonResult {
fn from(value: PointInPolygonResult) -> Self {
match value {
PointInPolygonResult::IsOn => ClipperPointInPolygonResult_IS_ON,
PointInPolygonResult::IsInside => ClipperPointInPolygonResult_IS_INSIDE,
PointInPolygonResult::IsOutside => ClipperPointInPolygonResult_IS_OUTSIDE,
}
}
}
impl From<ClipperPointInPolygonResult> for PointInPolygonResult {
fn from(value: ClipperPointInPolygonResult) -> Self {
match value {
ClipperPointInPolygonResult_IS_ON => PointInPolygonResult::IsOn,
ClipperPointInPolygonResult_IS_INSIDE => PointInPolygonResult::IsInside,
ClipperPointInPolygonResult_IS_OUTSIDE => PointInPolygonResult::IsOutside,
_ => panic!(
"Invalid ClipperPointInPolygonResult value {}",
value as usize
),
}
}
}