-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeometry.go
More file actions
61 lines (54 loc) · 828 Bytes
/
Copy pathgeometry.go
File metadata and controls
61 lines (54 loc) · 828 Bytes
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
package edit
type Position struct {
X, Y int
}
type Size struct {
W, H int
}
type Rectangle struct {
Position
Size
}
func (r Rectangle) BottomRight() Position {
return Position{r.X + r.W, r.Y + r.H}
}
func (p Position) MoveBy(q Position) Position {
return Position{
p.X + q.X,
p.Y + q.Y,
}
}
func (p Position) MoveByX(x int) Position {
return Position{
p.X + x,
p.Y,
}
}
func (r Rectangle) Intersect(s Rectangle) Rectangle {
r1 := r.BottomRight()
s1 := s.BottomRight()
if r.X < s.X {
r.X = s.X
}
if r.Y < s.Y {
r.Y = s.Y
}
if r1.X > s1.X {
r1.X = s1.X
}
if r1.Y > s1.Y {
r1.Y = s1.Y
}
r.W = s1.X - r.X
if r.W < 0 {
r.W = 0
}
r.H = s1.Y - r.Y
if r.H < 0 {
r.H = 0
}
return r
}
func (s Size) Contains(p Position) bool {
return p.X >= 0 && p.Y >= 0 && p.X < s.W && p.Y < s.H
}