Skip to content

Commit ba50a41

Browse files
committed
tune cg::Path api
1 parent 706e948 commit ba50a41

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

cidre/src/cg/geometry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl Rect {
8989
/// let d = cg::Rect::zero().dictionary_representaion();
9090
/// assert_eq!(d.len(), 4);
9191
/// ```
92+
#[inline]
9293
pub fn dictionary_representaion(&self) -> arc::R<cf::Dictionary> {
9394
unsafe { CGRectCreateDictionaryRepresentation(*self) }
9495
}

cidre/src/cg/path.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ impl Path {
100100

101101
#[doc(alias = "CGPathCreateCopyByTransformingPath")]
102102
#[inline]
103-
pub fn copy_transforming_path(&self, transform: Option<&cg::AffineTransform>) -> arc::R<Self> {
103+
pub fn transforming_path(&self, transform: Option<&cg::AffineTransform>) -> arc::R<Self> {
104104
unsafe { CGPathCreateCopyByTransformingPath(self, transform) }
105105
}
106106

107107
#[doc(alias = "CGPathCreateMutableCopyByTransformingPath")]
108108
#[inline]
109-
pub fn copy_mut_transforming_path(
109+
pub fn transforming_path_mut(
110110
&self,
111111
transform: Option<&cg::AffineTransform>,
112112
) -> arc::R<PathMut> {
@@ -115,7 +115,7 @@ impl Path {
115115

116116
#[doc(alias = "CGPathCreateCopyByDashingPath")]
117117
#[inline]
118-
pub fn copy_dashing_path(
118+
pub fn dashing_path(
119119
&self,
120120
transform: Option<&cg::AffineTransform>,
121121
phase: cg::Float,
@@ -128,7 +128,7 @@ impl Path {
128128

129129
#[doc(alias = "CGPathCreateCopyByStrokingPath")]
130130
#[inline]
131-
pub fn copy_stroking_path(
131+
pub fn stroking_path(
132132
&self,
133133
transform: Option<&cg::AffineTransform>,
134134
line_width: cg::Float,
@@ -203,13 +203,14 @@ impl Path {
203203
pub fn bounding_box(&self) -> cg::Rect {
204204
unsafe { CGPathGetBoundingBox(self) }
205205
}
206-
206+
207207
#[doc(alias = "CGPathGetPathBoundingBox")]
208208
#[inline]
209209
pub fn path_bounding_box(&self) -> cg::Rect {
210210
unsafe { CGPathGetPathBoundingBox(self) }
211211
}
212212

213+
#[doc(alias = "CGPathContainsPoint")]
213214
#[inline]
214215
pub fn contains_point(
215216
&self,
@@ -237,13 +238,20 @@ impl Path {
237238
unsafe { CGPathApplyWithBlock(self, block) }
238239
}
239240

241+
#[cfg(feature = "blocks")]
242+
#[inline]
243+
pub fn apply_mut(&self, mut f: impl FnMut(&cg::PathElement)) {
244+
let mut block = unsafe { ApplyBlock::stack1(&mut f) };
245+
self.apply_block(&mut block);
246+
}
247+
240248
#[inline]
241-
pub fn copy_normalizing(&self, even_odd_fill_rule: bool) -> arc::R<Self> {
249+
pub fn normalizing(&self, even_odd_fill_rule: bool) -> arc::R<Self> {
242250
unsafe { CGPathCreateCopyByNormalizing(self, even_odd_fill_rule) }
243251
}
244252

245253
#[inline]
246-
pub fn copy_unioning_path(
254+
pub fn unioning_path(
247255
&self,
248256
mask_path: Option<&Path>,
249257
even_odd_fill_rule: bool,
@@ -252,7 +260,7 @@ impl Path {
252260
}
253261

254262
#[inline]
255-
pub fn copy_intersecting_path(
263+
pub fn intersecting_path(
256264
&self,
257265
mask_path: Option<&Path>,
258266
even_odd_fill_rule: bool,
@@ -261,7 +269,7 @@ impl Path {
261269
}
262270

263271
#[inline]
264-
pub fn copy_subtructing_path(
272+
pub fn subtructing_path(
265273
&self,
266274
mask_path: Option<&Path>,
267275
even_odd_fill_rule: bool,
@@ -270,7 +278,7 @@ impl Path {
270278
}
271279

272280
#[inline]
273-
pub fn copy_symmetric_diff_of_path(
281+
pub fn symmetric_diff_of_path(
274282
&self,
275283
mask_path: Option<&Path>,
276284
even_odd_fill_rule: bool,
@@ -279,15 +287,15 @@ impl Path {
279287
}
280288

281289
#[inline]
282-
pub fn copy_line_by_substructing_path(
290+
pub fn line_by_substructing_path(
283291
&self,
284292
mask_path: Option<&Path>,
285293
even_odd_fill_rule: bool,
286294
) -> arc::R<Self> {
287295
unsafe { CGPathCreateCopyOfLineBySubtractingPath(self, mask_path, even_odd_fill_rule) }
288296
}
289297
#[inline]
290-
pub fn copy_line_by_intersecting_path(
298+
pub fn line_by_intersecting_path(
291299
&self,
292300
mask_path: Option<&Path>,
293301
even_odd_fill_rule: bool,
@@ -301,7 +309,7 @@ impl Path {
301309
}
302310

303311
#[inline]
304-
pub fn copy_flattering(&self, flattening_threshold: cg::Float) -> arc::R<Self> {
312+
pub fn flattering(&self, flattening_threshold: cg::Float) -> arc::R<Self> {
305313
unsafe { CGPathCreateCopyByFlattening(self, flattening_threshold) }
306314
}
307315

@@ -312,17 +320,20 @@ impl Path {
312320
}
313321

314322
impl PartialEq for Path {
323+
#[inline]
315324
fn eq(&self, other: &Self) -> bool {
316325
self.equal(other)
317326
}
318327
}
319328

320329
define_cf_type!(PathMut(Path));
321330
impl PathMut {
331+
#[inline]
322332
pub fn new() -> arc::R<Self> {
323333
unsafe { CGPathCreateMutable() }
324334
}
325335

336+
#[inline]
326337
pub fn add_rounded_rect(
327338
&mut self,
328339
transform: Option<&cg::AffineTransform>,
@@ -740,7 +751,7 @@ mod tests {
740751
let path = cg::Path::with_ellipse_in_rect(cg::Rect::zero(), None);
741752
path.show();
742753

743-
let path = path.copy_stroking_path(
754+
let path = path.stroking_path(
744755
None,
745756
5.0f64,
746757
cg::LineCap::Round,
@@ -765,5 +776,11 @@ mod tests {
765776
path.curve_to(10, 20, 30, -40, 10, 20);
766777
path.close_subpath();
767778
path.show();
779+
780+
elements.clear();
781+
path.apply_mut(|element| {
782+
elements.push(element.type_);
783+
});
784+
assert!(!elements.is_empty());
768785
}
769786
}

cidre/src/mtl/argument.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ define_obj_type!(pub ArrayType(BaseType));
182182
define_obj_type!(pub PointerType(BaseType));
183183
define_obj_type!(pub TextureRefType(BaseType));
184184

185-
define_obj_type!(pub Arg(ns::Id));
185+
define_obj_type!(
186+
#[doc(alias = "MTLArgument")]
187+
pub Arg(ns::Id)
188+
);
186189

187190
impl Arg {
188191
#[objc::msg_send(name)]

0 commit comments

Comments
 (0)