diff --git a/internal/render/scene.go b/internal/render/scene.go index 90810b3..2cdab8f 100644 --- a/internal/render/scene.go +++ b/internal/render/scene.go @@ -25,6 +25,7 @@ type Render struct { DebugThumbnails bool Zoom int + CanvasRect Rect CanvasImage draw.Image } @@ -99,25 +100,13 @@ func (scene *Scene) Draw(config *Render, c *canvas.Context, scales Scales, sourc solid.Draw(c, scales) } - // for i := range scene.Photos { - // photo := &scene.Photos[i] - // photo.Draw(config, scene, c, scales, source) - // } - concurrent := 10 photoCount := len(scene.Photos) if photoCount < concurrent { concurrent = photoCount } - // startTime := time.Now() - - tileRect := Rect{X: 0, Y: 0, W: (float64)(config.TileSize), H: (float64)(config.TileSize)} - tileToCanvas := c.View().Inv() - tileCanvasRect := tileRect.Transform(tileToCanvas) - tileCanvasRect.Y = -tileCanvasRect.Y - tileCanvasRect.H - - visiblePhotos := scene.GetVisiblePhotos(tileCanvasRect, math.MaxInt32) + visiblePhotos := scene.GetVisiblePhotos(config.CanvasRect, math.MaxInt32) visiblePhotoCount := 0 wg := &sync.WaitGroup{} @@ -131,9 +120,6 @@ func (scene *Scene) Draw(config *Render, c *canvas.Context, scales Scales, sourc visiblePhotoCount += <-counts } - // micros := time.Since(startTime).Microseconds() - // log.Printf("scene draw %5d / %5d photos, %6d μs all, %.2f μs / photo\n", visiblePhotoCount, photoCount, micros, float64(micros)/float64(visiblePhotoCount)) - for i := range scene.Texts { text := &scene.Texts[i] text.Draw(config, c, scales) diff --git a/main.go b/main.go index 96c1aa0..73bb2eb 100644 --- a/main.go +++ b/main.go @@ -188,9 +188,25 @@ func drawTile(c *canvas.Context, r *render.Render, scene *render.Scene, zoom int if 1 < scene.Bounds.W/scene.Bounds.H { scale = tileSize / scene.Bounds.W tx += (scale*scene.Bounds.W - tileSize) * 0.5 + + // Explicit to avoid floating point precision issues + r.CanvasRect = render.Rect{ + X: float64(x) * scene.Bounds.W / float64(zoomPower), + Y: float64(y) * scene.Bounds.W / float64(zoomPower), + W: scene.Bounds.W / float64(zoomPower), + H: scene.Bounds.W / float64(zoomPower), + } } else { scale = tileSize / scene.Bounds.H ty += (scale*scene.Bounds.H - tileSize) * 0.5 + + // Explicit to avoid floating point precision issues + r.CanvasRect = render.Rect{ + X: float64(x) * scene.Bounds.H / float64(zoomPower), + Y: float64(y) * scene.Bounds.H / float64(zoomPower), + W: scene.Bounds.H / float64(zoomPower), + H: scene.Bounds.H / float64(zoomPower), + } } scale *= float64(zoomPower)