-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrectangle.go
More file actions
36 lines (28 loc) · 748 Bytes
/
Copy pathrectangle.go
File metadata and controls
36 lines (28 loc) · 748 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
package chessImager
import "image"
type Rectangle struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `json:"height"`
}
func (r Rectangle) coords() (float64, float64, float64, float64) {
return r.X, r.Y, r.Width, r.Height
}
func (r Rectangle) shrink(f float64) Rectangle {
wf := r.Width * (1 - f) / 2
hf := r.Height * (1 - f) / 2
rr := Rectangle{
X: r.X + wf,
Y: r.Y + hf,
Width: r.Width - wf*2,
Height: r.Height - hf*2,
}
return rr
}
func (r Rectangle) toImageRect() image.Rectangle {
return image.Rect(int(r.X), int(r.Y), int(r.X+r.Width), int(r.Y+r.Height))
}
func (r Rectangle) center() (float64, float64) {
return r.X + r.Width/2, r.Y + r.Height/2
}