added bounds function and segline to intersect function

This commit is contained in:
Doc
2025-09-10 10:50:03 +02:00
parent e69e1967bb
commit 9e89ce4d95
2 changed files with 36 additions and 0 deletions

25
internal/geom/fit.go Normal file
View File

@@ -0,0 +1,25 @@
package geom
import "math"
type AABB struct{ Min, Max Vec }
func Bounds(pts []Vec) AABB {
minX, minY := math.Inf(1), math.Inf(1)
maxX, maxY := math.Inf(-1), math.Inf(-1)
for _, p := range pts {
if p.X < minX {
minX = p.X
}
if p.Y < minY {
minY = p.Y
}
if p.X > maxX {
maxX = p.X
}
if p.Y > maxY {
maxY = p.Y
}
}
return AABB{Min: V(minX, minY), Max: V(maxX, maxY)}
}

View File

@@ -0,0 +1,11 @@
package geom
func SegLineIntersect(A, B, O, D Vec) (bool, float64) {
r := Sub(B, A)
den := Cross(r, D)
if NearlyZero(den) {
return false, 0
}
t := Cross(Sub(O, A), D) / den
return t > EPS && t < 1-EPS, t
}