f64

package
v0.0.0-...-123a482 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: MIT Imports: 6 Imported by: 4

Documentation

Overview

Package f64 provides float64 operations for all listed vectors, as well as interpolation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadGrid is returned if the samples given don't form a grid
	ErrBadGrid = errors.New("provided samples do not form a grid")

	// ErrBadCoord is returned if you interpolate coords outside of the sample range
	ErrBadCoord = errors.New("provided coordinate is outside of the sample range")

	// ErrNotEnough is returned if less than 9 samples are provided
	ErrNotEnough = errors.New("need to provide at least 9 samples")
)

Functions

func Grid2DPositions

func Grid2DPositions(min, stride, max Vec2) <-chan Vec2

Grid2DPositions returns a channel of 2d positions across the defined grid.

Types

type Function2D

type Function2D func(pos Vec2) (float64, error)

Interpolator2D is an interpolation method created using a set of samples and an interpolation algorithm.

func Grid2D

func Grid2D(samples []Vec3, filter filters.GridFilter) (Function2D, error)

Grid2D creates a 2D grid-based interpolator using the provided filter. The Z axis of a sample is the value that will be interpolated.

func MicroSphere2D

func MicroSphere2D(samples []Vec3) Function2D

MicroSphere2D is a 2D interpolator that uses microsphere projection to interpolate over non grid-aligned samples. The Z axis of the samples is the value that will be interpolated.

func (Function2D) Fallback

func (interp Function2D) Fallback(next Function2D) Function2D

Fallback allows you to create a new interpolator that will use the interpolation from next if the interpolation from interp fails.

func (Function2D) Multi

func (interp Function2D) Multi(positions <-chan Vec2) <-chan Vec3

Multi takes a channel of positions and returns a channel of results. Ordering is not guaranteed, and the result channel will be closed when all incoming positions have been processed. Only valid positions will be returned on the channel.

type Vec2

type Vec2 [2]float64

Vec2 is a 2-dimentional float64 vector

func NewVec2

func NewVec2(vs ...float64) Vec2

NewVec2 creates a new Vec2 from the provided values.

func (Vec2) Abs

func (v Vec2) Abs() (res Vec2)

Abs returns the absolute value of v

func (Vec2) Add

func (v Vec2) Add(o Vec2) (res Vec2)

Add o to v

func (*Vec2) At

func (v *Vec2) At(dim int) float64

At returns the value at dimension dim.

func (Vec2) Div

func (v Vec2) Div(s float64) Vec2

Div scales v by the multiplicative inverse of s

func (Vec2) Dot

func (v Vec2) Dot(o Vec2) (d float64)

Dot returns the dot product of v and o (v⋅o)

func (Vec2) Eq

func (v Vec2) Eq(o Vec2) bool

Eq returns true if v and o are equal

func (*Vec2) Get

func (v *Vec2) Get() []float64

Get a slice of the underlying values

func (Vec2) Inv

func (v Vec2) Inv() (res Vec2)

Inv returns the multiplicative inverse of v

func (Vec2) Mag

func (v Vec2) Mag() float64

Mag returns the L2 norm of v

func (Vec2) Mul

func (v Vec2) Mul(s float64) (res Vec2)

Mul scales v by s

func (Vec2) MulV

func (v Vec2) MulV(o Vec2) (res Vec2)

MulV multiplies v*s per dim

func (Vec2) Neg

func (v Vec2) Neg() Vec2

Neg returns the negative vector of v (-v)

func (*Vec2) Set

func (v *Vec2) Set(vs ...float64)

Set vector values

func (Vec2) Sub

func (v Vec2) Sub(o Vec2) Vec2

Sub o from v

func (Vec2) Unit

func (v Vec2) Unit() Vec2

Unit returns the (l2) normalized vector of v or the zero vector if v is zero.

func (*Vec2) Vec2

func (v *Vec2) Vec2() Vec2

Vec2 version of this vector.

func (*Vec2) Vec3

func (v *Vec2) Vec3() Vec3

Vec3 version of this vector.

func (*Vec2) Vec4

func (v *Vec2) Vec4() Vec4

Vec4 version of this vector.

func (*Vec2) VecN

func (v *Vec2) VecN() VecN

VecN version of this vector.

func (Vec2) Within

func (v Vec2) Within(o Vec2) bool

Within returns true if v is within the bounds of o considering both values as their absolute.

type Vec3

type Vec3 [3]float64

Vec3 is a 3-dimentional float64 vector

func NewVec3

func NewVec3(vs ...float64) Vec3

NewVec3 creates a new Vec3 from the provided values.

func (Vec3) Abs

func (v Vec3) Abs() (res Vec3)

