spatial

package
v0.0.0-...-fdcb90e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: GPL-3.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNegativeDirection

func IsNegativeDirection(dir Direction) bool

func IsPositiveDirection

func IsPositiveDirection(dir Direction) bool

Types

type Direction

type Direction int
const (
	NullDirection     Direction = 0
	PositiveDirection Direction = 1
	NegativeDirection Direction = 2
)

func (Direction) String

func (d Direction) String() string

type Distance

type Distance float64

Distance represents a distance in meters. This is the base unit for all spatial measurements in the simulation.

const (
	Millimeter Distance = 0.001
	Meter      Distance = 1.0
	Kilometer  Distance = 1000.0
)

Distance unit constants for multiplication.

Usage:

d := 5 * spatial.Kilometer           // 5000 m
d := 1500 * spatial.Millimeter       // 1.5 m
d := spatial.Distance(123.456)       // 123.456 m
const DistanceEpsilon Distance = 0.5

DistanceEpsilon is the tolerance for PK comparison (50cm). PK values are expected to be 1 meter precise, so 0.5m tolerance handles rounding.

func Max

func Max(a, b Distance) Distance

Max returns the larger of two distances.

func Min

func Min(a, b Distance) Distance

Min returns the smaller of two distances.

func ParsePK

func ParsePK(pkStr string) (Distance, error)

ParsePK parses a PK (point kilométrique) string in the format "XXX+YYY" or "XXX-YYY" where XXX is kilometers and YYY is meters. - "123+456" means 123 km + 456 m = 123456 m - "123-456" means 123 km - 456 m = 122544 m

func (Distance) Abs

func (d Distance) Abs() Distance

Abs returns the absolute value of the distance.

func (Distance) Clamp

func (d Distance) Clamp(min, max Distance) Distance

Clamp returns d clamped to the range [min, max].

func (Distance) Equal

func (d Distance) Equal(other Distance) bool

Equal returns true if the two distances are within DistanceEpsilon of each other. Use this instead of == for PK comparisons.

func (Distance) Greater

func (d Distance) Greater(other Distance) bool

Greater returns true if d is strictly greater than other (with epsilon tolerance). Returns true if d > other + DistanceEpsilon.

func (Distance) GreaterOrEqual

func (d Distance) GreaterOrEqual(other Distance) bool

GreaterOrEqual returns true if d is greater than or approximately equal to other. Returns true if d > other - DistanceEpsilon.

func (Distance) Kilometers

func (d Distance) Kilometers() float64

Kilometers returns the distance in kilometers.

func (Distance) Less

func (d Distance) Less(other Distance) bool

Less returns true if d is strictly less than other (with epsilon tolerance). Returns true if d < other - DistanceEpsilon.

func (Distance) LessOrEqual

func (d Distance) LessOrEqual(other Distance) bool

LessOrEqual returns true if d is less than or approximately equal to other. Returns true if d < other + DistanceEpsilon.

func (Distance) Meters

func (d Distance) Meters() float64

Meters returns the distance in meters (the base unit).

func (Distance) Millimeters

func (d Distance) Millimeters() float64

Millimeters returns the distance in millimeters.

func (Distance) String

func (d Distance) String() string

String returns a human-readable representation of the distance. Distances >= 1km are shown in kilometers, otherwise in meters.

type Speed

type Speed float64

Speed represents a speed in meters per second. This is the base unit for all velocity measurements in the simulation.

const (
	MeterPerSecond   Speed = 1.0
	KilometerPerHour Speed = 1.0 / 3.6 // ≈0.2778 m/s
)

Speed unit constants for multiplication.

Usage:

s := 120 * spatial.KilometerPerHour  // 120 km/h ≈ 33.33 m/s
s := 30 * spatial.MeterPerSecond     // 30 m/s
s := spatial.SpeedFromKmh(300)       // 300 km/h

func DistancePerDuration

func DistancePerDuration(d Distance, t time.Duration) Speed

DistancePerDuration calculates the speed from a distance and duration.

func MaxSpeed

func MaxSpeed(a, b Speed) Speed

MaxSpeed returns the larger of two speeds.

func MinSpeed

func MinSpeed(a, b Speed) Speed

MinSpeed returns the smaller of two speeds.

func SpeedFromKmh

func SpeedFromKmh(kmh float64) Speed

SpeedFromKmh creates a Speed from kilometers per hour.

func SpeedFromMps

func SpeedFromMps(mps float64) Speed

SpeedFromMps creates a Speed from meters per second. This is an identity function provided for clarity.

func (Speed) Abs

func (s Speed) Abs() Speed

Abs returns the absolute value of the speed.

func (Speed) Clamp

func (s Speed) Clamp(min, max Speed) Speed

Clamp returns s clamped to the range [min, max].

func (Speed) DistanceIn

func (s Speed) DistanceIn(d time.Duration) Distance

DistanceIn returns the distance traveled at this speed over the given duration.

func (Speed) Kmh

func (s Speed) Kmh() float64

Kmh returns the speed in kilometers per hour.

func (Speed) Mps

func (s Speed) Mps() float64

Mps returns the speed in meters per second (the base unit).

func (Speed) String

func (s Speed) String() string

String returns a human-readable representation of the speed in km/h.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL