1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use crate::{ffi, Bound, EdgeHolder, EdgeSegment, Polarity};
#[repr(transparent)]
pub struct Contour {
raw: ffi::msdfgen_Contour,
}
impl Default for Contour {
fn default() -> Self {
let raw = unsafe { ffi::msdfgen_Contour_constructor() };
Self { raw }
}
}
impl Drop for Contour {
fn drop(&mut self) {
unsafe {
ffi::msdfgen_Contour_destructor(&mut self.raw);
}
}
}
impl Contour {
pub(crate) fn as_raw(&self) -> &ffi::msdfgen_Contour {
&self.raw
}
pub fn add_edge(&mut self, edge: &EdgeHolder) {
unsafe { self.raw.addEdge(edge.as_raw()) }
}
pub fn add_edge_mut(&mut self) -> &mut EdgeHolder {
unsafe { &mut *(self.raw.addEdge2() as *mut EdgeHolder) }
}
pub fn add_segment(&mut self, segment: impl EdgeSegment) {
self.add_edge(&segment.into())
}
pub fn bound(&self, bound: &mut Bound<f64>) {
unsafe {
self.raw.bound(
&mut bound.left,
&mut bound.bottom,
&mut bound.right,
&mut bound.top,
)
}
}
pub fn get_bound(&self) -> Bound<f64> {
let mut bound = Bound::default();
self.bound(&mut bound);
bound
}
pub fn bound_miters(
&self,
bound: &mut Bound<f64>,
border: f64,
miter_limit: f64,
polarity: Polarity,
) {
unsafe {
self.raw.boundMiters(
&mut bound.left,
&mut bound.bottom,
&mut bound.right,
&mut bound.top,
border,
miter_limit,
polarity as _,
)
}
}
pub fn get_bound_miters(
&self,
border: f64,
miter_limit: f64,
polarity: Polarity,
) -> Bound<f64> {
let mut bound = Bound::default();
self.bound_miters(&mut bound, border, miter_limit, polarity);
bound
}
pub fn winding(&self) -> i32 {
unsafe { self.raw.winding() }
}
}