Skip to content
Merged
Changes from 1 commit
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
104 changes: 103 additions & 1 deletion iOverlay/src/string/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ impl IntClip for [IntPoint] {
}
}


#[cfg(test)]
mod tests {
use alloc::vec;
Expand Down Expand Up @@ -354,4 +353,107 @@ mod tests {
assert_eq!(result_0.len(), 3);
assert_eq!(result_1.len(), 2);
}

#[test]
fn test_tiny_shape() {
let path = vec![
IntPoint::new(-1, 0),
IntPoint::new(1, 0),
IntPoint::new(0, 1),
];

let result_0 = path.clip_line(
[IntPoint::new(0, -1), IntPoint::new(0, 2)],
FillRule::NonZero,
ClipRule { invert: false, boundary_included: false },
);

let result_1 = path.clip_line(
[IntPoint::new(0, -1), IntPoint::new(0, 2)],
FillRule::NonZero,
ClipRule { invert: true, boundary_included: false },
);

assert_eq!(result_0.len(), 1);
assert_eq!(result_1.len(), 2);
}

#[test]
fn test_shared_vertices_0() {
let path = vec![
IntPoint::new(-1, -1),
IntPoint::new(1, -1),
IntPoint::new(1, 1),
IntPoint::new(-1, 1),
];

let result_0 = path.clip_line(
[IntPoint::new(-1, -1), IntPoint::new(1, -1)],
FillRule::NonZero,
ClipRule { invert: false, boundary_included: false },
);

let result_1 = path.clip_line(
[IntPoint::new(-1, -1), IntPoint::new(1, -1)],
FillRule::NonZero,
ClipRule { invert: false, boundary_included: true },
);

assert_eq!(result_0.len(), 0);
assert_eq!(result_1.len(), 1);
}

#[test]
fn test_shared_vertices_1() {
let rect = vec![

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to rename it to something neutral like path_0. It's not a rect right now

IntPoint::new(-2, -2),
IntPoint::new(2, -2),
IntPoint::new(3, 0),
IntPoint::new(-3, 0),
];

let path = vec![
IntPoint::new(-4, 1),
IntPoint::new(-2, -2),
IntPoint::new(2, -2),
IntPoint::new(4, 1),
];

let result_0 = rect.clip_path(&path, FillRule::NonZero,
ClipRule { invert: false, boundary_included: false },
);

let result_1 = rect.clip_path(&path, FillRule::NonZero,
ClipRule { invert: false, boundary_included: true },
);

assert_eq!(result_0.len(), 0);
assert_eq!(result_1.len(), 1);
}

#[test]
fn test_sliding_intersection() {
let path = vec![
IntPoint::new(0, 0),
IntPoint::new(2, 0),
IntPoint::new(2, 2),
IntPoint::new(1, 0),
IntPoint::new(0, 2),
];

let result_0 = path.clip_line(
[IntPoint::new(-3, 2), IntPoint::new(3, 2)],
FillRule::NonZero,
ClipRule { invert: false, boundary_included: false },
);

let result_1 = path.clip_line(
[IntPoint::new(-3, 2), IntPoint::new(3, 2)],
FillRule::NonZero,
ClipRule { invert: false, boundary_included: false },
);

assert_eq!(result_0.len(), 0);
assert_eq!(result_1.len(), 0);
}
}