-
Notifications
You must be signed in to change notification settings - Fork 26
/
point.go
69 lines (55 loc) · 1.4 KB
/
point.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
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
68
69
// Copyright 2018 Joshua J Baker. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package geometry
type Point struct {
X, Y float64
}
func (point Point) Move(deltaX, deltaY float64) Point {
return Point{X: point.X + deltaX, Y: point.Y + deltaY}
}
func (point Point) Empty() bool {
return false
}
func (point Point) Valid() bool {
return point.X >= -180 && point.X <= 180 && point.Y >= -90 && point.Y <= 90
}
func (point Point) Rect() Rect {
return Rect{point, point}
}
func (point Point) ContainsPoint(other Point) bool {
return point == other
}
func (point Point) IntersectsPoint(other Point) bool {
return point == other
}
func (point Point) ContainsRect(rect Rect) bool {
return point.Rect() == rect
}
func (point Point) IntersectsRect(rect Rect) bool {
return rect.ContainsPoint(point)
}
func (point Point) ContainsLine(line *Line) bool {
if line == nil {
return false
}
return !line.Empty() && line.Rect() == point.Rect()
}
func (point Point) IntersectsLine(line *Line) bool {
if line == nil {
return false
}
return line.IntersectsPoint(point)
}
func (point Point) ContainsPoly(poly *Poly) bool {
if poly == nil {
return false
}
return !poly.Empty() && poly.Rect() == point.Rect()
}
func (point Point) IntersectsPoly(poly *Poly) bool {
if poly == nil {
return false
}
return poly.IntersectsPoint(point)
}