Documentation ¶
Overview ¶
Package geom contains utilities for working with geometry.
Index ¶
- Constants
- func AngleStrictlyBetween(angle, low, high float64) bool
- func FindBalancedFactors(value int) (int, int)
- func InnerSquareRadius(r float64) float64
- func OuterSquareRadius(r float64) float64
- type Point
- func (p Point) Add(other Point) Point
- func (p Point) Div(divisor float64) Point
- func (p Point) Mul(factor float64) Point
- func (p Point) Neg() Point
- func (p Point) Polar() (float64, float64)
- func (p Point) Rotate(angle float64) Point
- func (p Point) RotateAround(angle float64, origin Point) Point
- func (p Point) Scale(other Point) Point
- func (p Point) String() string
- func (p Point) Sub(other Point) Point
- func (p Point) XY() (float64, float64)
- type Polygon
- func (pg Polygon) BoundingRect() Rectangle
- func (pg Polygon) Center() Point
- func (pg Polygon) Empty() bool
- func (pg Polygon) Scale(factor float64) Polygon
- func (pg Polygon) ScaleFrom(factor float64, origin Point) Polygon
- func (pg Polygon) ScaleFromCenter(factor float64) Polygon
- func (pg Polygon) Translate(p Point) Polygon
- type Rectangle
- func (r Rectangle) BottomLeft() Point
- func (r Rectangle) BottomRight() Point
- func (r Rectangle) Center() Point
- func (r Rectangle) GrowToContain(points ...Point) Rectangle
- func (r Rectangle) Height() float64
- func (r Rectangle) InnerCenterSquare() Rectangle
- func (r Rectangle) MaxSide() float64
- func (r Rectangle) MinSide() float64
- func (r Rectangle) RotateAround(angle float64, origin Point) Polygon
- func (r Rectangle) RotateAroundCenter(angle float64) Polygon
- func (r Rectangle) Scale(factor float64) Rectangle
- func (r Rectangle) ScaleFrom(factor float64, origin Point) Rectangle
- func (r Rectangle) ScaleFromCenter(factor float64) Rectangle
- func (r Rectangle) String() string
- func (r Rectangle) TopLeft() Point
- func (r Rectangle) TopRight() Point
- func (r Rectangle) Translate(p Point) Rectangle
- func (r Rectangle) Vertices() []Point
- func (r Rectangle) Width() float64
Constants ¶
const HalfPi = math.Pi / 2
HalfPi represents PI / 2
const QuarterPi = math.Pi / 4
QuarterPi represents PI / 4
const TwoPi = 2 * math.Pi
TwoPi represents 2 * PI
Variables ¶
This section is empty.
Functions ¶
func AngleStrictlyBetween ¶
AngleStrictlyBetween checks whether the given angle is strictly between two other angles.
func FindBalancedFactors ¶
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 ¶
InnerSquareRadius returns the inner radius of a square.
func OuterSquareRadius ¶
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 PtFromPolar ¶
PtFromPolar creates a new point from the given polar coordinates.
func (Point) RotateAround ¶
RotateAround rotates a point counterclockwise around another point.
type Polygon ¶
type Polygon struct {
Vertices []Point
}
A Polygon represents any polygon.
func (Polygon) BoundingRect ¶
BoundingRect returns the bounding rectangle
func (Polygon) ScaleFromCenter ¶
ScaleFromCenter scales the polygon from the center.
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 ¶
RectContainingPoints finds the smallest rectangle containing all given points.
func RectWithSideLengths ¶
RectWithSideLengths creates a new rectangle with the given size.
func SquareWithSideLen ¶
SquareWithSideLen creates a new square with the given size.
func (Rectangle) BottomLeft ¶
BottomLeft returns the bottom left corner point
func (Rectangle) BottomRight ¶
BottomRight returns the bottom right corner point
func (Rectangle) GrowToContain ¶
GrowToContain returns a new rectangle expanded to contain the given points. If the rectangle already contains the points, a copy is returned.
func (Rectangle) InnerCenterSquare ¶
InnerCenterSquare returns a new square which fits inside of the rectangle.
func (Rectangle) RotateAround ¶
RotateAround returns the four vertices of the rectangle after a counterclockwise rotation around the given point.
func (Rectangle) RotateAroundCenter ¶
RotateAroundCenter returns the four vertices of the rectangle after a counterclockwise rotation around the center.
func (Rectangle) ScaleFromCenter ¶
ScaleFromCenter scales the rectangle from the center.