MCPcopy Index your code
hub / github.com/fogleman/ln / Simplify

Method Simplify

ln/path.go:70–92  ·  view source on GitHub ↗
(threshold float64)

Source from the content-addressed store, hash-verified

68}
69
70func (p Path) Simplify(threshold float64) Path {
71 if len(p) < 3 {
72 return p
73 }
74 a := p[0]
75 b := p[len(p)-1]
76 index := -1
77 distance := 0.0
78 for i := 1; i < len(p)-1; i++ {
79 d := p[i].SegmentDistance(a, b)
80 if d > distance {
81 index = i
82 distance = d
83 }
84 }
85 if distance > threshold {
86 r1 := p[:index+1].Simplify(threshold)
87 r2 := p[index:].Simplify(threshold)
88 return append(r1[:len(r1)-1], r2...)
89 } else {
90 return Path{a, b}
91 }
92}
93
94func (p Path) Print() {
95 for _, v := range p {

Callers 2

SimplifyMethod · 0.45
RenderWithMatrixMethod · 0.45

Calls 1

SegmentDistanceMethod · 0.80

Tested by

no test coverage detected