three_d/core/
scissor_box.rs1#[derive(Debug, Copy, Clone, PartialEq)]
7pub struct ScissorBox {
8 pub x: i32,
10 pub y: i32,
12 pub width: u32,
14 pub height: u32,
16}
17
18impl ScissorBox {
19 pub fn new_at_origo(width: u32, height: u32) -> Self {
23 Self {
24 x: 0,
25 y: 0,
26 width,
27 height,
28 }
29 }
30
31 pub fn intersection(&self, other: impl Into<Self>) -> Self {
35 let other = other.into();
36 let x = self.x.max(other.x);
37 let y = self.y.max(other.y);
38 let width = (self.x + self.width as i32 - x)
39 .min(other.x + other.width as i32 - x)
40 .max(0) as u32;
41 let height = (self.y + self.height as i32 - y)
42 .min(other.y + other.height as i32 - y)
43 .max(0) as u32;
44 Self {
45 x,
46 y,
47 width,
48 height,
49 }
50 }
51}
52
53impl From<crate::core::Viewport> for ScissorBox {
54 fn from(viewport: crate::core::Viewport) -> Self {
55 Self {
56 x: viewport.x,
57 y: viewport.y,
58 width: viewport.width,
59 height: viewport.height,
60 }
61 }
62}
63
64impl From<crate::core::ScissorBox> for crate::core::Viewport {
65 fn from(viewport: crate::core::ScissorBox) -> Self {
66 Self {
67 x: viewport.x,
68 y: viewport.y,
69 width: viewport.width,
70 height: viewport.height,
71 }
72 }
73}