Files
galaxy-game/client/world/renderer_points_wrap_test.go
T
2026-03-07 00:29:06 +03:00

100 lines
2.1 KiB
Go

package world
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPoints_WrapCopies_AppearInsideViewportWhenViewportEqualsWorld(t *testing.T) {
t.Parallel()
params := RenderParams{
ViewportWidthPx: 10,
ViewportHeightPx: 10,
MarginXPx: 0,
MarginYPx: 0,
CameraXWorldFp: 5 * SCALE,
CameraYWorldFp: 5 * SCALE,
CameraZoom: 1.0,
Options: &RenderOptions{
Style: func() *RenderStyle {
s := DefaultRenderStyle()
s.PointRadiusPx = 2.0 // so that a point at 9 "spills" by 1 and needs a copy at -1
return &s
}(),
},
}
type tc struct {
name string
x, y float64
wantCenters [][2]float64
}
tests := []tc{
{
name: "bottom boundary wraps to top",
x: 5,
y: 9,
wantCenters: [][2]float64{{5, 9}, {5, -1}},
},
{
name: "right boundary wraps to left",
x: 9,
y: 5,
wantCenters: [][2]float64{{9, 5}, {-1, 5}},
},
{
name: "corner wraps to three extra copies",
x: 9,
y: 9,
wantCenters: [][2]float64{{9, 9}, {9, -1}, {-1, 9}, {-1, -1}},
},
{
name: "no wrap inside",
x: 5,
y: 5,
wantCenters: [][2]float64{{5, 5}},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
w := NewWorld(10, 10)
w.resetGrid(2 * SCALE)
_, err := w.AddPoint(tt.x, tt.y)
require.NoError(t, err)
for _, obj := range w.objects {
w.indexObject(obj)
}
plan, err := w.buildRenderPlanStageA(params)
require.NoError(t, err)
d := &fakePrimitiveDrawer{}
style := DefaultRenderStyle()
style.PointRadiusPx = 2.0
applyPointStyle(d, style)
drawPointsFromPlanWithRadius(d, plan, w.W, w.H, style.PointRadiusPx)
cmds := d.CommandsByName("AddPoint")
require.Len(t, cmds, len(tt.wantCenters))
got := make([][2]float64, 0, len(cmds))
for _, c := range cmds {
require.Len(t, c.Args, 3)
got = append(got, [2]float64{c.Args[0], c.Args[1]})
}
require.ElementsMatch(t, tt.wantCenters, got)
})
}
}