70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package world
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTorusShortestLineSegments_TieCaseIsDeterministicAndSplits(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// World 10 units => 10000 fixed.
|
|
worldW := 10 * SCALE
|
|
worldH := 10 * SCALE
|
|
|
|
// Tie-case along X: 1 -> 6 is exactly half world apart (dx = +5000).
|
|
// Deterministic rule chooses negative delta representation (wrap is applied).
|
|
l := Line{
|
|
X1: 1 * SCALE, Y1: 5 * SCALE,
|
|
X2: 6 * SCALE, Y2: 5 * SCALE,
|
|
}
|
|
|
|
segs := torusShortestLineSegments(l, worldW, worldH)
|
|
|
|
// Expect two horizontal segments:
|
|
// [6000..10000] and [0..1000] at y=5000.
|
|
require.Len(t, segs, 2)
|
|
|
|
// Direction is deterministic and follows the chosen negative-delta representation.
|
|
require.Equal(t, lineSeg{x1: 1000, y1: 5000, x2: 0, y2: 5000}, segs[0])
|
|
require.Equal(t, lineSeg{x1: 10000, y1: 5000, x2: 6000, y2: 5000}, segs[1])
|
|
}
|
|
|
|
func TestLines_NoWrap_TieCaseDoesNotWrap(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
w := NewWorld(10, 10)
|
|
w.resetGrid(2 * SCALE)
|
|
|
|
// Tie-case along X: 1 -> 6 in world of 10.
|
|
_, err := w.AddLine(1, 5, 6, 5)
|
|
require.NoError(t, err)
|
|
for _, obj := range w.objects {
|
|
w.indexObject(obj)
|
|
}
|
|
|
|
params := RenderParams{
|
|
ViewportWidthPx: 10,
|
|
ViewportHeightPx: 10,
|
|
MarginXPx: 0,
|
|
MarginYPx: 0,
|
|
CameraXWorldFp: 5 * SCALE,
|
|
CameraYWorldFp: 5 * SCALE,
|
|
CameraZoom: 1.0,
|
|
Options: &RenderOptions{
|
|
DisableWrapScroll: true,
|
|
Layers: []RenderLayer{RenderLayerLines},
|
|
},
|
|
}
|
|
|
|
d := &fakePrimitiveDrawer{}
|
|
require.NoError(t, w.Render(d, params))
|
|
|
|
lines := d.CommandsByName("AddLine")
|
|
require.Len(t, lines, 1)
|
|
|
|
// At zoom=1 and margin=0, world==canvas, so pixels equal world units.
|
|
require.Equal(t, []float64{1, 5, 6, 5}, lines[0].Args)
|
|
}
|