Advent-of-Code/year25/day9/utils.go
2025-12-24 22:25:20 +02:00

18 lines
567 B
Go

package day9
import "git.bizdoc.ro/private/devkit.git/collections/geometry/v2"
func ccw(A, B, C geometry.Point) bool {
return (C.Line-A.Line)*(B.Col-A.Col) > (B.Line-A.Line)*(C.Col-A.Col)
}
// https://stackoverflow.com/questions/3838329/how-can-i-check-if-two-segments-intersect
// intersect Return true if line segments AB and CD intersect
func intersect(A, B, C, D geometry.Point) bool {
return ccw(A, C, D) != ccw(B, C, D) && ccw(A, B, C) != ccw(A, B, D)
}
func verticesIntersect(v1, v2 Vertex) bool {
return intersect(v1.Start, v1.End, v2.Start, v2.End)
}