mathg

package
v0.0.0-...-79bc5c6 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package mathg provides mathematical functions for graphics / games.

Index

Constants

View Source
const (
	Tau     = math.Pi * 2
	Deg2Rad = math.Pi / 180
	Rad2Deg = 180 / math.Pi
)

Variables

This section is empty.

Functions

func Clamp

func Clamp(v float64) float64

func Lerp

func Lerp(a, b, t float64) float64

func Yoyo

func Yoyo(v float64) float64

Types

type Line

type Line struct {
	Start, End Point
}

func (*Line) Angle

func (l *Line) Angle() float64

func (*Line) Bounds

func (l *Line) Bounds() Rectangle

func (*Line) Dx

func (l *Line) Dx() float64

Dx returns l's width.

func (*Line) Dy

func (l *Line) Dy() float64

Dy returns l's height.

func (*Line) Intersects

func (l *Line) Intersects(m Line) bool

func (*Line) Length

func (l *Line) Length() float64

type Point

type Point struct {
	X, Y float64
}

A Point is an X, Y coordinate pair.

func PolarToPoint

func PolarToPoint(r, theta float64) Point

func Pt

func Pt(X, Y float64) Point

Pt is shorthand for Point{X, Y}.

func (Point) Add

func (p Point) Add(q Point) Point

Add returns the vector p+q.

func (Point) Angle

func (p Point) Angle() float64

func (Point) Cross

func (p Point) Cross(q Point) float64

func (Point) Div

func (p Point) Div(k float64) Point

Div returns the vector p/k.

func (Point) Dot

func (p Point) Dot(q Point) float64

func (Point) Equal

func (p Point) Equal(q Point) bool

Equal reports whether p and q are equal.

func (Point) In

func (p Point) In(r Rectangle) bool

In reports whether p is in r.

func (Point) LengthSq

func (p Point) LengthSq() float64

LengthSq returns |p|^2.

func (Point) Lerp

func (p Point) Lerp(q Point, t float64) Point

func (Point) Mul

func (p Point) Mul(k float64) Point

Mul returns the vector p*k.

func (Point) Normalized

func (p Point) Normalized() Point

Normalized returns the normalized vector.

func (Point) Rotate

func (p Point) Rotate(theta float64) Point

func (Point) String

func (p Point) String() string

func (Point) Sub

func (p Point) Sub(q Point) Point

Sub returns the vector p-q.

type Rectangle

type Rectangle struct {
	Min, Max Point
}

func Rect

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

func (Rectangle) Add

func (r Rectangle) Add(p Point) Rectangle

Add returns the rectangle r translated by p.

func (Rectangle) At

func (r Rectangle) At(x, y int) color.Color

At implements the Image interface.

func (Rectangle) Bounds

func (r Rectangle) Bounds() image.Rectangle

Bounds implements the Image interface.

func (Rectangle) Canon

func (r Rectangle) Canon() Rectangle

Canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.

func (Rectangle) ColorModel

func (r Rectangle) ColorModel() color.Model

ColorModel implements the Image interface.

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) Empty

func (r Rectangle) Empty() bool

Empty reports whether the rectangle contains no points.

func (Rectangle) Eq

func (r Rectangle) Eq(s Rectangle) bool

Eq reports whether r and s contain the same set of points. All empty rectangles are considered equal.

func (Rectangle) Image

func (r Rectangle) Image() image.Rectangle

func (Rectangle) In

func (r Rectangle) In(s Rectangle) bool

In reports whether every point in r is in s.

func (Rectangle) Inset

func (r Rectangle) Inset(n float64) Rectangle

Inset returns the rectangle r inset by n, which may be negative. If either of r's dimensions is less than 2*n then an empty rectangle near the center of r will be returned.

func (Rectangle) Intersect

func (r Rectangle) Intersect(s Rectangle) Rectangle

Intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then the zero rectangle will be returned.

func (Rectangle) Overlaps

func (r Rectangle) Overlaps(s Rectangle) bool

Overlaps reports whether r and s have a non-empty intersection.

func (Rectangle) Size

func (r Rectangle) Size() Point

Size returns r's width and height.

func (Rectangle) String

func (r Rectangle) String() string

String returns a string representation of r like "(3,4)-(6,5)".

func (Rectangle) Sub

func (r Rectangle) Sub(p Point) Rectangle

Sub returns the rectangle r translated by -p.

func (Rectangle) Union

func (r Rectangle) Union(s Rectangle) Rectangle

Union returns the smallest rectangle that contains both r and s.

Jump to

Keyboard shortcuts

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