vec2d

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 3 Imported by: 1

README

PkgGoDev License Go Version Tag

CI Go Report Card Maintainability Test Coverage Issues

vec2d

generic 2D vector for golang

fetures

  • includes all common vector operations
  • 100% test coverage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type V

type V[T numeric] struct {
	X, Y T
}

V represents 2D vector.

func New

func New[T numeric](x, y T) V[T]

New creates new vector with given coordinates.

func (V[T]) Abs

func (v V[T]) Abs() V[T]

Abs returns vector of absolute values.

func (V[T]) Add

func (v V[T]) Add(n V[T]) V[T]

Add performs vector addition.

func (V[T]) Angle added in v1.1.0

func (v V[T]) Angle() float64

Angle returns the angle of the vector.

func (V[T]) Ceil

func (v V[T]) Ceil() V[T]

Ceil returns rounded-up vector.

func (V[T]) Cross

func (v V[T]) Cross(n V[T]) T

Cross calculates cross-product.

func (V[T]) Div

func (v V[T]) Div(n V[T]) V[T]

Div performs vector division.

func (V[T]) DivScalar

func (v V[T]) DivScalar(n T) V[T]

DivScalar performs vector * scalar division.

func (V[T]) Dot

func (v V[T]) Dot(n V[T]) T

Dot calculates dot-product.

func (V[T]) Equal added in v1.1.0

func (v V[T]) Equal(n V[T]) bool

Equal return true if vectors are equal.

func (V[T]) Floor

func (v V[T]) Floor() V[T]

Floor returns rounded-down vector.

func (V[T]) IsZero added in v1.2.0

func (v V[T]) IsZero() bool

IsZero return true if vector has both coordinates equal to zero.

func (V[T]) Len

func (v V[T]) Len() T

Len calculates length of vector.

func (V[T]) LenSquared added in v1.2.0

func (v V[T]) LenSquared() T

LenSquared same as Len(), but without sqrt.

func (V[T]) Max

func (v V[T]) Max(n V[T]) V[T]

Max returns maximum of two vectors.

func (V[T]) Min

func (v V[T]) Min(n V[T]) V[T]

Min returns minimum of two vectors.

func (V[T]) Mul

func (v V[T]) Mul(n V[T]) V[T]

Mul performs vector multiplication.

func (V[T]) MulScalar

func (v V[T]) MulScalar(n T) V[T]

MulScalar performs vector * scalar multiplication.

func (V[T]) Neg

func (v V[T]) Neg() V[T]

Neg negates the vector.

func (V[T]) Norm

func (v V[T]) Norm() V[T]

Norm calculates normal vector.

func (V[T]) Perpendicular added in v1.1.0

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

Perpendicular returns the perpendicular/normal vector.

func (V[T]) Rotate added in v1.1.0

func (v V[T]) Rotate(angle float64) V[T]

Rotate returns vector rotated by the given angle in radians.

func (V[T]) String

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

String returns string representation of vector.

func (V[T]) Sub

func (v V[T]) Sub(n V[T]) V[T]

Sub performs vector subtraction.

Jump to

Keyboard shortcuts

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