-
Notifications
You must be signed in to change notification settings - Fork 4
/
point.go
42 lines (35 loc) · 834 Bytes
/
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
package main
import (
"fmt"
"math"
)
type Point struct {
X, Y int
}
func (p Point) String() string {
return fmt.Sprintf("%d,%d", p.X, p.Y)
}
func (p Point) Equal(p2 Point) bool {
return p.X == p2.X && p.Y == p2.Y
}
// TranslateToDirection move point by using defined distance and direction
func (p Point) TranslateToDirection(distance int, direction Direction) Point {
dir := float64(direction.Degree) * math.Pi / 180
return Point{
X: p.X + distance*int(math.Round(math.Cos(dir))),
Y: p.Y + distance*int(math.Round(math.Sin(dir))),
}
}
// Translate moves p in x and y axis
func (p Point) Translate(x, y int) Point {
return Point{X: p.X + x, Y: p.Y + y}
}
func (p Point) IsInArena(a Arena) bool {
if p.X > a.Width-1 || p.X < 0 {
return false
}
if p.Y > a.Height-1 || p.Y < 0 {
return false
}
return true
}