aoc2023/day-18/imager.go
2023-12-22 21:57:00 +00:00

38 lines
654 B
Go

package main
type coords struct {
X int
Y int
}
func newCoords(x, y int) coords {
return coords{X: x, Y: y}
}
type imager struct {
point coords
space []coords
}
// newImager returns an imager type
func newImager() *imager {
return &imager{point: newCoords(0, 0), space: make([]coords, 0)}
}
// add appends new coordinates to all points that describe the polygon
func (i *imager) add(direction string, count int) {
for j := 0; j < count; j++ {
switch direction {
case "U":
i.point.Y--
case "D":
i.point.Y++
case "L":
i.point.X--
case "R":
i.point.X++
}
i.space = append(i.space, newCoords(i.point.X, i.point.Y))
}
}