intgeom

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package intgeom provides primitives for integer geometry.

Index

Constants

This section is empty.

Variables

View Source
var (
	Up        = Dir2(Point2{0, -1})
	Down      = Dir2(Point2{0, 1})
	Left      = Dir2(Point2{-1, 0})
	Right     = Dir2(Point2{1, 0})
	UpRight   = Up.And(Right)
	DownRight = Down.And(Right)
	DownLeft  = Down.And(Left)
	UpLeft    = Up.And(Left)
)

Dir2 values

Functions

func Distance2

func Distance2(x1, y1, x2, y2 int) float64

Distance2 calculates the euclidean distance between two points, as two (x,y) pairs

func Distance3

func Distance3(x1, y1, z1, x2, y2, z2 int) float64

Distance3 calculates the euclidean distance between two points, as two (x,y,z) triplets

Types

type Dir2

type Dir2 Point2

Dir2 is a helper type for representing points as directions

func (Dir2) And

func (d Dir2) And(d2 Dir2) Dir2

And combines two directions

func (Dir2) X

func (d Dir2) X() int

X retrieves the horizontal component of a Dir2

func (Dir2) Y

func (d Dir2) Y() int

Y retrieves the vertical component for a Dir2

type Point2

type Point2 [2]int

Point2 represents a 2D point in space.

func (Point2) Add

func (p Point2) Add(ps ...Point2) Point2

Add combines the input points via addition.

func (Point2) AngleTo

func (p Point2) AngleTo(p2 Point2) float64

AngleTo returns the angle from p to p2 in degrees.

func (Point2) Dim

func (p Point2) Dim(i int) int

Dim returns the value of p in the ith dimension. Panics if i > 1. No check is made for efficiency's sake, pending benchmarks, but adding an error here would significantly worsen the API.

func (Point2) Distance

func (p Point2) Distance(p2 Point2) float64

Distance calculates the distance between this Point2 and another.

func (Point2) Div

func (p Point2) Div(ps ...Point2) Point2

Div combines the input points via division. Div does not check that the inputs are non zero before operating, and can panic if that is not true.

func (Point2) DivConst

func (p Point2) DivConst(fs ...int) Point2

DivConst divides all elements of a point by the input floats DivConst does not check that the inputs are non zero before operating, and can panic if that is not true.

func (Point2) Dot

func (p Point2) Dot(p2 Point2) int

Dot returns the dot product of the input points

func (Point2) GreaterOf

func (p Point2) GreaterOf(ps ...Point2) Point2

GreaterOf returns the highest values on each axis of the input points as a point.

func (Point2) LesserOf

func (p Point2) LesserOf(ps ...Point2) Point2

LesserOf returns the lowest values on each axis of the input points as a point.

func (Point2) Magnitude

func (p Point2) Magnitude() float64

Magnitude returns the magnitude of the combined components of a Point

func (Point2) Mul

func (p Point2) Mul(ps ...Point2) Point2

Mul combines in the input points via multiplication.

func (Point2) MulConst

func (p Point2) MulConst(fs ...int) Point2

MulConst multiplies all elements of a point by the input floats

func (Point2) RadiansTo

func (p Point2) RadiansTo(p2 Point2) float64

RadiansTo returns the angle from p to p2 in radians.

func (Point2) Sub

func (p Point2) Sub(ps ...Point2) Point2

Sub combines the input points via subtraction.

func (Point2) ToAngle

func (p Point2) ToAngle() float64

ToAngle returns this point as an angle in degrees.

func (Point2) ToRadians

func (p Point2) ToRadians() float64

ToRadians returns this point as an angle in radians.

func (Point2) ToRect

func (p Point2) ToRect(span int) Rect2

ToRect converts this point into a rectangle spanning span distance in each axis.

func (Point2) X

func (p Point2) X() int

X returns the point's value on the X axis.

func (Point2) Y

