Documentation
¶
Overview ¶
Package intgeom provides primitives for integer geometry.
Index ¶
- Variables
- func Distance2(x1, y1, x2, y2 int) float64
- func Distance3(x1, y1, z1, x2, y2, z2 int) float64
- type Dir2
- type Point2
- func (p Point2) Add(ps ...Point2) Point2
- func (p Point2) AngleTo(p2 Point2) float64
- func (p Point2) Dim(i int) int
- func (p Point2) Distance(p2 Point2) float64
- func (p Point2) Div(ps ...Point2) Point2
- func (p Point2) DivConst(fs ...int) Point2
- func (p Point2) Dot(p2 Point2) int
- func (p Point2) GreaterOf(ps ...Point2) Point2
- func (p Point2) LesserOf(ps ...Point2) Point2
- func (p Point2) Magnitude() float64
- func (p Point2) Mul(ps ...Point2) Point2
- func (p Point2) MulConst(fs ...int) Point2
- func (p Point2) RadiansTo(p2 Point2) float64
- func (p Point2) Sub(ps ...Point2) Point2
- func (p Point2) ToAngle() float64
- func (p Point2) ToRadians() float64
- func (p Point2) ToRect(span int) Rect2
- func (p Point2) X() int
- func (p Point2) Y() int
- type Point3
- func (p Point3) Add(ps ...Point3) Point3
- func (p Point3) Dim(i int) int
- func (p Point3) Distance(p2 Point3) float64
- func (p Point3) Div(ps ...Point3) Point3
- func (p Point3) DivConst(fs ...int) Point3
- func (p Point3) Dot(p2 Point3) int
- func (p Point3) GreaterOf(ps ...Point3) Point3
- func (p Point3) LesserOf(ps ...Point3) Point3
- func (p Point3) Magnitude() float64
- func (p Point3) Mul(ps ...Point3) Point3
- func (p Point3) MulConst(fs ...int) Point3
- func (p Point3) ProjectX() Point2
- func (p Point3) ProjectY() Point2
- func (p Point3) ProjectZ() Point2
- func (p Point3) Sub(ps ...Point3) Point3
- func (p Point3) ToRect(span int) Rect3
- func (p Point3) X() int
- func (p Point3) Y() int
- func (p Point3) Z() int
- type Rect2
- func (r Rect2) Area() int
- func (r Rect2) Center() Point2
- func (r Rect2) Clamp(pt Point2) Point2
- func (r Rect2) Contains(p Point2) bool
- func (r Rect2) ContainsRect(r2 Rect2) bool
- func (r Rect2) GreaterOf(r2 Rect2) Rect2
- func (r Rect2) H() int
- func (r Rect2) Intersects(r2 Rect2) bool
- func (r Rect2) MaxDimensions() int
- func (r Rect2) Midpoint(i int) int
- func (r Rect2) MulConst(i int) Rect2
- func (r Rect2) MulSpan(f float64) span.Span[Point2]
- func (r Rect2) Percentile(f float64) Point2
- func (r Rect2) Perimeter() int
- func (r Rect2) Poll() Point2
- func (r Rect2) Span(i int) int
- func (r Rect2) W() int
- type Rect3
- func (r Rect3) Center() Point3
- func (r Rect3) Clamp(pt Point3) Point3
- func (r Rect3) Contains(p Point3) bool
- func (r Rect3) ContainsRect(r2 Rect3) bool
- func (r Rect3) D() int
- func (r Rect3) GreaterOf(r2 Rect3) Rect3
- func (r Rect3) H() int
- func (r Rect3) Intersects(r2 Rect3) bool
- func (r Rect3) Margin() int
- func (r Rect3) MaxDimensions() int
- func (r Rect3) Midpoint(i int) int
- func (r Rect3) MulConst(i int) Rect3
- func (r Rect3) MulSpan(f float64) span.Span[Point3]
- func (r Rect3) Percentile(f float64) Point3
- func (r Rect3) Poll() Point3
- func (r Rect3) Space() int
- func (r Rect3) Span(i int) int
- func (r Rect3) W() int
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type Point2 ¶
type Point2 [2]int
Point2 represents a 2D point in space.
func (Point2) Dim ¶
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) Div ¶
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 ¶
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) GreaterOf ¶
GreaterOf returns the highest values on each axis of the input points as a point.
func (Point2) LesserOf ¶
LesserOf returns the lowest values on each axis of the input points as a point.
type Point3 ¶
type Point3 [3]int
Point3 represents a 3D point in space.
func (Point3) Dim ¶
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) Div ¶
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 ¶
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) GreaterOf ¶
GreaterOf returns the highest values on each axis of the input points as a point.
func (Point3) LesserOf ¶
LesserOf returns the lowest values on each axis of the input points as a point.
func (Point3) ProjectX ¶
ProjectX projects the Point3 onto the x axis, removing it's x component and returning a Point2
func (Point3) ProjectY ¶
ProjectY projects the Point3 onto the y axis, removing it's y component and returning a Point2
func (Point3) ProjectZ ¶
ProjectZ projects the Point3 onto the z axis, removing it's z component and returning a Point2
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 ¶
NewBoundingRect2 will produce the minimal rectangle that contains all of the input points.
func NewRect2 ¶
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 ¶
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) Clamp ¶
Clamp returns a version of the provided point such that it is contained within r. If it was already contained in r, it will not be changed.
func (Rect2) ContainsRect ¶
ContainsRect tests whether r2 is is located inside r1.
func (Rect2) GreaterOf ¶
GreaterOf returns a rectangle formed of the lowest values on each dimension for Min, and the highest for Max.
func (Rect2) Intersects ¶
Intersects returns whether the two rectangles intersect.
func (Rect2) MaxDimensions ¶
MaxDimensions reports that a Rect2 has only two dimensions of definition.
func (Rect2) Midpoint ¶
Midpoint returns the midpoint of this rectangle's span over a given dimension.
func (Rect2) MulSpan ¶
MulSpan returns this rectangle as a Point2 Span after multiplying the boundary points of the rectangle by f.
func (Rect2) Percentile ¶
Percentile returns a point within this rectangle along the vector from the top left to the bottom right of the rectangle, where for example, 0.0 will be r.Min, 1.0 will be r.Max, and 2.0 will be project the vector beyond r and return r.Min + {r.W()*2, r.H()*2}
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 ¶
NewBoundingRect3 will produce the minimal rectangle that contains all of the input points.
func NewRect3 ¶
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 ¶
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) Clamp ¶
Clamp returns a version of the provided point such that it is contained within r. If it was already contained in r, it will not be changed.
func (Rect3) ContainsRect ¶
ContainsRect tests whether r2 is is located inside r1.
func (Rect3) GreaterOf ¶
GreaterOf returns a rectangle formed of the lowest values on each dimension for Min, and the highest for Max.
func (Rect3) Intersects ¶
Intersects returns whether the two rectangles intersect.
func (Rect3) MaxDimensions ¶
MaxDimensions reports that a Rect3 has only three dimensions of definition.
func (Rect3) Midpoint ¶
Midpoint returns the midpoint of this rectangle's span over a given dimension.
func (Rect3) Percentile ¶
Percentile returns a point within this rectangle along the vector from the top left to the bottom right of the rectangle, where for example, 0.0 will be r.Min, 1.0 will be r.Max, and 2.0 will be project the vector beyond r and return r.Min + {r.W()*2, r.H()*2, r.D()*2}