geom

package
v0.0.0-...-8b39f33 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Point

type Point struct {
	X, Y float64
}

A Point is an X, Y coordinate pair. The axes increase right and down.

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

func (p Point) Dist(q Point) float64

Dist returns the distance of two points.

func (Point) Div

func (p Point) Div(q Point) Point

Div returns the vector p/q.

func (Point) Eq

func (p Point) Eq(q Point) bool

Eq returns whether p and q are equal.

func (Point) Len

func (p Point) Len() float64

Len returns the magnitude of the vector defined by p.

func (Point) Mul

func (p Point) Mul(q Point) Point

Mul returns the vector p*q

func (Point) Normalize

func (p Point) Normalize() Point

Normalize returns the vector normalized so that it has a magnitude of one.

func (Point) SqDist

func (p Point) SqDist(q Point) float64

SqDist returns the squared distance between two points.

func (Point) String

func (p Point) String() string

String returns a string representation of p like "(3.00,4.01)".

func (Point) Sub

func (p Point) Sub(q Point) Point

Sub returns the vector p-q.

type Rectangle

type Rectangle struct {
	Min, Max Point
}

A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y. It is well-formed if Min.X <= Max.X and likewise for Y. Points are always well-formed. A rectangle's methods always return well-formed outputs for well-formed inputs.

func Rect

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

Rect is shorthand for Rectangle{Pt(x0, y0), Pt(x1, y1)}.

func (Rectangle) Add

func (r Rectangle) Add(p Point) Rectangle

Add returns the rectangle r translated by p.

func (Rectangle) Center

func (r Rectangle) Center() Point

Center returns r's center point.

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

func (r Rectangle) Eq(s Rectangle) bool

Eq returns whether r and s are equal.

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 returns whether r and s have a non-empty intersection.

func (Rectangle) OverlapsX

func (r Rectangle) OverlapsX(s Rectangle) bool

OverlapsX returns whether r and s have a non-empty intersection in the x direction.

func (Rectangle) OverlapsY

func (r Rectangle) OverlapsY(s Rectangle) bool

OverlapsY returns whether r and s have a non-empty intersection in the y direction.

func (Rectangle) Pad

func (r Rectangle) Pad(p float64) Rectangle

Pad returns a rectangle with p added to the left, right, top, and bottom of r.

func (Rectangle) Rpad

func (r Rectangle) Rpad(p float64) Rectangle

Rpad returns a rectangle with p removed from the left, right, top, and bottom of r.

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.

type Torus

type Torus struct {
	W, H float64
}

A Torus represents a torus with the given width and height.

func (Torus) AlignRects

func (t Torus) AlignRects(a, b Rectangle) (Rectangle, Rectangle)

AlignRects returns a pair of rectangles. The first is the normalized equivalent of a. The second is equivalent to b on the torus. If there is b equivalent that overlaps a on the torus, then it is returned, otherwise it is any b equivalent.

Both a and b are assumed to be smaller than the width and height of the torus.

func (Torus) Dist

func (t Torus) Dist(a, b Point) float64

Dist returns the distance of two points on the torus.

func (Torus) Intersect

func (t Torus) Intersect(a, b Rectangle) Rectangle

Intersect returns the intersection of a and b on the torus.

Both a and b must be smaller than the size of the torus.

func (Torus) Norm

func (t Torus) Norm(a Point) Point

Norm returns a point that is equivalent to a on the torus, but is within (0,0)-(W-1, H-1).

func (Torus) NormRect

func (t Torus) NormRect(r Rectangle) Rectangle

NormRect returns a rectangle equivalent to r on the torus, but with its minimum point normalized.

func (Torus) Overlaps

func (t Torus) Overlaps(a, b Rectangle) bool

Overlaps returns true if the two rectangles intersect on the torus.

Both a and b must be smaller than the size of the torus.

func (Torus) SqDist

func (t Torus) SqDist(a, b Point) float64

SqDist returns the squared distance of two points on the torus.

func (Torus) Sub

func (t Torus) Sub(a, b Point) Point

Sub returns vector a - b respecting the torus. For example, with a 100 by 100 torus, (99,99) - (0,0) points toward the negative x and y directions since (0,0) == (100,100).

Jump to

Keyboard shortcuts

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