1package core
2
3import (
4 "github.com/bnema/neferwl/internal/ports"
5 "github.com/stretchr/testify/require"
6 "math"
7 "testing"
8)
9
10func TestHintLabelGeometry(t *testing.T) {
11 for _, scale := range []float64{1, 1.5} {
12 sc := &screen{scale: scale, info: ports.OutputInfo{Width: 1500, Height: 1200}}
13 sc.mon = newMonitor("", "")
14 sc.mon.SetOutput(int(float64(sc.info.Width)/sc.scale), int(float64(sc.info.Height)/sc.scale))
15 c := &Core{}
16 c.cfg.Hint.Size = 200
17 w, h := c.hintLabelSize(sc)
18 font := math.Min(200, 256/scale)
19 require.Equal(t, int(math.Ceil(1.2*font+6*font/13+2/scale+1)), w)
20 require.Equal(t, int(math.Ceil(1.25*font+2*font/13+2/scale+1)), h)
21 bounds := sc.rect()
22 // Corner separation exceeds label width, but right-edge clamping folds
23 // the second label back over the first.
24 a := hintTarget{rect: ports.Rect{X: bounds.W - w - 1, Y: bounds.H - h - 1}, score: 1}
25 b := hintTarget{rect: ports.Rect{X: bounds.W - 1, Y: bounds.H - 1}, score: .5}
26 require.Len(t, c.hintSpread(sc, []hintTarget{a, b}), 1)
27 b.rect = ports.Rect{X: 0, Y: 0}
28 require.Len(t, c.hintSpread(sc, []hintTarget{a, b}), 2)
29 }
30}
31
32func TestHintSpreadBudget(t *testing.T) {
33 sc := &screen{scale: 1, info: ports.OutputInfo{Width: 1000000, Height: 1000}}
34 sc.mon = newMonitor("", "")
35 sc.mon.SetOutput(int(float64(sc.info.Width)/sc.scale), int(float64(sc.info.Height)/sc.scale))
36 c := &Core{}
37 ts := make([]hintTarget, 4*hintMaxTargets+10)
38 for i := range ts {
39 ts[i] = hintTarget{rect: ports.Rect{X: 100 + i*100, Y: 100}, score: float32(i)}
40 }
41 got := c.hintSpread(sc, ts)
42 require.Len(t, got, 4*hintMaxTargets)
43 require.Equal(t, float32(len(ts)-1), got[0].score)
44 require.Equal(t, float32(10), got[len(got)-1].score)
45}