Abs returns the absolute value of v

func (Vec3) Add

func (v Vec3) Add(o Vec3) (res Vec3)

Add o to v

func (*Vec3) At

func (v *Vec3) At(dim int) float64

At returns the value at dimension dim.

func (Vec3) Cross

func (v Vec3) Cross(b Vec3) Vec3

Cross returns the cross product of v and o (v x o)

func (Vec3) Div

func (v Vec3) Div(s float64) Vec3

Div scales v by the multiplicative inverse of s

func (Vec3) Dot

func (v Vec3) Dot(o Vec3) (d float64)

Dot returns the dot product of v and o (v⋅o)

func (Vec3) Eq

func (v Vec3) Eq(o Vec3) bool

Eq returns true if v and o are equal

func (*Vec3) Get

func (v *Vec3) Get() []float64

Get a slice of the underlying values

func (Vec3) Inv

func (v Vec3) Inv() (res Vec3)

Inv returns the multiplicative inverse of v

func (Vec3) Mag

func (v Vec3) Mag() float64

Mag returns the L2 norm of v

func (Vec3) Mul

func (v Vec3) Mul(s float64) (res Vec3)

Mul scales v by s

func (Vec3) MulV

func (v Vec3) MulV(o Vec3) (res Vec3)

MulV multiplies v*s per dim

func (Vec3) Neg

func (v Vec3) Neg() Vec3

Neg returns the negative vector of v (-v)

func (*Vec3) Set

func (v *Vec3) Set(vs ...float64)

Set vector values

func (Vec3) Sub

func (v Vec3) Sub(o Vec3) Vec3

Sub o from v

func (Vec3) Unit

func (v Vec3) Unit() Vec3

Unit returns the (l2) normalized vector of v or the zero vector if v is zero.

func (*Vec3) Vec2

func (v *Vec3) Vec2() Vec2

Vec2 version of this vector.

func (*Vec3) Vec3

func (v *Vec3) Vec3() Vec3

Vec3 version of this vector.

func (*Vec3) Vec4

func (v *Vec3) Vec4() Vec4

Vec4 version of this vector.

func (*Vec3) VecN

func (v *Vec3) VecN() VecN

VecN version of this vector.

func (Vec3) Within

func (v Vec3) Within(o Vec3) bool

Within returns true if v is within the bounds of o considering both values as their absolute.

type Vec4

type Vec4 [4]float64

Vec4 is a 4-dimentional float64 vector

func NewVec4

func NewVec4(vs ...float64) Vec4

NewVec4 creates a new Vec4 from the provided values.

func (Vec4) Abs

func (v Vec4) Abs() (res Vec4)

Abs returns the absolute value of v

func (Vec4) Add

func (v Vec4) Add(o Vec4) (res Vec4)

Add o to v

func (*Vec4) At

func (v *Vec4) At(dim int) float64

At returns the value at dimension dim.

func (Vec4) Div

func (v Vec4) Div(s float64) Vec4

Div scales v by the multiplicative inverse of s

func (Vec4) Dot

func (v Vec4) Dot(o Vec4) (d float64)

Dot returns the dot product of v and o (v⋅o)

func (Vec4) Eq

func (v Vec4) Eq(o Vec4) bool

Eq returns true if v and o are equal

func (*Vec4) Get

func (v *Vec4) Get() []float64

Get a slice of the underlying values

func (Vec4) Inv

func (v Vec4) Inv() (res Vec4)

Inv returns the multiplicative inverse of v

func (Vec4) Mag

func (v Vec4) Mag() float64

Mag returns the L2 norm of v

func (Vec4) Mul

func (v Vec4) Mul(s float64) (res Vec4)

Mul scales v by s

func (Vec4) MulV

func (v Vec4) MulV(o Vec4) (res Vec4)

MulV multiplies v*s per dim

func (Vec4) Neg

func (v Vec4) Neg() Vec4

Neg returns the negative vector of v (-v)

func (*Vec4) Set

func (v *Vec4) Set(vs ...float64)

Set vector values

func (Vec4) Sub

func (v Vec4) Sub(o Vec4) Vec4

Sub o from v

func (Vec4) Unit

func (v Vec4) Unit() Vec4

Unit returns the (l2) normalized vector of v or the zero vector if v is zero.

func (*Vec4) Vec2

func (v *Vec4) Vec2() Vec2

Vec2 version of this vector.

func (*Vec4) Vec3

func (v *Vec4) Vec3() Vec3

Vec3 version of this vector.

func (*Vec4) Vec4

func (v *Vec4) Vec4() Vec4

Vec4 version of this vector.

func (*Vec4) VecN

