geom

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package geom contains utilities for working with geometry.

Index

Constants

View Source
const HalfPi = math.Pi / 2

HalfPi represents PI / 2

View Source
const QuarterPi = math.Pi / 4

QuarterPi represents PI / 4

View Source
const TwoPi = 2 * math.Pi

TwoPi represents 2 * PI

Variables

This section is empty.

Functions

func AngleStrictlyBetween

func AngleStrictlyBetween(angle, low, high float64) bool

AngleStrictlyBetween checks whether the given angle is strictly between two other angles.

func FindBalancedFactors

func FindBalancedFactors(value int) (int, int)

FindBalancedFactors finds the two factors a and b of the given number such that the difference between a and b is minimal (i.e. a = b = sqrt(value) for square numbers) The return order is a, b such that a <= b

func InnerSquareRadius

func InnerSquareRadius(r float64) float64

InnerSquareRadius returns the inner radius of a square.

func OuterSquareRadius

func OuterSquareRadius(r float64) float64

OuterSquareRadius returns the outer radius of a square.

Types

type Point

type Point struct {
	X, Y float64
}

A Point represents a point using cartesian coordinates.

func Pt

func Pt(x, y float64) Point

Pt creates a new point from the given coordinates.

func PtFromPolar

func PtFromPolar(radius, angle float64) Point

PtFromPolar creates a new point from the given polar coordinates.

func (Point) Add

func (p Point) Add(other Point) Point

Add returns a new point with the given point added.

func (Point) Div

func (p Point) Div(divisor float64) Point

Div returns a new point divided by the divisor.

func (Point) Mul

func (p Point) Mul(factor float64) Point

Mul returns a new point multiplied with the factor.

func (Point) Neg

func (p Point) Neg() Point

Neg returns the negative point

func (Point) Polar

func (p Point) Polar() (float64, float64)

Polar returns the point in polar form. Return order: radius, angle

func (Point) Rotate

func (p Point) Rotate(angle float64) Point

Rotate rotates a point counterclockwise around the origin

func (Point) RotateAround

func (p Point) RotateAround(angle float64, origin Point) Point

RotateAround rotates a point counterclockwise around another point.

func (Point) Scale

func (p Point) Scale(other Point) Point

Scale multiplies two points component-wise

func (Point) String

func (p Point) String() string

func (Point) Sub

func (p Point) Sub(other Point) Point

Sub returns a new point with the given point subtracted.

func (Point) XY

func (p Point) XY() (float64, float64)

XY returns the x and y coordinates.

type Polygon

type Polygon struct {
	Vertices []Point
}

A Polygon represents any polygon.

func Poly

func Poly(points ...Point) Polygon

Poly creates a new polygon containing the given points.

func (Polygon) BoundingRect

func (pg Polygon) BoundingRect() Rectangle

BoundingRect returns the bounding rectangle

func (Polygon) Center

func (pg Polygon) Center() Point

Center returns the centroid of the polygon.

func (Polygon) Empty

func (pg Polygon) Empty() bool

Empty checks whether the polygon contains no points

func (Polygon) Scale

func (pg Polygon) Scale(factor float64) Polygon

Scale scales the polygon from the origin.

func (Polygon) ScaleFrom

func (pg Polygon) ScaleFrom(factor float64, origin Point) Polygon

ScaleFrom scales the polygon from a given point.

func (Polygon) ScaleFromCenter

func (pg Polygon) ScaleFromCenter(factor float64) Polygon

ScaleFromCenter scales the polygon from the center.

func (Polygon) Translate

func (pg Polygon) Translate(p Point) Polygon

Translate moves the polygon by the given amount.

type Rectangle

type Rectangle struct {
	Min, Max Point
}

A Rectangle represents a rectangle using 2 corner points. Only rectangles aligned with the coordinate axes can be represented.

func RectContainingPoints

func RectContainingPoints(points ...Point) Rectangle

RectContainingPoints finds the smallest rectangle containing all given points.

func RectWithSideLengths

func RectWithSideLengths(p Point) Rectangle

RectWithSideLengths creates a new rectangle with the given size.

func SquareWithSideLen

func SquareWithSideLen(side float64) Rectangle

SquareWithSideLen creates a new square with the given size.

func (Rectangle) BottomLeft

func (r Rectangle) BottomLeft() Point

BottomLeft returns the bottom left corner point

func (Rectangle) BottomRight

func (r Rectangle) BottomRight() Point

BottomRight returns the bottom right corner point

func (Rectangle) Center

func (r Rectangle) Center() Point

Center returns the center of the rectangle.

func (Rectangle) GrowToContain

func (r Rectangle) GrowToContain(points ...Point) Rectangle

GrowToContain returns a new rectangle expanded to contain the given points. If the rectangle already contains the points, a copy is returned.

func (Rectangle) Height

func (r Rectangle) Height() float64

Height returns the height of the rectangle).

func (Rectangle) InnerCenterSquare

func (r Rectangle) InnerCenterSquare() Rectangle

InnerCenterSquare returns a new square which fits inside of the rectangle.

func (Rectangle) MaxSide

func (r Rectangle) MaxSide() float64

MaxSide returns the length of the bigger side.

func (Rectangle) MinSide

func (r Rectangle) MinSide() float64

MinSide return the length of the smaller side.

func (Rectangle) RotateAround

func (r Rectangle) RotateAround(angle float64, origin Point) Polygon

RotateAround returns the four vertices of the rectangle after a counterclockwise rotation around the given point.

func (Rectangle) RotateAroundCenter

func (r Rectangle) RotateAroundCenter(angle float64) Polygon

RotateAroundCenter returns the four vertices of the rectangle after a counterclockwise rotation around the center.

func (Rectangle) Scale

func (r Rectangle) Scale(factor float64) Rectangle

Scale scales the rectangle from the origin.

func (Rectangle) ScaleFrom

func (r Rectangle) ScaleFrom(factor float64, origin Point) Rectangle

ScaleFrom scales the rectangle from a given point.

func (Rectangle) ScaleFromCenter

func (r Rectangle) ScaleFromCenter(factor float64) Rectangle

ScaleFromCenter scales the rectangle from the center.

func (Rectangle) String

func (r Rectangle) String() string

func (Rectangle) TopLeft

func (r Rectangle) TopLeft() Point

TopLeft returns the top left corner point

func (Rectangle) TopRight

func (r Rectangle) TopRight() Point

TopRight returns the top right corner point

func (Rectangle) Translate

func (r Rectangle) Translate(p Point) Rectangle

Translate moves the rectangle around by the given point.

func (Rectangle) Vertices

func (r Rectangle) Vertices() []Point

Vertices returns a slice containing all four corner points The order is clockwise starting with the top left corner.

func (Rectangle) Width

func (r Rectangle) Width() float64

Width returns the width of the rectangle.

Jump to

Keyboard shortcuts

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