internal/atlas: add a benchmark for adjustDestinationPixel

This commit is contained in:
Hajime Hoshi 2022-09-15 01:25:26 +09:00
parent 2cbc5e7b60
commit 9319266c01
3 changed files with 14 additions and 3 deletions

View File

@ -59,6 +59,5 @@ func (i *Image) EnsureIsolatedForTesting() {
i.ensureIsolated()
}
func ResolveDeferredForTesting() {
resolveDeferred()
}
var ResolveDeferredForTesting = resolveDeferred
var AdjustDestinationPixelForTesting = adjustDestinationPixel

View File

@ -799,6 +799,12 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
func adjustDestinationPixel(x float32) float32 {
// Avoid the center of the pixel, which is problematic (#929, #1171).
// Instead, align the vertices with about 1/3 pixels.
//
// The intention here is roughly this code:
//
// float32(math.Floor((float64(x)+1.0/6.0)*3) / 3)
//
// The actual implementation is more optimized than the above implementation.
ix := float32(math.Floor(float64(x)))
frac := x - ix
switch {

View File

@ -737,4 +737,10 @@ func TestImageWritePixelsModify(t *testing.T) {
}
}
func BenchmarkAdjustPixel(b *testing.B) {
for i := 0; i < b.N; i++ {
atlas.AdjustDestinationPixelForTesting(float32(i) / 17)
}
}
// TODO: Add tests to extend image on an atlas out of the main loop