-
Notifications
You must be signed in to change notification settings - Fork 23
/
box.go
40 lines (32 loc) · 867 Bytes
/
box.go
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
package wordclouds
import "fmt"
type Box struct {
Top float64
Left float64
Right float64
Bottom float64
}
func (a *Box) x() float64 {
return a.Left
}
func (a *Box) y() float64 {
return a.Bottom
}
func (a *Box) w() float64 {
return a.Right - a.Left
}
func (a *Box) h() float64 {
return a.Top - a.Bottom
}
func (a *Box) fits(width float64, height float64) bool {
return a.Bottom > 0 && a.Top < height && a.Left > 0 && a.Right < width
}
func (a *Box) overlaps(b *Box) bool {
return a.Left <= b.Right && a.Right >= b.Left && a.Top >= b.Bottom && a.Bottom <= b.Top
}
func (a *Box) overlapsRaw(top float64, left float64, right float64, bottom float64) bool {
return a.Left <= right && a.Right >= left && a.Top >= bottom && a.Bottom <= top
}
func (a *Box) String() string {
return fmt.Sprintf("[x %f y %f w %f h %f]", a.x(), a.y(), a.w(), a.h())
}