Skip to content

Commit

Permalink
Fix flex layout not loading in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg committed Oct 27, 2024
1 parent 6187244 commit be7970d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
8 changes: 4 additions & 4 deletions internal/image/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions internal/image/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions internal/layout/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/layout/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion internal/layout/highlights.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion internal/layout/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit be7970d

Please sign in to comment.