adventofcode/2019/day20/square.go

29 lines
646 B
Go
Raw Permalink Normal View History

2020-11-03 21:09:13 +00:00
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)
}