common

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZV = &Vector{0, 0}

ZV is a zero vector

Functions

This section is empty.

Types

type Rectangle

type Rectangle struct {
	Min, Max Vector
}

Rectangle is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.

The invariant should hold, that Max's components are greater or equal than Min's components respectively.

func Rect

func Rect(x0 float64, y0 float64, x1 float64, y1 float64) Rectangle

Rect returns a rectangle

func RectImageCopy

func RectImageCopy(srcRect image.Rectangle) *Rectangle

RectImageCopy converts an image rectangle to model rect

func (*Rectangle) Dx

func (r *Rectangle) Dx() float64

Dx returns r's width

func (*Rectangle) Dy

func (r *Rectangle) Dy() float64

Dy returns r's height

func (*Rectangle) String

func (r *Rectangle) String() string

String returns the string representation of the rectangle

type Vector

type Vector struct {
	X, Y float64
}

Vector is a 2D vector type with X and Y coordinates

func NewVectorFromPoint

func NewVectorFromPoint(point image.Point) *Vector

NewVectorFromPoint converts an image point to a vector

func Unit

func Unit(angle float64) *Vector

Unit returns a vector of length 1 facing the given angle.

func Vect

func Vect(x, y float64) Vector

Vect returns a 2D vector based on two points

func (*Vector) Add

func (v *Vector) Add(nv *Vector) *Vector

Add returns the sum of vectors u and v.

func (*Vector) Angle

func (v *Vector) Angle() float64

Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].

func (*Vector) Copy

func (v *Vector) Copy() *Vector

Copy creates a copy of provided vector

func (*Vector) Cross

func (v *Vector) Cross(nv *Vector) float64

Cross return the cross product of vector u and v.

func (*Vector) Dot

func (v *Vector) Dot(nv *Vector) float64

Dot returns the dot product of vector u and v.

func (*Vector) Equal

func (v *Vector) Equal(nv *Vector) bool

Equal returns true if both vectors are at the same location

func (*Vector) Len

func (v *Vector) Len() float64

Len returns the length of the vector.

func (*Vector) Lerp

func (v *Vector) Lerp(a *Vector, b *Vector, t float64) *Vector

Lerp returns a linear interpolation between vector a and b.

This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.

func (*Vector) Map

func (v *Vector) Map(f func(float64) float64) *Vector

Map applies the function f to both x and y components of the vector u and returns the modified vector.

u := pixel.V(10.5, -1.5)
v := nv.Map(math.Floor)   // v is Vector(10, -2), both components of u floored

func (*Vector) Normal

func (v *Vector) Normal() *Vector

Normal returns a vector normal to nv. Equivalent to nv.Rotated(math.Pi / 2), but faster.

func (*Vector) Project

func (v *Vector) Project(nv *Vector) *Vector

Project returns a projection (or component) of vector u in the direction of vector v.

Behaviour is undefined if v is a zero vector.

func (*Vector) Rotated

func (v *Vector) Rotated(angle float64) *Vector

Rotated returns the vector u rotated by the given angle in radians.

func (*Vector) Scaled

func (v *Vector) Scaled(s float64) *Vector

Scaled returns the vector u multiplied by c.

func (*Vector) ScaledXY

func (v *Vector) ScaledXY(nv *Vector) *Vector

ScaledXY returns the vector u multiplied by c.

func (*Vector) String

func (v *Vector) String() string

String returns the string representation of the vector

func (*Vector) Sub

func (v *Vector) Sub(nv *Vector) *Vector

Sub returns the difference betweeen vectors u and v.

func (*Vector) Unit

func (v *Vector) Unit() *Vector

Unit returns a vector of length 1 facing the direction of u (has the same angle).

func (*Vector) XY

func (v *Vector) XY() (x, y float64)

XY returns the components of the vector in two return values.

Jump to

Keyboard shortcuts

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