dry it up a little

This commit is contained in:
onyx-and-iris 2024-12-13 23:24:05 +00:00
parent 401bd4201b
commit dcf3479d88

View File

@ -101,33 +101,31 @@ func isCorner(graph *graph, current, p, q point) bool {
func numInnerCorner(graph *graph, current point, ns [4]point) int {
var corners int
if !graph.isOutOfBounds(ns[N]) && !graph.isOutOfBounds(ns[E]) {
if graph.sameKind(ns[N], current) && graph.sameKind(ns[E], current) &&
!graph.sameKind(point{current.x + 1, current.y - 1}, current) {
corners++
}
if isInnerCorner(graph, current, ns[N], ns[E], point{current.x + 1, current.y - 1}) {
corners++
}
if !graph.isOutOfBounds(ns[N]) && !graph.isOutOfBounds(ns[W]) {
if graph.sameKind(ns[N], current) && graph.sameKind(ns[W], current) &&
!graph.sameKind(point{current.x - 1, current.y - 1}, current) {
corners++
}
if isInnerCorner(graph, current, ns[N], ns[W], point{current.x - 1, current.y - 1}) {
corners++
}
if !graph.isOutOfBounds(ns[S]) && !graph.isOutOfBounds(ns[E]) {
if graph.sameKind(ns[S], current) && graph.sameKind(ns[E], current) &&
!graph.sameKind(point{current.x + 1, current.y + 1}, current) {
corners++
}
if isInnerCorner(graph, current, ns[S], ns[E], point{current.x + 1, current.y + 1}) {
corners++
}
if !graph.isOutOfBounds(ns[S]) && !graph.isOutOfBounds(ns[W]) {
if graph.sameKind(ns[S], current) && graph.sameKind(ns[W], current) &&
!graph.sameKind(point{current.x - 1, current.y + 1}, current) {
corners++
}
if isInnerCorner(graph, current, ns[S], ns[W], point{current.x - 1, current.y + 1}) {
corners++
}
return corners
}
func isInnerCorner(graph *graph, current, p, q, diagonal point) bool {
if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) {
if graph.sameKind(p, current) && graph.sameKind(q, current) &&
!graph.sameKind(diagonal, current) {
return true
}
}
return false
}