func (p Point2) Y() int

Y returns the point's value on the Y axis.

type Point3

type Point3 [3]int

Point3 represents a 3D point in space.

func (Point3) Add

func (p Point3) Add(ps ...Point3) Point3

Add combines the input points via addition.

func (Point3) Dim

func (p Point3) Dim(i int) int

Dim returns the value of p in the ith dimension. Panics if i > 2. No check is made for efficiency's sake, pending benchmarks, but adding an error here would significantly worsen the API.

func (Point3) Distance

func (p Point3) Distance(p2 Point3) float64

Distance calculates the distance between this Point3 and another.

func (Point3) Div

func (p Point3) Div(ps ...Point3) Point3

Div combines the input points via division. Div does not check that the inputs are non zero before operating, and can panic if that is not true.

func (Point3) DivConst

func (p Point3) DivConst(fs ...int) Point3

DivConst divides all elements of a point by the input floats DivConst does not check that the inputs are non zero before operating, and can panic if that is not true.

func (Point3) Dot

func (p Point3) Dot(p2 Point3) int

Dot returns the dot product of the input points

func (Point3) GreaterOf

func (p Point3) GreaterOf(ps ...Point3) Point3

GreaterOf returns the highest values on each axis of the input points as a point.

func (Point3) LesserOf

func (p Point3) LesserOf(ps ...Point3) Point3

LesserOf returns the lowest values on each axis of the input points as a point.

func (Point3) Magnitude

func (p Point3) Magnitude() float64

Magnitude returns the magnitude of the combined components of a Point

func (Point3) Mul

func (p Point3) Mul(ps ...Point3) Point3

Mul combines in the input points via multiplication.

func (Point3) MulConst

func (p Point3) MulConst(fs ...int) Point3

MulConst multiplies all elements of a point by the input floats

func (Point3) ProjectX

func (p Point3) ProjectX() Point2

ProjectX projects the Point3 onto the x axis, removing it's x component and returning a Point2

func (Point3) ProjectY

func (p Point3) ProjectY() Point2

ProjectY projects the Point3 onto the y axis, removing it's y component and returning a Point2

func (Point3) ProjectZ

func (p Point3) ProjectZ() Point2

ProjectZ projects the Point3 onto the z axis, removing it's z component and returning a Point2

func (Point3) Sub

func (p Point3) Sub(ps ...Point3) Point3

Sub combines the input points via subtraction.

func (Point3) ToRect

func (p Point3) ToRect(span int) Rect3

ToRect converts this point into a rectangle spanning span distance in each axis.

func (Point3) X

func (p Point3) X() int

X returns the point's value on the X axis.

func (Point3) Y

func (p Point3) Y() int

Y returns the point's value on the Y axis.

func (Point3) Z

func (p Point3) Z() int

Z returns the point's value on the Z axis.

type Rect2

type Rect2 struct {
	Min, Max Point2
}

A Rect2 represents a span from one point in 2D space to another. If Min is less than max on any axis, it will return undefined results for methods.

func NewBoundingRect2

func NewBoundingRect2(pts ...Point2) Rect2

NewBoundingRect2 will produce the minimal rectangle that contains all of the input points.

func NewRect2

func NewRect2(x, y, x2, y2 int) Rect2

NewRect2 returns an (X,Y):(X2,Y2) rectangle. This enforces that x < x2 and y < y2, and will swap the inputs if that is not true. If that enforcement is not desired, construct the struct manually.

func NewRect2WH

func NewRect2WH(x, y, w, h int) Rect2

NewRect2WH returns an (X,Y):(X+W,Y+H) rectangle. This enforces that w and h are positive, and will decrease x and y respectively if that is not true.

func (Rect2) Area

func (r Rect2) Area() int

Area returns W * H.

func (Rect2) Center

func (r Rect2) Center() Point2

Center returns the center of this rectangle.

func (Rect2) Contains

