From be7970d94e917a62763aff8482c96bb85e66f57d Mon Sep 17 00:00:00 2001 From: Miha Lunar Date: Sun, 27 Oct 2024 13:45:27 +0100 Subject: [PATCH] Fix flex layout not loading in some cases --- internal/image/info.go | 8 ++++---- internal/image/source.go | 14 ++------------ internal/layout/common.go | 3 +-- internal/layout/flex.go | 2 +- internal/layout/highlights.go | 2 +- internal/layout/search.go | 2 +- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/internal/image/info.go b/internal/image/info.go index d353920..ae38e02 100644 --- a/internal/image/info.go +++ b/internal/image/info.go @@ -39,11 +39,11 @@ func AngleToKm(a s1.Angle) float64 { return a.Radians() * earthRadiusKm } -func (info *Info) MakeValid() { - if info.Width == 0 || info.Height == 0 { - info.Width = 3 - info.Height = 2 +func (info *Info) AspectRatio() float64 { + if info.Height == 0 { + return 3 / 2 } + return float64(info.Width) / float64(info.Height) } func (info *Info) Size() Size { diff --git a/internal/image/source.go b/internal/image/source.go index 3aae063..2b2e3c9 100644 --- a/internal/image/source.go +++ b/internal/image/source.go @@ -376,18 +376,8 @@ func (source *Source) ListInfos(dirs []string, options ListOptions) (<-chan Sour } func (source *Source) ListInfosEmb(dirs []string, options ListOptions) <-chan InfoEmb { - out := make(chan InfoEmb, 1000) - go func() { - defer metrics.Elapsed("list infos embedded")() - - infos := source.database.ListWithEmbeddings(dirs, options) - for info := range infos { - info.SourcedInfo.Info.MakeValid() - out <- info - } - close(out) - }() - return out + defer metrics.Elapsed("list infos embedded")() + return source.database.ListWithEmbeddings(dirs, options) } // Prefer using ImageId over this unless you absolutely need the path diff --git a/internal/layout/common.go b/internal/layout/common.go index 6ab121a..1d39a42 100644 --- a/internal/layout/common.go +++ b/internal/layout/common.go @@ -317,8 +317,7 @@ func addSectionToScene(section *Section, scene *render.Scene, bounds render.Rect Id: info.Id, } - aspectRatio := float64(info.Width) / float64(info.Height) - imageWidth := float64(config.ImageHeight) * aspectRatio + imageWidth := float64(config.ImageHeight) * info.AspectRatio() if x+imageWidth > bounds.W { scale := layoutFitRow(scene.Photos[rowIdx:], bounds, config.ImageSpacing) diff --git a/internal/layout/flex.go b/internal/layout/flex.go index efe2757..c11a27b 100644 --- a/internal/layout/flex.go +++ b/internal/layout/flex.go @@ -104,7 +104,7 @@ func LayoutFlex(infos <-chan image.SourcedInfo, layout Layout, scene *render.Sce } photo := dag.Photo{ Id: info.Id, - AspectRatio: float32(info.Width) / float32(info.Height), + AspectRatio: float32(info.AspectRatio()), } photos = append(photos, photo) layoutCounter.Set(len(photos)) diff --git a/internal/layout/highlights.go b/internal/layout/highlights.go index f957d77..e6c421a 100644 --- a/internal/layout/highlights.go +++ b/internal/layout/highlights.go @@ -136,7 +136,7 @@ func LayoutHighlights(infos <-chan image.InfoEmb, layout Layout, scene *render.S photo := HighlightPhoto{ Photo: dag.Photo{ Id: info.Id, - AspectRatio: float32(info.Width) / float32(info.Height), + AspectRatio: float32(info.AspectRatio()), }, Height: float32(simHeight), } diff --git a/internal/layout/search.go b/internal/layout/search.go index 8f104eb..80ff5a3 100644 --- a/internal/layout/search.go +++ b/internal/layout/search.go @@ -53,7 +53,7 @@ func LayoutSearch(infos <-chan image.SimilarityInfo, layout Layout, scene *rende mostSimilar = info.Similarity } - aspectRatio := float64(info.Width) / float64(info.Height) + aspectRatio := info.AspectRatio() imageWidth := float64(imageHeight) * aspectRatio if rect.X+imageWidth > rect.W {