added side and split geom logic
This commit is contained in:
5
internal/geom/side.go
Normal file
5
internal/geom/side.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package geom
|
||||
|
||||
func Side(P, O, D Vec) float64 {
|
||||
return Cross(D, Sub(P, O))
|
||||
}
|
||||
29
internal/geom/split.go
Normal file
29
internal/geom/split.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package geom
|
||||
|
||||
func SplitSeg(s Seg, O, D Vec) (front, back []Seg) {
|
||||
sa := Side(s.A, O, D)
|
||||
sb := Side(s.B, O, D)
|
||||
|
||||
if sa >= -EPS && sb >= -EPS {
|
||||
return []Seg{s}, nil
|
||||
}
|
||||
if sa <= EPS && sb <= EPS {
|
||||
return nil, []Seg{s}
|
||||
}
|
||||
|
||||
ok, t := SegLineIntersect(s.A, s.B, O, D)
|
||||
if !ok {
|
||||
|
||||
if sa >= 0 {
|
||||
return []Seg{s}, nil
|
||||
}
|
||||
return nil, []Seg{s}
|
||||
}
|
||||
M := Vec{s.A.X + t*(s.B.X-s.A.X), s.A.Y + t*(s.B.Y-s.A.Y)}
|
||||
a := Seg{s.A, M}
|
||||
b := Seg{M, s.B}
|
||||
if sa > 0 {
|
||||
return []Seg{a}, []Seg{b}
|
||||
}
|
||||
return []Seg{b}, []Seg{a}
|
||||
}
|
||||
Reference in New Issue
Block a user