Documentation ¶
Index ¶
- Variables
- func DegreesToRadians(degrees float64) float64
- func Float64NearZero(v float64, tolerance float64) bool
- func FloatsEqual(a, b float64) bool
- func FloatsEqualTol(a, b, tolerance float64) bool
- func Fmt(a any, params any) fmt.Stringer
- func IsCollinear[T Number](p1, p2, p3 Point[T]) bool
- func Max[T Number](a, b T) T
- func Min[T Number](a, b T) T
- func NullHitTest(PtF) bool
- func OnSegment[T Number](p, start, end Point[T]) bool
- func Orient[T Number](a, b, c Point[T]) T
- func Pt3dNearZero(v Pt3dF, tolerance float64) bool
- func RadiansToDegrees(radians float64) float64
- func Ratio(a, b float64) float64
- func RectsEqual[T Number](a, b Rectangle[T]) bool
- func Sqr[T Number](x T) T
- func XAtY(s SegF, y float64) (float64, bool)
- func XYToIndex[T constraints.Integer](width, height T, pt Point[T]) (T, error)
- func XYToIndexFast[T constraints.Integer](x, y, width T) T
- type Angle
- type BezF
- type CircleHitTest
- type CubicBezier
- type Float
- type HitTest
- type Line
- type LnF
- type Mode
- type Number
- type Orientation
- type Point
- func Centroid[T Number](pts []Point[T]) Point[T]
- func ConvertPoint[A Number, B Number](a Point[A]) Point[B]
- func FindIntersection[T Number](s1, s2 Segment[T]) (Point[T], bool)
- func IndexToXY[T constraints.Integer](width, height, index T) (Point[T], error)
- func PerpendicularIntersection[T Float](seg Segment[T], pt Point[T]) (Point[T], bool)
- func Pt[T Number](x, y T) Point[T]
- func Pts[T Number](xys ...T) []Point[T]
- func (a Point[T]) Add(b Point[T]) Point[T]
- func (p Point[T]) Area() T
- func (a Point[T]) Cross(b Point[T]) T
- func (a Point[T]) Degrees(b Point[T]) float64
- func (a Point[T]) Dist(b Point[T]) float64
- func (a Point[T]) DistSquared(b Point[T]) T
- func (a Point[T]) Dot(b Point[T]) float64
- func (a Point[T]) Inside(r Rectangle[T]) bool
- func (a Point[T]) Magnitude() float64
- func (a Point[T]) Mult(b Point[T]) Point[T]
- func (a Point[T]) Normalize() Point[T]
- func (a Point[T]) Project(m, dist float64) (Point[T], Point[T])
- func (a Point[T]) ProjectDegree(deg, dist float64) Point[T]
- func (a Point[T]) Radians() float64
- func (a Point[T]) Rotate(origin Point[T], angleInRads float64) Point[T]
- func (a Point[T]) Sub(b Point[T]) Point[T]
- func (p Point[T]) ToIndex(xy Point[T]) T
- type Point3d
- func (a Point3d[T]) Add(b Point3d[T]) Point3d[T]
- func (a Point3d[T]) CLampFast(rng Range[T]) Point3d[T]
- func (a Point3d[T]) Cross(b Point3d[T]) Point3d[T]
- func (a Point3d[T]) Div(b Point3d[T]) Point3d[T]
- func (a Point3d[T]) DivT(t T) Point3d[T]
- func (a Point3d[T]) Dot(b Point3d[T]) T
- func (a Point3d[T]) DotProduct(b Point3d[T]) T
- func (a Point3d[T]) Magnitude() float64
- func (a Point3d[T]) Mult(b Point3d[T]) Point3d[T]
- func (a Point3d[T]) MultT(t T) Point3d[T]
- func (a Point3d[T]) Normalize() Point3d[T]
- func (a Point3d[T]) Sub(b Point3d[T]) Point3d[T]
- func (a Point3d[T]) SubT(t T) Point3d[T]
- type Poly
- type PolyF
- type PolyF64
- type PolyI
- type PolyI64
- type PolyUI64
- type PolygonBB
- type PolygonBBF64
- type ProcessPtF64Func
- type Pt3dF
- func LinePlaneIntersection(lineA, lineB Pt3dF, planeNormal, planeOrigin Pt3dF) (Pt3dF, bool)
- func TrianglePlaneIntersection(tri Tri3dF, triPt Pt3dF, planeTri Tri3dF, planePt Pt3dF) (Pt3dF, bool)
- func TrianglePlaneIntersection2(tri Tri3dF, triPt Pt3dF, planeTri Tri3dF, planePt Pt3dF) (Pt3dF, bool)
- func TrianglePlaneIntersection5(tri Tri3dF, triPt Pt3dF, planeTri Tri3dF, planePt Pt3dF) (Pt3dF, bool)
- type Pt3dF32
- type Pt3dF64
- type Pt3dI
- type Pt3dI64
- type PtF
- func CubicBezierDistance(cb CubicBezier, pt PtF) (float64, PtF)
- func CubicBezierDistanceSquared(cb CubicBezier, pt PtF) (float64, PtF)
- func DegreesToDirectionCw(degrees float64) PtF
- func DistPointToSegment(seg SegF, p PtF) (float64, PtF)
- func DistSquared(seg SegF, p PtF) (float64, PtF)
- func DistToPolyF(poly []PtF, pt PtF) (float64, PtF)
- func LineLineIntersectionF(l1, l2 LnF) (PtF, bool)
- func LineToSegIntersection(A, B PtF, pq SegF) (PtF, bool)
- func PtToSegIntersection(pt, direction PtF, seg SegF) (PtF, bool)
- func PtToSegIntersection_Off(pt, direction PtF, seg SegF) (PtF, bool)
- func PtToSegIntersection_Off2(pt, direction PtF, seg SegF) (PtF, bool)
- func QuadraticBezierDistanceBrute(cb QuadraticBezier, pt PtF) (float64, PtF)
- func QuadraticBezierDistanceSquared(cb QuadraticBezier, pt PtF) (float64, PtF)
- func QuadraticBezierDistanceSquaredBrute(cb QuadraticBezier, pt PtF) (float64, PtF)
- type PtF32
- type PtF64
- type PtI
- type PtI64
- type QuadraticBezier
- type Range
- func (p Range[T]) Clamp(value T) T
- func (r Range[T]) ClampFast(value T) T
- func (p Range[T]) Clip(value T) T
- func (p Range[T]) Contains(value T) bool
- func (a Range[T]) Intersection(b Range[T]) Range[T]
- func (p Range[T]) MapNormal(normal float64) T
- func (p Range[T]) Midpoint() T
- func (p Range[T]) Normalize(value T) float64
- func (a Range[T]) Overlaps(b Range[T]) bool
- type RectF
- type RectF32
- type RectF64
- type RectI
- type RectI64
- type Rectangle
- func (r1 Rectangle[T]) Add(l, t, r, b T) Rectangle[T]
- func (r Rectangle[T]) Area() T
- func (r Rectangle[T]) Center() Point[T]
- func (r1 Rectangle[T]) Clip(r2 Rectangle[T]) Rectangle[T]
- func (r1 Rectangle[T]) Contains(r2 Rectangle[T]) bool
- func (r Rectangle[T]) ContainsPoint(pt Point[T]) bool
- func (r Rectangle[T]) Height() T
- func (r Rectangle[T]) IsZero() bool
- func (r Rectangle[T]) LT() Point[T]
- func (r1 Rectangle[T]) MergePoint(x, y T) Rectangle[T]
- func (r1 Rectangle[T]) Overlaps(r2 Rectangle[T]) bool
- func (r Rectangle[T]) RB() Point[T]
- func (r Rectangle[T]) Size() Point[T]
- func (r Rectangle[T]) String() string
- func (r Rectangle[T]) Translate(pt Point[T]) Rectangle[T]
- func (r1 Rectangle[T]) Union(r2 Rectangle[T]) Rectangle[T]
- func (r Rectangle[T]) Width() T
- func (r Rectangle[T]) WithExpand(v T) Rectangle[T]
- func (r Rectangle[T]) WithSize(pt Point[T]) Rectangle[T]
- type RngF
- type RngF32
- type RngF64
- type RngI
- type RngI64
- type SegF
- type SegF32
- type SegF64
- type SegFmtF
- type SegI
- type SegI64
- type Segment
- func (s Segment[T]) AddPt(pt Point[T]) Segment[T]
- func (s Segment[T]) AsArray() []Point[T]
- func (s Segment[T]) Degrees() float64
- func (s Segment[T]) Dir() Point[T]
- func (s Segment[T]) Interp(unit T) Point[T]
- func (s Segment[T]) Len() T
- func (s Segment[T]) LenSquared() T
- func (s Segment[T]) Midpoint() Point[T]
- func (s Segment[T]) PerpendicularSlope() Slope
- func (s Segment[T]) Slope() Slope
- type SliceSegFmtF
- type Slope
- type Tri3dF
- type Triangle3d
Constants ¶
This section is empty.
Variables ¶
var ( HorizontalSlope = Slope{Angle: Horizontal, M: 0.} VerticalSlope = Slope{Angle: Vertical, M: math.MaxFloat64} )
var RngFUnit = RngF{Min: 0., Max: 1.}
Functions ¶
func DegreesToRadians ¶
func Float64NearZero ¶
func FloatsEqual ¶
func FloatsEqualTol ¶
func IsCollinear ¶
IsCollinear checks if three points are collinear
func Min ¶
func Min[T Number](a, b T) T
Surely these are SOMEWHERE? TODO: Yes, builtin min() and max(), and they are highly optimized, perform the same as this. So remove these.
func NullHitTest ¶
func Orient ¶
Orient answers whether C is left / clockwise to direct segment AB. Response: 0: C is collinear < 0: C is left / clockwise > 0: C is right / counterclockwise
func Pt3dNearZero ¶
func RadiansToDegrees ¶
func RectsEqual ¶
func XAtY ¶
XAtY answers the X value for this segment at the given Y value, or false if the line does not intersect y.
func XYToIndex ¶
func XYToIndex[T constraints.Integer](width, height T, pt Point[T]) (T, error)
XYToIndex converts an X, Y to a flat index.
func XYToIndexFast ¶
func XYToIndexFast[T constraints.Integer](x, y, width T) T
XYToIndexFast converts an X, Y to a flat index without any bounds checking.
Types ¶
type BezF ¶
type BezF = QuadraticBezier
type CircleHitTest ¶
type CircleHitTest struct {
// contains filtered or unexported fields
}
func (*CircleHitTest) Hit ¶
func (t *CircleHitTest) Hit(pt PtF) bool
func (*CircleHitTest) Set ¶
func (t *CircleHitTest) Set(center PtF, radius float64)
func (*CircleHitTest) String ¶
func (t *CircleHitTest) String() string
type CubicBezier ¶
type CubicBezier struct {
P0, P1, P2, P3 PtF
}
CubicBezier represents a cubic Bezier curve.
func CubicBez ¶
func CubicBez(x0, y0, x1, y1, x2, y2, x3, y3 float64) CubicBezier
CubicBez is shorthand for creating a cubic bezier curve.
func (*CubicBezier) At ¶
func (bc *CubicBezier) At(t float64) PtF
At evaluates the Bezier curve at a given parameter t.
func (*CubicBezier) PointBounds ¶
func (bc *CubicBezier) PointBounds() RectF
PointBounds is the bounding box for my control points. It does not include any point that lies outside the controls.
type Float ¶
type Float interface { constraints.Float }
type Line ¶
https://github.com/vlecomte/cp-geo/blob/master/basics/line.tex
func LineFromDir ¶
From direction vector v and offset c
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
type Orientation ¶
type Orientation uint8
const ( Collinear Orientation = iota Clockwise CounterClockwise )
func RadialDist ¶
func RadialDist(a, b float64) (float64, Orientation)
RadialDist answers the distance between two unit values, accounting for wrapping. Andswer 0 - 1, with 1 being the two values are closest. Examples: a=.1, b=.9, distance is .2, i.e. it wraps around 1.
type Point ¶
type Point[T Number] struct { X T Y T }
func FindIntersection ¶
FindIntersection finds the intersection between two line segments. Note: I am finding cases where this doesn't work, where an intersection is found on some segments but if you scale one of the points further out, no intersection. From https://github.com/vlecomte/cp-geo/blob/master/basics/segment.tex Further note: This doesn't seem to find intersections exactly on end points. Further review of that page shows yes this is correct, there's a different algorithm to account for endpoints.
func IndexToXY ¶
func IndexToXY[T constraints.Integer](width, height, index T) (Point[T], error)
IndexToXY converts a flat index into an array into an XY position.
func PerpendicularIntersection ¶
PerpendicularIntersection finds the intersection of point to the line segment by drawing a perpendicular line from point to segment. Note: this is from Gemini. Seems to work but not heavily tested.
func (Point[T]) Degrees ¶
Degrees finds the angle of the segment with this point as the origin. Degrees will be 0-360, with 0/360 on the right, proceeding clockwise.
func (Point[T]) DistSquared ¶
Dist2 is the distance without the square root.
func (Point[T]) Normalize ¶
Normalize normalizs the point to a unit. Can be negative if they are generated from a negative point, i.e. a negative direction vector.
func (Point[T]) Project ¶
Given slope m and distance, project the positive and negative points on the line. Uses upper-left coordinate system.
func (Point[T]) ProjectDegree ¶
ProjectDegree takes a degree and distance and projects a new point.
func (Point[T]) Rotate ¶
Rotate the point. Rotation will be: In Quandrant 4 this rotates CW for positive angles and CCW for negative. TODO: API might be confusing, after not using it I've started thinking of the a point as the center and the point being passed in as the point to rotate. so might switch those.
type Point3d ¶
type Point3d[T Number] struct { X T Y T Z T }
func (Point3d[T]) Cross ¶
Cross calculates the cross product of two vectors and returns a new vector
func (Point3d[T]) DotProduct ¶
type PolygonBBF64 ¶
type ProcessPtF64Func ¶
type Pt3dF ¶
func LinePlaneIntersection ¶
type PtF ¶
func CubicBezierDistance ¶
func CubicBezierDistance(cb CubicBezier, pt PtF) (float64, PtF)
CubicBezierDistance approximates the distance from a point to a Bezier curve
func CubicBezierDistanceSquared ¶
func CubicBezierDistanceSquared(cb CubicBezier, pt PtF) (float64, PtF)
CubicBezierDistanceSquared approximates the distance from a point to a Bezier curve
func DegreesToDirectionCw ¶
DegreesToDirectionCcw converts degrees to a direction vector, where 0 = right and it continues clockwise, so 90 is down.
func DistPointToSegment ¶
DistPointToSegment answers the distance from the point to the segment, as well as the point found on the segment. From https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
func DistSquared ¶
DistSquared answers the squared distance from the point to the segment, as well as the point found on the segment. From https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
func LineLineIntersectionF ¶
LineLineIntersectionF provides the intersection of two lines. https://github.com/vlecomte/cp-geo/blob/master/basics/line.tex
func LineToSegIntersection ¶
https://stackoverflow.com/questions/34415671/intersection-of-a-line-with-a-line-segment-in-c line segment p-q intersect with line A-B. This looks a lot more efficient than the current seg-seg test I'm doing, but also I actually want a seg-seg test because this gives false positives. So... maybe I'll switch to it if I think of a way for it to make sense, but probably not because this is just a different operation.
func PtToSegIntersection_Off ¶
func QuadraticBezierDistanceBrute ¶
func QuadraticBezierDistanceBrute(cb QuadraticBezier, pt PtF) (float64, PtF)
QuadraticBezierDistanceBrute approximates the distance from a point to a Bezier curve
func QuadraticBezierDistanceSquared ¶
func QuadraticBezierDistanceSquared(cb QuadraticBezier, pt PtF) (float64, PtF)
QuadraticBezierDistanceSquared approximates the distance from a point to a Bezier curve
func QuadraticBezierDistanceSquaredBrute ¶
func QuadraticBezierDistanceSquaredBrute(cb QuadraticBezier, pt PtF) (float64, PtF)
QuadraticBezierDistanceSquaredBrute approximates the distance from a point to a Bezier curve
type QuadraticBezier ¶
type QuadraticBezier struct {
P0, P1, P2 PtF
}
QuadraticBezier represents a quadratic Bezier curve.
func Bez ¶
func Bez(x0, y0, x1, y1, x2, y2 float64) QuadraticBezier
Bez is shorthand for creating a quadratic bezier curve.
func QuadraticBez ¶
func QuadraticBez(x0, y0, x1, y1, x2, y2 float64) QuadraticBezier
QuadraticBez is shorthand for creating a quadratic bezier curve.
func (*QuadraticBezier) At ¶
func (b *QuadraticBezier) At(t float64) PtF
At evaluates the Bezier curve at a given parameter t.
func (*QuadraticBezier) PointBounds ¶
func (b *QuadraticBezier) PointBounds() RectF
PointBounds is the bounding box for my control points. It does not include any point that lies outside the controls.
type Range ¶
type Range[T Number] struct { Min T Max T }
func (Range[T]) Clamp ¶
func (p Range[T]) Clamp(value T) T
Clamp returns the value clipped to my range.
func (Range[T]) ClampFast ¶
func (r Range[T]) ClampFast(value T) T
ClampFast returns the value clipped to my range. It assumes Min is less than Max.
func (Range[T]) Clip ¶
func (p Range[T]) Clip(value T) T
Clip returns the value clipped to my range. TODO: Clamp() seems more common so switch to that.
func (Range[T]) Intersection ¶
Intersection returns the intersection of A and B ranges.
type Rectangle ¶
type Rectangle[T Number] struct { L, T, R, B T }
func PolygonBounds ¶
func (Rectangle[T]) ContainsPoint ¶
ContainsPoint returns true if the point is inside the half-closed rectangle.
func (Rectangle[T]) MergePoint ¶
MergePoint will expand the bounds to include the point.
func (Rectangle[T]) WithExpand ¶
Expand adds the value to all edges.
type Segment ¶
Segment represents a line segment with start and end points
func (Segment[T]) Degrees ¶
Degrees finds the angle of the segment with A as the origin. Degrees will be 0-360, with 0/360 on the right, proceeding clockwise.
func (Segment[T]) Interp ¶
Interp answers a new point at the unit position on this segment, where 0. = A and 1. = B. Note this really only works on floats, need a way to narrow that constraint.
func (Segment[T]) LenSquared ¶
func (s Segment[T]) LenSquared() T
LenSquared answers the squared length of this segment.
func (Segment[T]) PerpendicularSlope ¶
PerpendicularSlope answers the perpendicular of Slope.
type SliceSegFmtF ¶
type SliceSegFmtF struct {
Segs []SegF
}
func (SliceSegFmtF) String ¶
func (f SliceSegFmtF) String() string
type Tri3dF ¶
type Tri3dF = Triangle3d[float64]
type Triangle3d ¶
func Tri3d ¶
func Tri3d[T Number](a, b, c Point3d[T]) Triangle3d[T]
Tri3d is shorthand for creating a triangle.
func Tri3dFlat ¶
func Tri3dFlat[T Number](ax, ay, az, bx, by, bz, cx, cy, cz T) Triangle3d[T]
func (Triangle3d[T]) Center ¶
func (t Triangle3d[T]) Center() Point3d[T]
func (Triangle3d[T]) SurfaceNormal ¶
func (t Triangle3d[T]) SurfaceNormal() Point3d[T]
https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal