Documentation ¶
Overview ¶
Package floatgeom provides primitives for floating point geometry.
Index ¶
- Variables
- func Distance2(x1, y1, x2, y2 float64) float64
- func Distance3(x1, y1, z1, x2, y2, z2 float64) 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) float64
- func (p Point2) Distance(p2 Point2) float64
- func (p Point2) Div(ps ...Point2) Point2
- func (p Point2) DivConst(fs ...float64) Point2
- func (p Point2) Dot(p2 Point2) float64
- 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 ...float64) Point2
- func (p Point2) Normalize() Point2
- func (p Point2) RadiansTo(p2 Point2) float64
- func (p Point2) Rotate(fs ...float64) Point2
- func (p Point2) RotateRadians(fs ...float64) Point2
- func (p Point2) Sub(ps ...Point2) Point2
- func (p Point2) ToAngle() float64
- func (p Point2) ToRadians() float64
- func (p Point2) ToRect(span float64) Rect2
- func (p Point2) X() float64
- func (p Point2) Y() float64
- type Point3
- func (p Point3) Add(ps ...Point3) Point3
- func (p Point3) Cross(p2 Point3) Point3
- func (p Point3) Dim(i int) float64
- func (p Point3) Distance(p2 Point3) float64
- func (p Point3) Div(ps ...Point3) Point3
- func (p Point3) DivConst(fs ...float64) Point3
- func (p Point3) Dot(p2 Point3) float64
- 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 ...float64) Point3
- func (p Point3) Normalize() 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 float64) Rect3
- func (p Point3) X() float64
- func (p Point3) Y() float64
- func (p Point3) Z() float64
- type Point4
- func (p Point4) Conjugate() Point4
- func (p Point4) Dim(i int) float64
- func (p Point4) DivConst(fs ...float64) Point4
- func (p Point4) Dot(p2 Point4) float64
- func (p Point4) Inverse() Point4
- func (p Point4) Magnitude() float64
- func (p Point4) MulConst(fs ...float64) Point4
- func (p Point4) MulQuat(p2 Point4) Point4
- func (p Point4) Normalize() Point4
- func (p Point4) W() float64
- func (p Point4) X() float64
- func (p Point4) Y() float64
- func (p Point4) Z() float64
- type Polygon2
- type Rect2
- func (r Rect2) Area() float64
- 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() float64
- func (r Rect2) Intersects(r2 Rect2) bool
- func (r Rect2) MaxDimensions() int
- func (r Rect2) Midpoint(i int) float64
- func (r Rect2) MulConst(i float64) Rect2
- func (r Rect2) MulSpan(f float64) span.Span[Point2]
- func (r Rect2) Percentile(f float64) Point2
- func (r Rect2) Perimeter() float64
- func (r Rect2) Poll() Point2
- func (r Rect2) Shift(p Point2) Rect2
- func (r Rect2) Span(i int) float64
- func (r Rect2) W() float64
- 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() float64
- func (r Rect3) GreaterOf(r2 Rect3) Rect3
- func (r Rect3) H() float64
- func (r Rect3) Intersects(r2 Rect3) bool
- func (r Rect3) Margin() float64
- func (r Rect3) MaxDimensions() int
- func (r Rect3) Midpoint(i int) float64
- func (r Rect3) MulConst(i float64) 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) ProjectZ() Rect2
- func (r Rect3) Shift(p Point3) Rect3
- func (r Rect3) Space() float64
- func (r Rect3) Span(i int) float64
- func (r Rect3) W() float64
- type Tri3
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]float64
Point2 represents a 2D point on a plane.
func AnglePoint ¶
AnglePoint creates a unit vector from the given angle in degrees as a Point2.
func RadianPoint ¶
RadianPoint creates a unit vector from the given angle in radians as a Point2.
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.
func (Point2) Rotate ¶
Rotate takes in a set of angles and rotates v by their sum the input angles are expected to be in degrees.
func (Point2) RotateRadians ¶
RotateRadians takes in a set of angles and rotates v by their sum the input angles are expected to be in radians.
type Point3 ¶
type Point3 [3]float64
Point3 represents a 3D point in space.
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 Point4 ¶
type Point4 [4]float64
Point4 represents a 4D point, in space + some additional dimension.
func (Point4) Conjugate ¶
Conjugate returns a value of a Point4 often obtained to calculate the inverse
func (Point4) 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 (Point4) MulQuat ¶
MulQuat multiplies two quaternions to generate a combined quarternion that represents both rotations ref: https://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
type Polygon2 ¶
type Polygon2 struct { // Bounding is a cached bounding box calculated from the input points // It is exported for convenience, but should be modified with care Bounding Rect2 // The component points of the polygon. If modified, Bounding should // be updated with NewBoundingRect2. Points []Point2 // contains filtered or unexported fields }
A Polygon2 is a series of points in 2D space.
func NewPolygon2 ¶
NewPolygon2 is a helper method to construct a valid polygon. Polygons cannot contain less than 3 points.
func (Polygon2) Contains ¶
Contains returns whether or not the current Polygon contains the passed in Point. If it is known that the polygon is convex, ConvexContains should be preferred for performance.
func (Polygon2) ConvexContains ¶
ConvexContains returns whether the given point is contained by the input polygon. It assumes the polygon is convex.
func (Polygon2) OverlappingRectCollides ¶
OverlappingRectCollides returns whether a Rect2 intersects or is contained by this Polygon. This method differs from RectCollides because it assumes that we already know r overlaps with pg.Bounding. It is only valid for convex polygons.
func (Polygon2) RectCollides ¶
RectCollides returns whether a Rect2 intersects or is contained by this Polygon. It is only valid for convex polygons.
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 ¶ added in v4.1.0
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) MulConst ¶ added in v4.1.0
MulConst multiplies the boundary points of this rectangle by i.
func (Rect2) MulSpan ¶ added in v4.1.0
MulSpan returns this rectangle as a Point2 Span after multiplying the boundary points of the rectangle by f.
func (Rect2) Percentile ¶ added in v4.1.0
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 ¶ added in v4.1.0
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) MulConst ¶ added in v4.1.0
MulConst multiplies the boundary points of this rectangle by i.
func (Rect3) MulSpan ¶ added in v4.1.0
MulConst multiplies the boundary points of this rectangle by i.
func (Rect3) Percentile ¶ added in v4.1.0
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}
func (Rect3) ProjectZ ¶
ProjectZ projects the Rect3 onto the z axis, removing it's z component and returning a Rect2
type Tri3 ¶
type Tri3 [3]Point3
Tri3 is a triangle of Point3s
func (Tri3) Barycentric ¶
Barycentric finds the barycentric coordinates of the given x,y cartesian coordinates within this triangle. If the point (x,y) is outside of the triangle, one of the output values will be negative. Credit goes to github.com/yellingintothefan for their work in gel