upd methods

This commit is contained in:
2019-10-27 01:30:57 +03:00
parent b8c8a65fa7
commit 0da505b01b
3 changed files with 27 additions and 7 deletions

View File

@ -1,9 +1,32 @@
package types
import "math"
type Coords struct {
X, Y int
}
func (c *Coords) Get() (int,int) {
return c.X,c.Y
func (c *Coords) Get() (int, int) {
return c.X, c.Y
}
func (c *Coords) DistanceTo(o *Coords) float64 {
dx := c.X - o.X
dy := c.X - o.Y
return math.Sqrt(math.Pow(float64(dx), 2) + math.Pow(float64(dy), 2))
}
func (c *Coords) IsAdjacentTo(o *Coords) bool {
var xDiff, yDiff int
if c.X > o.X {
xDiff = c.X - o.X
} else {
xDiff = o.X - c.X
}
if c.Y > o. Y {
yDiff = c.Y - o.Y
} else {
yDiff = o.Y - c.Y
}
return xDiff < 2 && yDiff < 2
}