77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package aoc
|
|
|
|
import "fmt"
|
|
|
|
type Coordinate3d struct {
|
|
X, Y, Z int
|
|
}
|
|
|
|
func NewCoordinate3d(x, y, z int) *Coordinate3d {
|
|
return &Coordinate3d{x, y, z}
|
|
}
|
|
|
|
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}
|
|
}
|
|
|
|
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("[X:%d, Y:%d, Z:%d]", c.X, c.Y, c.Z)
|
|
}
|