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
+23 -11
View File
@@ -1,28 +1,32 @@
package world
import (
"github.com/google/uuid"
)
// PrimitiveID is a compact stable identifier for primitives stored in the World.
// It is allocated by the World and may be reused after deletion (free-list).
type PrimitiveID uint32
// MapItem is the common interface implemented by all world primitives.
type MapItem interface {
ID() uuid.UUID
ID() PrimitiveID
}
// Point is a point primitive in fixed-point world coordinates.
type Point struct {
Id uuid.UUID
Id PrimitiveID
X, Y int
// Priority controls per-object draw ordering. Smaller draws earlier.
Priority int
// StyleID references a resolved style in the world's style table.
StyleID StyleID
// HitSlopPx expands hit-test radius in screen pixels (per-object override).
// 0 means "use primitive default".
HitSlopPx int
}
// Line is a line segment primitive in fixed-point world coordinates.
type Line struct {
Id uuid.UUID
Id PrimitiveID
X1, Y1 int
X2, Y2 int
@@ -30,28 +34,36 @@ type Line struct {
Priority int
// StyleID references a resolved style in the world's style table.
StyleID StyleID
// HitSlopPx expands hit-test radius in screen pixels (per-object override).
// 0 means "use primitive default".
HitSlopPx int
}
// Circle is a circle primitive in fixed-point world coordinates.
type Circle struct {
Id uuid.UUID
Id PrimitiveID
X, Y int
Radius int
// Priority controls per-object draw ordering. Smaller draws earlier.
Priority int
// StyleID references a resolved style in the world's style table.
StyleID StyleID
// HitSlopPx expands hit-test radius in screen pixels (per-object override).
// 0 means "use primitive default".
HitSlopPx int
}
// ID returns the point identifier.
func (p Point) ID() uuid.UUID { return p.Id }
func (p Point) ID() PrimitiveID { return p.Id }
// ID returns the line identifier.
func (l Line) ID() uuid.UUID { return l.Id }
func (l Line) ID() PrimitiveID { return l.Id }
// ID returns the circle identifier.
func (c Circle) ID() uuid.UUID { return c.Id }
func (c Circle) ID() PrimitiveID { return c.Id }
// MinX returns the minimum X endpoint coordinate of the line.
func (l Line) MinX() int { return min(l.X1, l.X2) }