Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

and Overlap enum for contains_rectangle #17

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions pixman/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ use paste::paste;

use crate::{Box16, Box32};

/// Describes overlap of a region with a rectangle
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Overlap {
/// No intersection
Out,
/// Region contains a rectangle
In,
/// Partial intersection
Part,
}

macro_rules! impl_region {
($(#[$attr:meta])* $name:ident, ffi => $ffi:path, impl => $impl:ident, box_t => $box_t:path, loc_t => $loc_t:path, size_t => $size_t:path$(,)?) => {
$(#[$attr])*
Expand Down Expand Up @@ -204,14 +215,14 @@ macro_rules! impl_region {
}

/// Whether this region contains the provided rectangle
pub fn contains_rectangle(&self, rect: $box_t) -> Option<usize> {
pub fn contains_rectangle(&self, rect: $box_t) -> Overlap {
let overlap =
unsafe { paste!($crate::ffi::[<$impl _contains_rectangle>](&self.0, &rect)) };

if overlap > 0 {
Some(overlap as usize)
} else {
None
match overlap {
$crate::ffi::pixman_region_overlap_t_PIXMAN_REGION_OUT => Overlap::Out,
$crate::ffi::pixman_region_overlap_t_PIXMAN_REGION_IN => Overlap::In,
$crate::ffi::pixman_region_overlap_t_PIXMAN_REGION_PART => Overlap::Part,
_ => unreachable!(),
}
}

Expand Down
Loading