Files
galaxy-game/client/world/primitive.go
T
2026-03-07 17:01:22 +02:00

79 lines
2.2 KiB
Go

package world
import (
"github.com/google/uuid"
)
// MapItem is the common interface implemented by all world primitives.
type MapItem interface {
ID() uuid.UUID
}
// Point is a point primitive in fixed-point world coordinates.
type Point struct {
Id uuid.UUID
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
}
// Line is a line segment primitive in fixed-point world coordinates.
type Line struct {
Id uuid.UUID
X1, Y1 int
X2, Y2 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
}
// Circle is a circle primitive in fixed-point world coordinates.
type Circle struct {
Id uuid.UUID
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
}
// ID returns the point identifier.
func (p Point) ID() uuid.UUID { return p.Id }
// ID returns the line identifier.
func (l Line) ID() uuid.UUID { return l.Id }
// ID returns the circle identifier.
func (c Circle) ID() uuid.UUID { return c.Id }
// MinX returns the minimum X endpoint coordinate of the line.
func (l Line) MinX() int { return min(l.X1, l.X2) }
// MaxX returns the maximum X endpoint coordinate of the line.
func (l Line) MaxX() int { return max(l.X1, l.X2) }
// MinY returns the minimum Y endpoint coordinate of the line.
func (l Line) MinY() int { return min(l.Y1, l.Y2) }
// MaxY returns the maximum Y endpoint coordinate of the line.
func (l Line) MaxY() int { return max(l.Y1, l.Y2) }
// MinX returns the minimum X coordinate of the circle bbox.
func (c Circle) MinX() int { return c.X - c.Radius }
// MaxX returns the maximum X coordinate of the circle bbox.
func (c Circle) MaxX() int { return c.X + c.Radius }
// MinY returns the minimum Y coordinate of the circle bbox.
func (c Circle) MinY() int { return c.Y - c.Radius }
// MaxY returns the maximum Y coordinate of the circle bbox.
func (c Circle) MaxY() int { return c.Y + c.Radius }