MCPcopy
hub / github.com/tdewolff/canvas / BenchmarkToScanx

Function BenchmarkToScanx

path_test.go:994–1026  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

992}
993
994func BenchmarkToScanx(b *testing.B) {
995 res := DPMM(10.0)
996 data, err := os.ReadFile("resources/netherlands.path")
997 if err != nil {
998 panic(err)
999 }
1000 p, err := ParseSVGPath(string(data))
1001 if err != nil {
1002 panic(err)
1003 }
1004 bounds := p.FastBounds()
1005 p = p.Transform(Identity.Scale(1.0, -1.0).Translate(-bounds.X0, -bounds.Y1))
1006
1007 w, h := math.Ceil(float64(res)*bounds.W()), math.Ceil(float64(res)*bounds.H())
1008 img := image.NewRGBA(image.Rect(0, 0, int(w), int(h)))
1009 spanner := scanx.NewImgSpanner(img)
1010 scanner := scanx.NewScanner(spanner, int(w), int(h))
1011
1012 scanner.SetColor(image.Black)
1013 p.ToScanxScanner(scanner, h, res)
1014 scanner.Draw()
1015
1016 f, _ := os.Create("ToScanx.png")
1017 defer f.Close()
1018 (&png.Encoder{}).Encode(f, img)
1019
1020 b.ResetTimer()
1021 for i := 0; i < b.N; i++ {
1022 scanner.Clear()
1023 p.ToScanxScanner(scanner, h, res)
1024 scanner.Draw()
1025 }
1026}

Callers

nothing calls this directly

Calls 13

DPMMFunction · 0.85
ParseSVGPathFunction · 0.85
FastBoundsMethod · 0.80
WMethod · 0.80
HMethod · 0.80
SetColorMethod · 0.80
ToScanxScannerMethod · 0.80
TransformMethod · 0.65
DrawMethod · 0.65
EncodeMethod · 0.65
TranslateMethod · 0.45
ScaleMethod · 0.45

Tested by

no test coverage detected