adventofcode/helpers/coordinate3d.go

58 lines
943 B
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) 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)
}