MCPcopy
hub / github.com/fogleman/ln / SegmentDistance

Method SegmentDistance

ln/vector.go:111–124  ·  view source on GitHub ↗
(v Vector, w Vector)

Source from the content-addressed store, hash-verified

109}
110
111func (p Vector) SegmentDistance(v Vector, w Vector) float64 {
112 l2 := v.DistanceSquared(w)
113 if l2 == 0 {
114 return p.Distance(v)
115 }
116 t := p.Sub(v).Dot(w.Sub(v)) / l2
117 if t < 0 {
118 return p.Distance(v)
119 }
120 if t > 1 {
121 return p.Distance(w)
122 }
123 return v.Add(w.Sub(v).MulScalar(t)).Distance(p)
124}

Callers 1

SimplifyMethod · 0.80

Calls 6

DistanceMethod · 0.95
SubMethod · 0.95
DistanceSquaredMethod · 0.80
DotMethod · 0.80
MulScalarMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected