Day 18 & Day 20 done
This commit is contained in:
28
2019/day20/square.go
Normal file
28
2019/day20/square.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user