Skip to content

Commit

Permalink
Merge branch 'master' into #13-go-routines
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator committed Aug 4, 2020
2 parents 46f45ab + d524238 commit 549f78f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions data/2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ func PerpendicularDistance2(a, b, point MicroPoint) Micrometer {

// douglasPeucker accepts a list of points and epsilon as threshold, simplifies a path by dropping
// points that do not pass threshold values.
func douglasPeucker(points Path, ep Micrometer) Path {
if len(points) <= 2 {
func douglasPeucker(points Path, ep Micrometer, depth int) Path {
// check depth to avoid stack overflow on some models
// TODO: I currently know no other way to avoid a stack overflow (beside avoiding recursion, read todo below)
// For now it's ok...
if len(points) <= 2 || depth >= 200 {
return points
}

idx, maxDist := seekMostDistantPoint(points[0], points[len(points)-1], points)
if maxDist >= ep {
// TODO: check if implementation without recursion would be possible and if it is more performant
left := douglasPeucker(points[:idx+1], ep)
right := douglasPeucker(points[idx:], ep)
left := douglasPeucker(points[:idx+1], ep, depth+1)
right := douglasPeucker(points[idx:], ep, depth+1)
return append(left[:len(left)-1], right...)
}

Expand Down Expand Up @@ -69,7 +72,7 @@ func DouglasPeucker(points Path, epsilon Micrometer) Path {
// TODO: This value may need optimization
epsilon = 70
}
return douglasPeucker(points, epsilon)
return douglasPeucker(points, epsilon, 0)
}

func ToRadians(angle float64) float64 {
Expand Down

0 comments on commit 549f78f

Please sign in to comment.