func (r Rect2) Contains(p Point2) bool

Contains tests whether p is located inside or on the boundary of r.

func (Rect2) ContainsRect

func (r Rect2) ContainsRect(r2 Rect2) bool

ContainsRect tests whether r2 is is located inside r1.

func (Rect2) GreaterOf

func (r Rect2) GreaterOf(r2 Rect2) Rect2

GreaterOf returns a rectangle formed of the lowest values on each dimension for Min, and the highest for Max.

func (Rect2) H

func (r Rect2) H() int

H returns the height of this rectangle.

func (Rect2) Intersects

func (r Rect2) Intersects(r2 Rect2) bool

Intersects returns whether the two rectangles intersect.

func (Rect2) MaxDimensions

func (r Rect2) MaxDimensions() int

MaxDimensions reports that a Rect2 has only two dimensions of definition.

func (Rect2) Midpoint

func (r Rect2) Midpoint(i int) int

Midpoint returns the midpoint of this rectangle's span over a given dimension.

func (Rect2) Perimeter

func (r Rect2) Perimeter() int

Perimeter computes the sum of the edge lengths of a rectangle.

func (Rect2) Span

func (r Rect2) Span(i int) int

Span returns the span on this rectangle's ith axis.

func (Rect2) W

func (r Rect2) W() int

W returns the width of this rectangle.

type Rect3

type Rect3 struct {
	Min, Max Point3
}

A Rect3 represents a span from one point in 3D space to another. If Min is less than Max on any axis, it will return undefined results for methods.

func NewBoundingRect3

func NewBoundingRect3(pts ...Point3) Rect3

NewBoundingRect3 will produce the minimal rectangle that contains all of the input points.

func NewRect3

func NewRect3(x, y, z, x2, y2, z2 int) Rect3

NewRect3 returns an (X,Y,Z):(X2,Y2,Z2) rectangle. This enforces that x < x2, y < y2, and z < z2, and will swap the inputs if that is not true.

func NewRect3WH

func NewRect3WH(x, y, z, w, h, d int) Rect3

NewRect3WH returns an (X,Y,Z):(X+W,Y+H,Z+D) rectangle. This enforces that w, h, and d and positive, and will decrease x, y, and z respectively if that is not true.

func (Rect3) Center

func (r Rect3) Center() Point3

Center returns the center of this rectangle.

func (Rect3) Contains

func (r Rect3) Contains(p Point3) bool

Contains tests whether p is located inside or on the boundary of r.

func (Rect3) ContainsRect

func (r Rect3) ContainsRect(r2 Rect3) bool

ContainsRect tests whether r2 is is located inside r1.

func (Rect3) D

func (r Rect3) D() int

D returns the depth of this rectangle.

func (Rect3) GreaterOf

func (r Rect3) GreaterOf(r2 Rect3) Rect3

GreaterOf returns a rectangle formed of the lowest values on each dimension for Min, and the highest for Max.

func (Rect3) H

func (r Rect3) H() int

H returns the height of this rectangle.

func (Rect3) Intersects

func (r Rect3) Intersects(r2 Rect3) bool

Intersects returns whether the two rectangles intersect.

func (Rect3) Margin

func (r Rect3) Margin() int

Margin computes the sum of the edge lengths of a rectangle.

func (Rect3) MaxDimensions

func (r Rect3) MaxDimensions() int

MaxDimensions reports that a Rect3 has only three dimensions of definition.

func (Rect3) Midpoint

func (r Rect3) Midpoint(i int) int

Midpoint returns the midpoint of this rectangle's span over a given dimension.

func (Rect3) Space

func (r Rect3) Space() int

Space returns W * H * D

func (Rect3) Span

func (r Rect3) Span(i int) int

Span returns the span on this rectangle's ith axis.

func (Rect3) W

func (r Rect3) W() int

W returns the width of this rectangle.

Jump to

Keyboard shortcuts

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