feat: hit on primitives

This commit is contained in:
IliaDenisov
2026-03-07 19:28:22 +02:00
parent e4b956232f
commit c076347d70
21 changed files with 1167 additions and 165 deletions
+15 -17
View File
@@ -3,8 +3,6 @@ package world
import (
"errors"
"testing"
"github.com/google/uuid"
)
func newIndexedTestWorld() *World {
@@ -13,7 +11,7 @@ func newIndexedTestWorld() *World {
return w
}
func cellHasOnlyID(t *testing.T, w *World, row, col int, want uuid.UUID) {
func cellHasOnlyID(t *testing.T, w *World, row, col int, want PrimitiveID) {
t.Helper()
cell := w.grid[row][col]
@@ -33,7 +31,7 @@ func cellIsEmpty(t *testing.T, w *World, row, col int) {
}
}
func occupiedCellsByID(w *World, id uuid.UUID) map[[2]int]struct{} {
func occupiedCellsByID(w *World, id PrimitiveID) map[[2]int]struct{} {
result := make(map[[2]int]struct{})
for row := range w.grid {
@@ -49,7 +47,7 @@ func occupiedCellsByID(w *World, id uuid.UUID) map[[2]int]struct{} {
return result
}
func assertOccupiedCells(t *testing.T, w *World, id uuid.UUID, want ...[2]int) {
func assertOccupiedCells(t *testing.T, w *World, id PrimitiveID, want ...[2]int) {
t.Helper()
got := occupiedCellsByID(w, id)
@@ -375,7 +373,7 @@ func TestIndexObjectPoint(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
p := Point{Id: id, X: 2500, Y: 4500}
w.indexObject(p)
@@ -389,7 +387,7 @@ func TestIndexObjectCircleWithoutWrap(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
c := Circle{Id: id, X: 3000, Y: 2000, Radius: 900}
w.indexObject(c)
@@ -404,7 +402,7 @@ func TestIndexObjectCircleWrapsAcrossCorner(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
c := Circle{Id: id, X: 500, Y: 500, Radius: 900}
w.indexObject(c)
@@ -421,7 +419,7 @@ func TestIndexObjectCircleCoversWholeWorld(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
c := Circle{Id: id, X: 5000, Y: 5000, Radius: 6000}
w.indexObject(c)
@@ -440,7 +438,7 @@ func TestIndexObjectVerticalLineExpandsDegenerateX(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
l := Line{Id: id, X1: 3000, Y1: 1000, X2: 3000, Y2: 5000}
w.indexObject(l)
@@ -456,7 +454,7 @@ func TestIndexObjectHorizontalLineExpandsDegenerateY(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
l := Line{Id: id, X1: 1000, Y1: 3000, X2: 5000, Y2: 3000}
w.indexObject(l)
@@ -472,7 +470,7 @@ func TestIndexObjectLineWrapsAcrossX(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
l := Line{Id: id, X1: 9000, Y1: 3000, X2: 1000, Y2: 3000}
w.indexObject(l)
@@ -487,7 +485,7 @@ func TestIndexObjectLineWrapsAcrossY(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
l := Line{Id: id, X1: 3000, Y1: 9000, X2: 3000, Y2: 1000}
w.indexObject(l)
@@ -502,7 +500,7 @@ func TestIndexObjectLineTieCaseUsesDeterministicWrap(t *testing.T) {
t.Parallel()
w := newIndexedTestWorld()
id := uuid.New()
id := PrimitiveID(1)
l := Line{Id: id, X1: 1000, Y1: 3000, X2: 6000, Y2: 3000}
w.indexObject(l)
@@ -515,10 +513,10 @@ func TestIndexObjectLineTieCaseUsesDeterministicWrap(t *testing.T) {
}
type unknown struct {
id uuid.UUID
id PrimitiveID
}
func (u unknown) ID() uuid.UUID {
func (u unknown) ID() PrimitiveID {
return u.id
}
@@ -533,5 +531,5 @@ func TestIndexBBoxPanicsOnUnknownItemType(t *testing.T) {
}
}()
w.indexObject(unknown{id: uuid.New()})
w.indexObject(unknown{id: PrimitiveID(1)})
}