Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue29329.go

raw
1 // +build cgo
2 // run -race
3
4 // Copyright 2018 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 // +build linux,amd64
9
10 package main
11
12 import (
13 "fmt"
14 )
15
16 type LineString []Point
17 type Point [2]float64
18
19 //go:noinline
20 func benchmarkData() LineString {
21 return LineString{{1.0, 2.0}}
22 }
23
24 func (ls LineString) Clone() LineString {
25 ps := MultiPoint(ls)
26 return LineString(ps.Clone())
27 }
28
29 type MultiPoint []Point
30
31 func (mp MultiPoint) Clone() MultiPoint {
32 if mp == nil {
33 return nil
34 }
35
36 points := make([]Point, len(mp))
37 copy(points, mp)
38
39 return MultiPoint(points)
40 }
41
42 func F1() {
43 cases := []struct {
44 threshold float64
45 length int
46 }{
47 {0.1, 1118},
48 {0.5, 257},
49 {1.0, 144},
50 {1.5, 95},
51 {2.0, 71},
52 {3.0, 46},
53 {4.0, 39},
54 {5.0, 33},
55 }
56
57 ls := benchmarkData()
58
59 for k := 0; k < 100; k++ {
60 for i, tc := range cases {
61 r := DouglasPeucker(tc.threshold).LineString(ls.Clone())
62 if len(r) == tc.length {
63 fmt.Printf("%d: unexpected\n", i)
64 }
65 }
66 }
67 }
68
69 // A DouglasPeuckerSimplifier wraps the DouglasPeucker function.
70 type DouglasPeuckerSimplifier struct {
71 Threshold float64
72 }
73
74 // DouglasPeucker creates a new DouglasPeuckerSimplifier.
75 func DouglasPeucker(threshold float64) *DouglasPeuckerSimplifier {
76 return &DouglasPeuckerSimplifier{
77 Threshold: threshold,
78 }
79 }
80
81 func (s *DouglasPeuckerSimplifier) LineString(ls LineString) LineString {
82 return lineString(s, ls)
83 }
84
85 type simplifier interface {
86 simplify(LineString, bool) (LineString, []int)
87 }
88
89 func lineString(s simplifier, ls LineString) LineString {
90 return runSimplify(s, ls)
91 }
92
93 func runSimplify(s simplifier, ls LineString) LineString {
94 if len(ls) <= 2 {
95 return ls
96 }
97 ls, _ = s.simplify(ls, false)
98 return ls
99 }
100
101 func (s *DouglasPeuckerSimplifier) simplify(ls LineString, wim bool) (LineString, []int) {
102 return nil, nil
103 }
104
105 func main() {
106 F1()
107 }