1    object ClearValue =
2        def color (color : Vector4) =
3            let color_value = ClearColorValue
4                float32 = [color.x, color.y, color.z, color.w]
5    
6            ClearValue
7                color = color_value
8    
9        def depth_stencil (depth : f32) (stencil : u32) =
10           let depth_stencil_value = ClearDepthStencilValue =depth =stencil
11   
12           ClearValue
13               depth_stencil = depth_stencil_value
14   
15   type SampleCountFlags
16       def compare (other : SampleCountFlags) = when
17           self as u32 > other as u32 -> Ordering/Greater
18           self == other -> Ordering/Equal
19           else -> Ordering/Less
20   
21       is Compare
22   
23   object Rect2D =
24       def create (x : i32
25                   y : i32
26                   width : u32
27                   height : u32) =
28           Rect2D
29               offset = Offset2D =x =y
30               extent = Extent2D =width =height
31   
32   type Rect2D
33       def intersect (rect : Rect2D) =
34           let left = offset.x
35           let right = left + extent.width as i32
36           let down = offset.y
37           let up = down + extent.height as i32
38   
39           let rect_left = rect.offset.x
40           let rect_right = rect_left + rect.extent.width as i32
41           let rect_down = rect.offset.y
42           let rect_up = rect_down + rect.extent.height as i32
43   
44           if left >= rect_right || rect_left >= right
45              || down >= rect_up || rect_down >= up
46           then
47               Rect2D@zero
48           else
49               let x = left.max rect_left
50               let y = down.max rect_down
51               let width = right.min rect_right - x
52               let height = up.min rect_up - y
53   
54               Rect2D.create x y width.as<u32> height.as<u32>
55   
56   type Result
57       def assert_success =
58           assert self == Result/Success
59