-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathgeometry.rs
67 lines (58 loc) · 1.59 KB
/
geometry.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Wrapper methods for various geometry types (rects, sizes, ec).
use core_graphics::geometry::{CGPoint, CGRect, CGSize};
/// A struct that represents a box - top, left, width and height. You might use this for, say,
/// setting the initial frame of a view.
#[derive(Copy, Clone, Debug)]
pub struct Rect {
/// Distance from the top, in points.
pub top: f64,
/// Distance from the left, in points.
pub left: f64,
/// Width, in points.
pub width: f64,
/// Height, in points.
pub height: f64
}
impl Rect {
/// Returns a new `Rect` initialized with the values specified.
pub fn new(top: f64, left: f64, width: f64, height: f64) -> Self {
Rect {
top: top,
left: left,
width: width,
height: height
}
}
/// Returns a zero'd out Rect, with f64 (32-bit is mostly dead on Cocoa, so... this is "okay").
pub fn zero() -> Rect {
Rect {
top: 0.0,
left: 0.0,
width: 0.0,
height: 0.0
}
}
}
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[repr(u32)]
pub enum Edge {
MinX = 0,
MinY = 1,
MaxX = 2,
MaxY = 3
}
impl From<Rect> for CGRect {
fn from(rect: Rect) -> CGRect {
CGRect::new(&CGPoint::new(rect.left, rect.top), &CGSize::new(rect.width, rect.height))
}
}
impl From<CGRect> for Rect {
fn from(rect: CGRect) -> Rect {
Rect {
top: rect.origin.y as f64,
left: rect.origin.x as f64,
width: rect.size.width as f64,
height: rect.size.height as f64
}
}
}