2020-11-03 11:02:36 +00:00
|
|
|
package aoc
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type Coordinate3d struct {
|
|
|
|
X, Y, Z int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCoordinate3d(x, y, z int) *Coordinate3d {
|
|
|
|
return &Coordinate3d{x, y, z}
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:56:23 +00:00
|
|
|
func (c Coordinate3d) North() Coordinate3d {
|
|
|
|
return Coordinate3d{X: c.X, Y: c.Y - 1, Z: c.Z}
|
|
|
|
}
|
|
|
|
func (c Coordinate3d) East() Coordinate3d {
|
|
|
|
return Coordinate3d{X: c.X + 1, Y: c.Y, Z: c.Z}
|
|
|
|
}
|
|
|
|
func (c Coordinate3d) South() Coordinate3d {
|
|
|
|
return Coordinate3d{X: c.X, Y: c.Y + 1, Z: c.Z}
|
|
|
|
}
|
|
|
|
func (c Coordinate3d) West() Coordinate3d {
|
|
|
|
return Coordinate3d{X: c.X - 1, Y: c.Y, Z: c.Z}
|
|
|
|
}
|
|
|
|
func (c Coordinate3d) Up() Coordinate3d {
|
|
|
|
return Coordinate3d{X: c.X, Y: c.Y, Z: c.Z + 1}
|
|
|
|
}
|
|
|
|
func (c Coordinate3d) Down() Coordinate3d {
|
|
|
|
return Coordinate3d{X: c.X, Y: c.Y, Z: c.Z - 1}
|
|
|
|
}
|
|
|
|
|
2020-11-03 11:02:36 +00:00
|
|
|
func (c *Coordinate3d) GetNorthCoord() *Coordinate3d {
|
|
|
|
return &Coordinate3d{
|
|
|
|
X: c.X,
|
|
|
|
Y: c.Y - 1,
|
|
|
|
Z: c.Z,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Coordinate3d) GetEastCoord() *Coordinate3d {
|
|
|
|
return &Coordinate3d{
|
|
|
|
X: c.X + 1,
|
|
|
|
Y: c.Y,
|
|
|
|
Z: c.Z,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Coordinate3d) GetSouthCoord() *Coordinate3d {
|
|
|
|
return &Coordinate3d{
|
|
|
|
X: c.X,
|
|
|
|
Y: c.Y + 1,
|
|
|
|
Z: c.Z,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Coordinate3d) GetWestCoord() *Coordinate3d {
|
|
|
|
return &Coordinate3d{
|
|
|
|
X: c.X - 1,
|
|
|
|
Y: c.Y,
|
|
|
|
Z: c.Z,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Coordinate3d) GetUpCoord() *Coordinate3d {
|
|
|
|
return &Coordinate3d{
|
|
|
|
X: c.X,
|
|
|
|
Y: c.Y,
|
|
|
|
Z: c.Z + 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Coordinate3d) GetDownCoord() *Coordinate3d {
|
|
|
|
return &Coordinate3d{
|
|
|
|
X: c.X,
|
|
|
|
Y: c.Y,
|
|
|
|
Z: c.Z - 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c Coordinate3d) String() string {
|
|
|
|
return fmt.Sprintf("[%d, %d, %d]", c.X, c.Y, c.Z)
|
|
|
|
}
|