Skip to content

Commit

Permalink
Combine ForceCW/CCW benchmark tests for correct and incorrect orienta…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
DoctorLoki committed Feb 4, 2022
1 parent 1e159ab commit c4429b7
Showing 1 changed file with 16 additions and 43 deletions.
59 changes: 16 additions & 43 deletions geom/perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func BenchmarkMultiLineStringIsSimpleManyLineStrings(b *testing.B) {
}
}

func BenchmarkForceCWandForceCCWOrientedCorrectly(b *testing.B) {
func BenchmarkForceCWandForceCCW(b *testing.B) {
for i, tc := range []struct {
wkt string
geoType GeometryType
Expand All @@ -439,48 +439,21 @@ func BenchmarkForceCWandForceCCWOrientedCorrectly(b *testing.B) {
{"MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))", TypeMultiPolygon, false, true, "all CCW"},
{"GEOMETRYCOLLECTION(POLYGON((0 0,0 5,5 5,5 0,0 0)), MULTIPOLYGON(((40 40, 45 30, 20 45, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20))))", TypeGeometryCollection, true, false, "all CW"},
} {
b.Run(strconv.Itoa(i), func(b *testing.B) {
g := geomFromWKT(b, tc.wkt)

b.ResetTimer()
for i := 0; i < b.N; i++ {
if tc.isCW {
g.ForceCW()
} else if tc.isCCW {
g.ForceCCW()
}
}
})
}
}

func BenchmarkForceCWandForceCCWOrientedIncorrectly(b *testing.B) {
for i, tc := range []struct {
wkt string
geoType GeometryType
isCW bool
isCCW bool
note string
}{
{"POLYGON((0 0,0 5,5 5,5 0,0 0))", TypePolygon, true, false, "CW"},
{"POLYGON((1 1,3 1,2 2,2 4,1 1))", TypePolygon, false, true, "CCW"},
{"POLYGON((0 0,0 5,5 5,5 0,0 0), (1 1,3 1,2 2,2 4,1 1))", TypePolygon, true, false, "outer CW inner CCW"},
{"POLYGON((0 0,5 0,5 5,0 5,0 0), (1 1,1 2,2 2,2 1,1 1))", TypePolygon, false, true, "outer CCW inner CW"},
{"MULTIPOLYGON(((40 40, 45 30, 20 45, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))", TypeMultiPolygon, true, false, "all CW"},
{"MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))", TypeMultiPolygon, false, true, "all CCW"},
{"GEOMETRYCOLLECTION(POLYGON((0 0,0 5,5 5,5 0,0 0)), MULTIPOLYGON(((40 40, 45 30, 20 45, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20))))", TypeGeometryCollection, true, false, "all CW"},
} {
b.Run(strconv.Itoa(i), func(b *testing.B) {
g := geomFromWKT(b, tc.wkt)

b.ResetTimer()
for i := 0; i < b.N; i++ {
if tc.isCW {
g.ForceCCW()
} else if tc.isCCW {
g.ForceCW()
g := geomFromWKT(b, tc.wkt)
for _, correct := range map[string]bool{
"correct": true,
"incorrect": false,
} {
b.Run(strconv.Itoa(i), func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
if tc.isCW && correct || tc.isCCW && !correct {
g.ForceCW()
} else if tc.isCCW && correct || tc.isCW && !correct {
g.ForceCCW()
}
}
}
})
})
}
}
}

0 comments on commit c4429b7

Please sign in to comment.