summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/issue29329.go
blob: 7818bca30a02e657bf357c55fe0e3b74fd7ea3d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// +build cgo
// run -race

// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build linux,amd64

package main

import (
	"fmt"
)

type LineString []Point
type Point [2]float64

//go:noinline
func benchmarkData() LineString {
	return LineString{{1.0, 2.0}}
}

func (ls LineString) Clone() LineString {
	ps := MultiPoint(ls)
	return LineString(ps.Clone())
}

type MultiPoint []Point

func (mp MultiPoint) Clone() MultiPoint {
	if mp == nil {
		return nil
	}

	points := make([]Point, len(mp))
	copy(points, mp)

	return MultiPoint(points)
}

func F1() {
	cases := []struct {
		threshold float64
		length    int
	}{
		{0.1, 1118},
		{0.5, 257},
		{1.0, 144},
		{1.5, 95},
		{2.0, 71},
		{3.0, 46},
		{4.0, 39},
		{5.0, 33},
	}

	ls := benchmarkData()

	for k := 0; k < 100; k++ {
		for i, tc := range cases {
			r := DouglasPeucker(tc.threshold).LineString(ls.Clone())
			if len(r) == tc.length {
				fmt.Printf("%d: unexpected\n", i)
			}
		}
	}
}

// A DouglasPeuckerSimplifier wraps the DouglasPeucker function.
type DouglasPeuckerSimplifier struct {
	Threshold float64
}

// DouglasPeucker creates a new DouglasPeuckerSimplifier.
func DouglasPeucker(threshold float64) *DouglasPeuckerSimplifier {
	return &DouglasPeuckerSimplifier{
		Threshold: threshold,
	}
}

func (s *DouglasPeuckerSimplifier) LineString(ls LineString) LineString {
	return lineString(s, ls)
}

type simplifier interface {
	simplify(LineString, bool) (LineString, []int)
}

func lineString(s simplifier, ls LineString) LineString {
	return runSimplify(s, ls)
}

func runSimplify(s simplifier, ls LineString) LineString {
	if len(ls) <= 2 {
		return ls
	}
	ls, _ = s.simplify(ls, false)
	return ls
}

func (s *DouglasPeuckerSimplifier) simplify(ls LineString, wim bool) (LineString, []int) {
	return nil, nil
}

func main() {
	F1()
}