adventofcode/2019/day20/square.go

29 lines
646 B
Go

package main
import h "git.bullercodeworks.com/brian/adventofcode/helpers"
type Square struct {
Tl h.Coordinate3d
Br h.Coordinate3d
}
func (s *Square) Contains(p h.Coordinate3d) bool {
return p.X >= s.Tl.X && p.Y >= s.Tl.Y && p.X <= s.Br.X && p.Y <= s.Br.Y
}
func (s *Square) IsInBorder(p h.Coordinate3d) bool {
if !s.Contains(p) {
return false
}
if p.Y == s.Tl.Y || p.Y == s.Br.Y {
return p.X >= s.Tl.X || p.X <= s.Br.X
} else if p.X == s.Tl.X || p.X == s.Br.X {
return p.Y >= s.Tl.Y || p.Y <= s.Br.Y
}
return false
}
func (s *Square) ContainsButNotBorder(p h.Coordinate3d) bool {
return s.Contains(p) && !s.IsInBorder(p)
}