1 Star 0 Fork 0

exlimit/tegola

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
douglaspeucker.go 647 Bytes
一键复制 编辑 原始数据 按行查看 历史
package maths
func DouglasPeucker(points []Pt, tolerence float64) []Pt {
if tolerence <= 0 || len(points) <= 2 {
return points
}
epsilon := tolerence * tolerence
// find the maximum distance from the end points.
l := Line{points[0], points[len(points)-1]}
dmax := 0.0
idx := 0
for i := 1; i < len(points)-2; i++ {
d := l.DistanceFromPoint(points[i])
if d > dmax {
dmax = d
idx = i
}
}
if dmax > epsilon {
rec1 := DouglasPeucker(points[0:idx], epsilon)
rec2 := DouglasPeucker(points[idx:len(points)-1], epsilon)
newpts := append(rec1, rec2...)
return newpts
}
return []Pt{points[0], points[len(points)-1]}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/exlimit/tegola.git
git@gitee.com:exlimit/tegola.git
exlimit
tegola
tegola
v0.4.0-alpha

搜索帮助