(threshold float64)
| 68 | } |
| 69 | |
| 70 | func (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 | |
| 94 | func (p Path) Print() { |
| 95 | for _, v := range p { |
no test coverage detected