Documentation ¶
Index ¶
- func DegreesToRadians(degrees float64) float64
- func DistanceFromPointToSegment[T Number](p Point[T], s Segment[T]) float64
- func FloatsEqual(a, b float64) bool
- 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(PointF64) bool
- func OnSegment[T Number](p, start, end Point[T]) bool
- func Orientation[T Number](p0, p1, p2 Point[T]) int
- func RadiansToDegrees(radians float64) float64
- func Ratio(a, b float64) float64
- func Sqr[T Number](x T) T
- func XAtY(s SegmentF64, y float64) (float64, bool)
- func XYToIndex[T constraints.Integer](width, height T, pt Point[T]) (T, error)
- type CircleHitTest
- type Float
- type HitTest
- type Number
- 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 FindIntersectionBAD[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 (a Point[T]) Add(b Point[T]) Point[T]
- func (p Point[T]) Area() 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]) Inside(r RectT[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]) Sub(b Point[T]) Point[T]
- func (p Point[T]) ToIndex(xy Point[T]) T
- type Point3d
- type Point3dF64
- type Point3dI
- type Point3dI64
- type Point3dUI64
- type PointF32
- type PointF64
- type PointI
- type PointI64
- type PointUI64
- type Poly
- type PolyF64
- type PolyI
- type PolyI64
- type PolyUI64
- type PolygonBB
- type PolygonBBF64
- type ProcessPtF64Func
- type Range
- type RangeF64
- type RangeI
- type RangeI64
- type RectF32
- type RectF64
- type RectI
- type RectI64
- type RectT
- func (r1 RectT[T]) Add(l, t, r, b T) RectT[T]
- func (r RectT[T]) Area() T
- func (r RectT[T]) LT() Point[T]
- func (r RectT[T]) RB() Point[T]
- func (r RectT[T]) Size() Point[T]
- func (r RectT[T]) Translate(pt Point[T]) RectT[T]
- func (r1 RectT[T]) Union(r2 RectT[T]) RectT[T]
- func (r RectT[T]) WithExpand(v T) RectT[T]
- func (r RectT[T]) WithSize(pt Point[T]) RectT[T]
- type RectUI64
- type Segment
- type SegmentF64
- type SegmentI
- type SegmentI64
- type SegmentUI64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DegreesToRadians ¶
func DistanceFromPointToSegment ¶
DistanceFromPointToSegment calculates the distance from a point to a line segment Ugh, what a mess. I guess this is obsoleted by DistPointToSegment, although I don't see why this couldn't answer return the point. And then I suppose I should see if there are differenecs in result and speed to decide which to keep. Although looking at the implementation, it sorta looks like it's just a distance to the closest endpoint? Which seems completely wrong?
func FloatsEqual ¶
func IsCollinear ¶
IsCollinear checks if three points are collinear
func NullHitTest ¶
func Orientation ¶
Orientation checks the orientation of three points
func RadiansToDegrees ¶
Types ¶
type CircleHitTest ¶
type CircleHitTest struct {
// contains filtered or unexported fields
}
func (*CircleHitTest) Hit ¶
func (t *CircleHitTest) Hit(pt PointF64) bool
func (*CircleHitTest) Set ¶
func (t *CircleHitTest) Set(center PointF64, radius float64)
func (*CircleHitTest) String ¶
func (t *CircleHitTest) String() string
type Float ¶
type Float interface { constraints.Float }
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
type Point ¶
type Point[T Number] struct { X T Y T }
func FindIntersectionBAD ¶
Actually, the answers everyone have given you so far are not optimal. They are imprecise, and so are not guaranteed to work on integer coordinates. Also, they are way too complicated.
Taken from Victor Lecomte's fabulous handbook, and modified for simplicity, this C++ function properInter returns whether there is an intersection between segments AB and CD:
struct pt { int x, int y };
int cross(pt a, pt b) { return a.x*b.y - a.y*b.x; }
int orient(pt a, pt b, pt c) { return cross(b-a, c-a); }
bool properInter(pt a, pt b, pt c, pt d) { int oa = orient(c,d,a), ob = orient(c,d,b), oc = orient(a,b,c), od = orient(a,b,d); // Proper intersection exists iff opposite signs return (oa*ob < 0 && oc*od < 0); }
FindIntersection finds the intersection point of two line segments
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]) Project ¶
Given slope m and distance, project the positive and negative points on the line. https://stackoverflow.com/questions/1250419/finding-points-on-a-line-with-a-given-distance
func (Point[T]) ProjectDegree ¶
ProjectDegree takes a degree and distance and projects a new point.
type Point3dF64 ¶
type Point3dI64 ¶
type Point3dUI64 ¶
type PointF64 ¶
func DistPointToSegment ¶
func DistPointToSegment(seg SegmentF64, p PointF64) (float64, PointF64)
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 ¶
func DistSquared(seg SegmentF64, p PointF64) (float64, PointF64)
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
type PolygonBBF64 ¶
type ProcessPtF64Func ¶
type Range ¶
type Range[T Number] struct { Min T Max T }
func (Range[T]) Clip ¶
func (p Range[T]) Clip(value T) T
Clip returns the value clipped to my range.
type RectT ¶
type RectT[T Number] struct { L, T, R, B T }
func PolygonBounds ¶
func (RectT[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]) PerpendicularSlope ¶
PerpendicularSlope answers the perpendicular of Slope.