vec2

package
v0.0.0-...-04a3da0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntersectsInfiniteLineCircle

func IntersectsInfiniteLineCircle(A, B, center F, radius float32) bool

IntersectsInfiniteLineCircle returns true if an infinite line segment A-B intersects circle with given center and radius Based on https://mathworld.wolfram.com/Circle-LineIntersection.html

func IntersectsLineCircleInclusive

func IntersectsLineCircleInclusive(A, B, center F, radius float32) bool

func IntersectsLineExclusive

func IntersectsLineExclusive(A, B, C, D F) bool

IntersectsLineExclusive returns true if line segments A-B and C-D intersect (excluding endpoints)

Types

type D

type D struct {
	X, Y float64
}

func ClosestPointOnLineD

func ClosestPointOnLineD(a, b, target D) (closest D)

ClosestPointOnLineD returns the point on the infinite line a-b closest to target

func ClosestPointOnLineSegmentD

func ClosestPointOnLineSegmentD(a, b, target D) (closest D, t float64)

ClosestPointOnLineSegmentD returns the point on the line a-b closest to target. t is the ratio between a and b of that point

func NewPolarD

func NewPolarD(angle, radius float64) D

func NewPolarDFast

func NewPolarDFast(angle, radius float64) D

func NewRandomD

func NewRandomD(minValue, maxValue float64) D

func (D) Abs

func (v D) Abs() D

func (D) Add

func (v D) Add(other D) D

func (D) AddScalar

func (v D) AddScalar(scalar float64) D

func (D) AddScalars

func (v D) AddScalars(x, y float64) D

func (D) Angle

func (v D) Angle() float64

func (D) AngleBetweenLines

func (v D) AngleBetweenLines(v2 D) float64

AngleBetweenLines calculates the angle between two lines starting at origo returns values in the range [-Pi, Pi].

func (D) AngleTo

func (v D) AngleTo(v2 D) float64

AngleTo returns the angle of the line v->v2

func (D) AsFloat

func (v D) AsFloat() F

func (D) AsInt

func (v D) AsInt() I

func (D) Ceil

func (v D) Ceil() D

func (D) Clamp

func (v D) Clamp(low, high D) D

func (D) Components

func (v D) Components() (x, y float64)

func (D) Cross

func (v D) Cross(other D) float64

func (D) DistanceTo

func (v D) DistanceTo(v2 D) float64

func (D) DistanceToLine

func (v D) DistanceToLine(a, b D) float64

func (D) DistanceToSquared

func (v D) DistanceToSquared(v2 D) float64

func (D) Div

func (v D) Div(other D) D

func (D) DivScalar

func (v D) DivScalar(scalar float64) D

func (D) DivScalars

func (v D) DivScalars(x, y float64) D

func (D) Dot

func (v D) Dot(other D) float64

func (D) Equals

func (v D) Equals(other D) bool

func (D) Floor

func (v D) Floor() D

func (D) IsBetweenInclusive

func (v D) IsBetweenInclusive(left, right D) bool

func (D) IsZero

func (v D) IsZero() bool

func (D) Magnitude

func (v D) Magnitude() float64

func (D) MarshalJSON

func (v D) MarshalJSON() ([]byte, error)

func (D) Max

func (v D) Max(v2 D) D

func (D) Min

func (v D) Min(v2 D) D

func (D) Mul

func (v D) Mul(other D) D

func (D) MulScalar

func (v D) MulScalar(scalar float64) D

func (D) MulScalars

func (v D) MulScalars(x, y float64) D

func (D) NegatedY

func (v D) NegatedY() D

func (D) Normalized

func (v D) Normalized() D

func (D) Perpendicular

func (v D) Perpendicular() D

func (D) Reflect

func (v D) Reflect(other D) D

func (D) Rotate

func (v D) Rotate(angle float64) D

func (D) Round

func (v D) Round() D

func (D) SideOfLine

func (v D) SideOfLine(a, b D) float64

SideOfLine calculates which side of the line A->B the point P lies on. Check the sign of the response.

func (D) String

func (v D) String() string

func (D) Sub

func (v D) Sub(other D) D

func (D) SubScalar

func (v D) SubScalar(scalar float64) D

func (D) SubScalars

func (v D) SubScalars(x, y float64) D

func (D) Swap

func (v D) Swap() D

func (*D) UnmarshalJSON

func (v *D) UnmarshalJSON(data []byte) error

func (D) WithX

func (v D) WithX(value float64) D

func (D) WithY

func (v D) WithY(value float64) D

type F

type F struct {
	X, Y float32
}

func ClosestPointOnLineF

func ClosestPointOnLineF(a, b, target F) (closest F)

ClosestPointOnLineF returns the point on the infinite line a-b closest to target

func ClosestPointOnLineSegmentF

func ClosestPointOnLineSegmentF(a, b, target F) (closest F, t float32)

ClosestPointOnLineSegmentF returns the point on the line a-b closest to target. t is the ratio between a and b of that point

func LineIntersection

