common

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ZeroRectangleF32 = Rectangle[float32]{}
	ZeroRectangleINT = Rectangle[int]{}
)

Zero values for reducing allocations

View Source
var (
	ZeroVector2F32 = Vector2[float32]{}
	ZeroVector2INT = Vector2[int]{}
)

Zero values for reducing allocations

View Source
var (
	ZeroColor = Color{}
)

Zero values for reducing allocations

Functions

func Abs

func Abs[T Numbers](v T) T

func Clamp

func Clamp[T Numbers](v, minv, maxv T) T

func Max

func Max[T Numbers](v1, v2 T) T

func Min

func Min[T Numbers](v1, v2 T) T

Types

type Animation

type Animation struct {
	// contains filtered or unexported fields
}

Animation used for calculating positions of animated objects (points)

func NewAnimation

func NewAnimation(from, to Vector2[float32], lifeTime float32) Animation

Lifetime is the life of the animation. Animation speed is depends of the delta time and lifetime. For lifeTime parameter, 1.0 value is 1 seconds

func (*Animation) IsFinished

func (anim *Animation) IsFinished() bool

func (*Animation) Step

func (anim *Animation) Step(delta float32) Vector2[float32]

Returns current position of animation

type BitMask

type BitMask uint32

This is just for making code more readable Can hold up to 32 enums

func (*BitMask) Clear

func (mask *BitMask) Clear()

func (*BitMask) Disable

func (mask *BitMask) Disable(flag BitMask)

func (*BitMask) Enable

func (mask *BitMask) Enable(flag BitMask)

func (*BitMask) EnableIf

func (mask *BitMask) EnableIf(flag BitMask, cond bool)

Enables flag if cond is true, disables otherwise.

func (BitMask) Has

func (mask BitMask) Has(flag BitMask) bool

func (BitMask) HasOnly

func (mask BitMask) HasOnly(flag BitMask) bool

Returns true if the mask only has the flag

func (BitMask) String

func (mask BitMask) String() string

func (*BitMask) Toggle

func (mask *BitMask) Toggle(flag BitMask)

type Color

type Color struct {
	R, G, B, A float32
}

func ColorFromUint

func ColorFromUint(color uint32) Color

func (Color) String

func (c Color) String() string

type Floats

type Floats interface {
	float32 | float64
}

type Integers

type Integers interface {
	int | int8 | int16 | int32 | int64
}

Constraints

type Numbers

type Numbers interface {
	Integers | UnsignedIntegers | Floats
}

type Rectangle

type Rectangle[T Numbers] struct {
	X, Y, W, H T
}

func Rect

func Rect[T Numbers](X, Y, W, H T) Rectangle[T]

Shortcut for creating a new rectangle

func (Rectangle[T]) Area

func (rect Rectangle[T]) Area() float32

func (Rectangle[T]) String

func (rect Rectangle[T]) String() string

func (Rectangle[T]) ToF32

func (rect Rectangle[T]) ToF32() Rectangle[float32]

func (Rectangle[T]) ToInt

func (rect Rectangle[T]) ToInt() Rectangle[int]

type UnsignedIntegers

type UnsignedIntegers interface {
	uint | uint8 | uint16 | uint32 | uint64
}

type Vector2

type Vector2[T Numbers] struct {
	X, Y T
}

func Vec2

func Vec2[T Numbers](X, Y T) Vector2[T]

just a shortcut

func (Vector2[T]) Add

func (v Vector2[T]) Add(v1 Vector2[T]) Vector2[T]

Add two vectors

func (Vector2[T]) Area

func (v Vector2[T]) Area() float32

func (Vector2[T]) Distance

func (v Vector2[T]) Distance(v2 Vector2[T]) float32

func (Vector2[T]) DistanceSquared

func (v Vector2[T]) DistanceSquared(v2 Vector2[T]) float32

Does not applies sqrt, faster

func (Vector2[T]) Div

func (v Vector2[T]) Div(v1 Vector2[T]) Vector2[T]

Divides v by v1

func (Vector2[T]) DivS

func (v Vector2[T]) DivS(S T) Vector2[T]

Divides the vector by a scalar

func (Vector2[T]) Equals

func (v Vector2[T]) Equals(v1 Vector2[T]) bool

Returns true if the vectors are equal

func (Vector2[T]) Height

func (v Vector2[T]) Height() T

func (Vector2[T]) IsHorizontal

func (v Vector2[T]) IsHorizontal() bool

Returns true if the vector is horizontal

func (Vector2[T]) IsInRect

func (v Vector2[T]) IsInRect(rect Rectangle[T]) bool

Returns true if the vector is in given rectangle

func (Vector2[T]) Length

func (v Vector2[T]) Length() float32

func (Vector2[T]) LengthSquared

func (v Vector2[T]) LengthSquared() float32

Does not applies sqrt, faster

func (Vector2[T]) Mul

func (v Vector2[T]) Mul(v1 Vector2[T]) Vector2[T]

Dot product of two vectors

func (Vector2[T]) MulS

func (v Vector2[T]) MulS(S T) Vector2[T]

Multiplies the vector by a scalar

func (Vector2[T]) Normalized

func (v Vector2[T]) Normalized() Vector2[T]

func (Vector2[T]) Perpendicular

func (v Vector2[T]) Perpendicular() Vector2[T]

Returns the perpenicular vector of v

func (Vector2[T]) String

func (v Vector2[T]) String() string

func (Vector2[T]) Sub

func (v Vector2[T]) Sub(v1 Vector2[T]) Vector2[T]

Subtract v1 from v

func (Vector2[T]) ToInt

func (v Vector2[T]) ToInt() Vector2[int]

func (Vector2[T]) Width

func (v Vector2[T]) Width() T

Jump to

Keyboard shortcuts

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