func (v *Vec4) VecN() VecN

VecN version of this vector.

func (Vec4) Within

func (v Vec4) Within(o Vec4) bool

Within returns true if v is within the bounds of o considering both values as their absolute.

type VecC

type VecC interface {
	At(dim int) float64
	Get() []float64
	Set(vs ...float64)
	Vec2() Vec2
	Vec3() Vec3
	Vec4() Vec4
	VecN() VecN
}

VecC provides a dimensionless interface for all cartesian vecs.

func RandomUnitVecN

func RandomUnitVecN(dims int, r *rand.Rand) VecC

RandomUnitVecN provides a random n-vector with uniform distribution for direction and magnitude of 1.

type VecN

type VecN []float64

VecN is an n-dimentional float64 vector

func NewVecN

func NewVecN(vs ...float64) VecN

NewVecN creates a new VecN from the provided values.

func (VecN) Abs

func (v VecN) Abs() (res VecN)

Abs returns the absolute value of v

func (VecN) Add

func (v VecN) Add(o VecN) (res VecN)

Add o to v

func (*VecN) At

func (v *VecN) At(dim int) float64

At returns the value at dimension dim.

func (VecN) Div

func (v VecN) Div(s float64) VecN

Div scales v by the multiplicative inverse of s

func (VecN) Dot

func (v VecN) Dot(o VecN) (d float64)

Dot returns the dot product of v and o (v⋅o)

func (VecN) Eq

func (v VecN) Eq(o VecN) bool

Eq returns true if v and o are equal

func (*VecN) Get

func (v *VecN) Get() []float64

Get a slice of the underlying values

func (VecN) Inv

func (v VecN) Inv() (res VecN)

Inv returns the multiplicative inverse of v

func (VecN) Mag

func (v VecN) Mag() float64

Mag returns the L2 norm of v

func (VecN) Mul

func (v VecN) Mul(s float64) (res VecN)

Mul scales v by s

func (VecN) MulV

func (v VecN) MulV(o VecN) (res VecN)

MulV multiplies v*s per dim

func (VecN) Neg

func (v VecN) Neg() VecN

Neg returns the negative vector of v (-v)

func (*VecN) Set

func (v *VecN) Set(vs ...float64)

Set vector values

func (VecN) Sub

func (v VecN) Sub(o VecN) VecN

Sub o from v

func (VecN) Unit

func (v VecN) Unit() VecN

Unit returns the (l2) normalized vector of v or the zero vector if v is zero.

func (*VecN) Vec2

func (v *VecN) Vec2() Vec2

Vec2 version of this vector.

func (*VecN) Vec3

func (v *VecN) Vec3() Vec3

Vec3 version of this vector.

func (*VecN) Vec4

func (v *VecN) Vec4() Vec4

Vec4 version of this vector.

func (*VecN) VecN

func (v *VecN) VecN() VecN

VecN version of this vector.

func (VecN) Within

func (v VecN) Within(o VecN) bool

Within returns true if v is within the bounds of o considering both values as their absolute.

type VecS

type VecS map[string]float64

VecS is an n-dimentional float64 vector with string-keyed dimensions.

func (VecS) Abs

func (v VecS) Abs() (res VecS)

Abs returns the absolute value of v

func (VecS) Add

func (v VecS) Add(o VecS) (res VecS)

Add o to v

func (*VecS) At

func (v *VecS) At(dim string) float64

At returns the value at dimension dim.

func (VecS) Div

func (v VecS) Div(s float64) VecS

Div scales v by the multiplicative inverse of s

func (VecS) Dot

func (v VecS) Dot(o VecS) (d float64)

Dot returns the dot product of v and o (v⋅o)

func (VecS) Eq

func (v VecS) Eq(o VecS) bool

Eq returns true if v and o are equal

func (VecS) Inv

func (v VecS) Inv() (res VecS)

Inv returns the multiplicative inverse of v

func (VecS) Mag

func (v VecS) Mag() float64

Mag returns the L2 norm of v

func (VecS) Mul

func (v VecS) Mul(s float64) (res VecS)

Mul scales v by s

func (VecS) MulV

func (v VecS) MulV(o VecS) (res VecS)

MulV multiplies v*s per dim

func (VecS) Neg

func (v VecS) Neg() VecS

Neg returns the negative vector of v (-v)

func (VecS) Sub

func (v VecS) Sub(o VecS) VecS

Sub o from v

func (VecS) Unit

func (v VecS) Unit() VecS

Unit returns the (l2) normalized vector of v or the zero vector if v is zero.

func (VecS) Within

func (v VecS) Within(o VecS) bool

Within returns true if v is within the bounds of o considering both values as their absolute.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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