func LineIntersection(A, B, C, D F) F

LineIntersection calculates the (extended) intersection between lines A-B and C-D

func NewPolarF

func NewPolarF(angle, radius float32) F

func NewPolarFFast

func NewPolarFFast(angle, radius float32) F

func NewRandomF

func NewRandomF(minValue, maxValue float32) F

func (F) Abs

func (v F) Abs() F

func (F) Add

func (v F) Add(other F) F

func (F) AddScalar

func (v F) AddScalar(scalar float32) F

func (F) AddScalars

func (v F) AddScalars(x, y float32) F

func (F) Angle

func (v F) Angle() float32

func (F) AngleBetweenLines

func (v F) AngleBetweenLines(v2 F) float32

AngleBetweenLines calculates the angle between two lines starting at origo returns values in the range [-Pi, Pi].

func (F) AngleTo

func (v F) AngleTo(v2 F) float32

AngleTo returns the angle of the line v->v2

func (F) AsDouble

func (v F) AsDouble() D

func (F) AsInt

func (v F) AsInt() I

func (F) Ceil

func (v F) Ceil() F

func (F) Clamp

func (v F) Clamp(low, high F) F

func (F) Components

func (v F) Components() (x, y float32)

func (F) Cross

func (v F) Cross(other F) float32

func (F) DistanceTo

func (v F) DistanceTo(v2 F) float32

func (F) DistanceToLine

func (v F) DistanceToLine(a, b F) float32

func (F) DistanceToSquared

func (v F) DistanceToSquared(v2 F) float32

func (F) Div

func (v F) Div(other F) F

func (F) DivScalar

func (v F) DivScalar(scalar float32) F

func (F) DivScalars

func (v F) DivScalars(x, y float32) F

func (F) Dot

func (v F) Dot(other F) float32

func (F) Equals

func (v F) Equals(other F) bool

func (F) Floor

func (v F) Floor() F

func (F) IsBetweenInclusive

func (v F) IsBetweenInclusive(left, right F) bool

func (F) IsZero

func (v F) IsZero() bool

func (F) Magnitude

func (v F) Magnitude() float32

func (F) MarshalJSON

func (v F) MarshalJSON() ([]byte, error)

func (F) Max

func (v F) Max(v2 F) F

func (F) Min

func (v F) Min(v2 F) F

func (F) Mul

func (v F) Mul(other F) F

func (F) MulScalar

func (v F) MulScalar(scalar float32) F

func (F) MulScalars

func (v F) MulScalars(x, y float32) F

func (F) NegatedY

func (v F) NegatedY() F

func (F) Normalized

func (v F) Normalized() F

func (F) Perpendicular

func (v F) Perpendicular() F

func (F) Reflect

func (v F) Reflect(other F) F

func (F) Rotate

func (v F) Rotate(angle float32) F

func (F) Round

func (v F) Round() F

func (F) SideOfLine

func (v F) SideOfLine(a, b F) float32

SideOfLine calculates which side of the line A->B the point P lies on. Check the sign of the response.

func (F) String

func (v F) String() string

func (F) Sub

func (v F) Sub(other F) F

func (F) SubScalar

func (v F) SubScalar(scalar float32) F

func (F) SubScalars

func (v F) SubScalars(x, y float32) F

func (F) Swap

func (v F) Swap() F

func (*F) UnmarshalJSON

func (v *F) UnmarshalJSON(data []byte) error

func (F) WithX

func (v F) WithX(value float32) F

func (F) WithY

func (v F) WithY(value float32) F

type I

type I struct {
	X, Y int32
}

func (I) Abs

func (i I) Abs() I

func (I) Add

func (i I) Add(other I) I

func (I) AddScalars

func (i I) AddScalars(x, y int32) I

func (I) Area

func (i I) Area() int32

func (I) AsDouble

func (i I) AsDouble() D

func (I) AsFloat

func (i I) AsFloat() F

func (I) Clamp

func (i I) Clamp(left, right I) I

func (I) Components

func (i I) Components() (x, y int32)

func (I) Equals

func (i I) Equals(other I) bool

func (I) Index

func (i I) Index(width int32) int32

func (I) IsBetweenInclusive

func (i I) IsBetweenInclusive(left, right I) bool

func (I) IsZero

func (i I) IsZero() bool

func (I) Magnitude

func (i I) Magnitude() float64

func (I) MarshalJSON

func (v I) MarshalJSON() ([]byte, error)

func (I) Max

func (i I) Max(other I) I

func (I) Min

func (i I) Min(other I) I

func (I) MinMax

func (i I) MinMax(other I) (min_, max_ I)

func (I) String

func (i I) String() string

func (I) Sub

func (i I) Sub(other I) I

func (*I) UnmarshalJSON

func (i *I) UnmarshalJSON(data []byte) error

type RotationKernel

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

func NewRotationKernel

func NewRotationKernel(angle float32) (rk RotationKernel)

func (RotationKernel) Rotate

func (rk RotationKernel) Rotate(v F) F

Jump to

Keyboard shortcuts

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