Skip to content

Commit baa9ce9

Browse files
committed
fix: clip mask checks
1 parent c075b2f commit baa9ce9

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

core/src/rectangle.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ impl Rectangle<f32> {
7979
&& point.y < self.y + self.height
8080
}
8181

82+
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
83+
/// The [`Point`] must be strictly contained, i.e. it must not be on the
84+
/// border.
85+
pub fn contains_strict(&self, point: Point) -> bool {
86+
self.x < point.x
87+
&& point.x < self.x + self.width
88+
&& self.y < point.y
89+
&& point.y < self.y + self.height
90+
}
91+
8292
/// Returns true if the current [`Rectangle`] is completely within the given
8393
/// `container`.
8494
pub fn is_within(&self, container: &Rectangle) -> bool {
@@ -88,6 +98,16 @@ impl Rectangle<f32> {
8898
)
8999
}
90100

101+
/// Returns true if the current [`Rectangle`] is completely within the given
102+
/// `container`. The [`Rectangle`] must be strictly contained, i.e. it must
103+
/// not be on the border.
104+
pub fn is_within_strict(&self, container: &Rectangle) -> bool {
105+
container.contains_strict(self.position())
106+
&& container.contains_strict(
107+
self.position() + Vector::new(self.width, self.height),
108+
)
109+
}
110+
91111
/// Computes the intersection with the given [`Rectangle`].
92112
pub fn intersection(
93113
&self,

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,13 @@
151151
#![doc(
152152
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
153153
)]
154-
#![forbid(rust_2018_idioms, unsafe_code)]
154+
#![forbid(unsafe_code)]
155155
#![deny(
156156
missing_debug_implementations,
157157
missing_docs,
158-
unused_results,
159-
rustdoc::broken_intra_doc_links
158+
rust_2018_idioms,
159+
rustdoc::broken_intra_doc_links,
160+
unused_results
160161
)]
161162
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
162163
#![cfg_attr(docsrs, feature(doc_cfg))]

tiny_skia/src/backend.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ impl Backend {
159159
return;
160160
}
161161

162-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
163-
.then_some(clip_mask as &_);
162+
let clip_mask = (!physical_bounds
163+
.is_within_strict(&clip_bounds))
164+
.then_some(clip_mask as &_);
164165

165166
let transform = tiny_skia::Transform::from_translate(
166167
translation.x,
@@ -378,8 +379,9 @@ impl Backend {
378379
return;
379380
}
380381

381-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
382-
.then_some(clip_mask as &_);
382+
let clip_mask = (!physical_bounds
383+
.is_within_strict(&clip_bounds))
384+
.then_some(clip_mask as &_);
383385

384386
self.text_pipeline.draw_paragraph(
385387
paragraph,
@@ -403,8 +405,9 @@ impl Backend {
403405
return;
404406
}
405407

406-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
407-
.then_some(clip_mask as &_);
408+
let clip_mask = (!physical_bounds
409+
.is_within_strict(&clip_bounds))
410+
.then_some(clip_mask as &_);
408411

409412
self.text_pipeline.draw_editor(
410413
editor,
@@ -434,8 +437,9 @@ impl Backend {
434437
return;
435438
}
436439

437-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
438-
.then_some(clip_mask as &_);
440+
let clip_mask = (!physical_bounds
441+
.is_within_strict(&clip_bounds))
442+
.then_some(clip_mask as &_);
439443

440444
self.text_pipeline.draw_cached(
441445
content,
@@ -465,8 +469,9 @@ impl Backend {
465469
return;
466470
}
467471

468-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
469-
.then_some(clip_mask as &_);
472+
let clip_mask = (!physical_bounds
473+
.is_within_strict(&clip_bounds))
474+
.then_some(clip_mask as &_);
470475

471476
let transform = tiny_skia::Transform::from_translate(
472477
translation.x,
@@ -502,8 +507,9 @@ impl Backend {
502507
return;
503508
}
504509

505-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
506-
.then_some(clip_mask as &_);
510+
let clip_mask = (!physical_bounds
511+
.is_within_strict(&clip_bounds))
512+
.then_some(clip_mask as &_);
507513

508514
self.vector_pipeline.draw(
509515
handle,
@@ -539,8 +545,9 @@ impl Backend {
539545
return;
540546
}
541547

542-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
543-
.then_some(clip_mask as &_);
548+
let clip_mask = (!physical_bounds
549+
.is_within_strict(&clip_bounds))
550+
.then_some(clip_mask as &_);
544551

545552
pixels.fill_path(
546553
path,
@@ -572,8 +579,9 @@ impl Backend {
572579
return;
573580
}
574581

575-
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
576-
.then_some(clip_mask as &_);
582+
let clip_mask = (!physical_bounds
583+
.is_within_strict(&clip_bounds))
584+
.then_some(clip_mask as &_);
577585

578586
pixels.stroke_path(
579587
path,

0 commit comments

Comments
 (0)