Versions in this module Expand all Collapse all v1 v1.2.0 Sep 23, 2026 Changes in this version type Shape + func (sh *Shape) SetHeight(h float64) + func (sh *Shape) SetWidth(w float64) v1.1.0 Sep 16, 2026 v1.0.4 Sep 16, 2026 v1.0.3 Sep 11, 2026 v1.0.2 Sep 9, 2026 v1.0.1 Sep 9, 2026 v1.0.0 Sep 9, 2026 Changes in this version + const Pi + const Tau + var Infinity = math.Inf(1) + var Vec2One = Vec2 + func CalcSpringTension(a, b Vec2, rd RestDistance) float64 + func DefaultCollisionFilterFunc(info CollisionInfo, normalVelocity float64) bool + func StiffnessDampingFrom(mass, softness float64) (stiffness, damping float64) + type AABB struct + Max Vec2 + Min Vec2 + Valid bool + func NewAABB(min, max Vec2) AABB + func NewAABBFromPoints(points []Vec2) (aabb AABB) + func NewAABBOf(points ...Vec2) AABB + func (a *AABB) Clear() + func (a *AABB) ExpandToInclude(point Vec2) + func (a *AABB) ExpandToIncludePoints(points []Vec2) + func (a AABB) Contains(point Vec2) bool + func (a AABB) Expanded(margin float64) AABB + func (a AABB) Intersects(box AABB) bool + type Bitmask uint64 + func (b *Bitmask) SetOn(index int) + type Body struct + AABB AABB + BaseShape Shape + Bitmask Bitmask + BitmaskX Bitmask + BitmaskY Bitmask + Components []Component + DerivedAngle float64 + DerivedOmega float64 + DerivedPos Vec2 + DerivedVel Vec2 + Edges []*BodyEdge + FreeRotate bool + GlobalShape Shape + IsKinematic bool + IsPinned bool + IsStatic bool + Joints []Joint + Material int + PointMasses []*PointMass + Scale Vec2 + UserData any + VelDamping float64 + func NewBody(shape Shape, pos Vec2, angle, mass float64, world ...*World) *Body + func NewStaticBody(shape Shape, pos Vec2, angle float64, world ...*World) *Body + func (b *Body) AccumulateExternalForces(world *World) + func (b *Body) AccumulateInternalForces(relaxing bool) + func (b *Body) AddAngularVelocity(vel float64) + func (b *Body) AddComponent(comp Component) + func (b *Body) AddVelocity(velocity Vec2) + func (b *Body) AddVelocityToPointAt(velocity Vec2, pointMassIndex int) + func (b *Body) ApplyForceAtGlobalPoint(force Vec2, pt Vec2) + func (b *Body) ApplyForceToPointAt(force Vec2, pointMassIndex int) + func (b *Body) ApplyGlobalForce(force Vec2) + func (b *Body) ApplyTorque(force float64) + func (b *Body) ClosestEdge(point Vec2, tolerance float64) (edgePosition Vec2, edgeRatio float64, edgePoint1, edgePoint2 int, ok bool) + func (b *Body) ClosestPoint(pt Vec2) (hitPoint, normal Vec2, pointA, pointB int, edgeD, distance float64) + func (b *Body) ClosestPointMass(pos Vec2) (point int, distance float64) + func (b *Body) ClosestPointOnEdge(pt Vec2, edgeNum int) (hitPoint, normal Vec2, edgeD, distance float64) + func (b *Body) ClosestPointOnEdgeSq(pt Vec2, edgeNum int) (hitPoint, normal Vec2, edgeD, distance float64) + func (b *Body) Contains(pt Vec2) bool + func (b *Body) DampenVelocity(elapsed float64) + func (b *Body) DerivePositionAndAngle(elapsed float64) + func (b *Body) GetComponent[T Component]() (component T) + func (b *Body) Integrate(elapsed float64) + func (b *Body) IntersectsLine(start, end Vec2) bool + func (b *Body) PointMass(pointMassIndex int) *PointMass + func (b *Body) Raycast(start, end Vec2) (closestHit Vec2, ok bool) + func (b *Body) RemoveComponent(comp Component) + func (b *Body) Reset() + func (b *Body) SetAngularVelocity(vel float64) + func (b *Body) SetAverageVelocity(velocity Vec2) + func (b *Body) SetMassAll(mass float64) + func (b *Body) SetMassByIndex(pointMassIndex int, mass float64) + func (b *Body) SetMassesFromSlice(masses []float64) + func (b *Body) SetPointPositionAt(position Vec2, pointMassIndex int) + func (b *Body) SetPointVelocityAt(velocity Vec2, pointMassIndex int) + func (b *Body) SetScaleAnglePosition(scale Vec2, angle float64, pos Vec2) + func (b *Body) SetShape(shape Shape) + func (b *Body) TranslatePointAt(offset Vec2, i int) + func (b *Body) UpdateAABB(elapsed float64, forceUpdate bool) + type BodyEdge struct + Difference Vec2 + EdgeIndex int + End Vec2 + EndPointIndex int + Length float64 + LengthSquared float64 + Normal Vec2 + Start Vec2 + StartPointIndex int + func NewBodyEdge(edgeIndex, startPointIndex, endPointIndex int, start, end Vec2) *BodyEdge + type BodyJointLink struct + func NewBodyJointLink(body *Body) *BodyJointLink + func (b *BodyJointLink) AddVelocity(velocity Vec2) + func (b *BodyJointLink) ApplyForce(force Vec2) + func (b *BodyJointLink) Body() *Body + func (b *BodyJointLink) IsStatic() bool + func (b *BodyJointLink) Mass() (totalMass float64) + func (b *BodyJointLink) Position() Vec2 + func (b *BodyJointLink) Translate(offset Vec2) + func (b *BodyJointLink) Velocity() Vec2 + type CollisionInfo struct + BodyA *Body + BodyApm int + BodyB *Body + BodyBpmA int + BodyBpmB int + EdgeD float64 + HitPt Vec2 + Normal Vec2 + Penetration float64 + func NewCollisionInfo(bodyA *Body, bodyApm int, bodyB *Body) CollisionInfo + func NewCollisionInfoWithEdge(bodyA *Body, bodyApm int, bodyB *Body, bodyBpmA, bodyBpmB int) CollisionInfo + type CollisionObserver interface + BodiesDidCollide func(infos []CollisionInfo) + BodyCollision func(info CollisionInfo, penetrationThreshold float64) + type Component interface + AccumulateExternalForces func(body *Body, world *World) + AccumulateInternalForces func(body *Body, worldRelaxing bool) + Disabled func() bool + Prepare func(body *Body) + type EdgeJointLink struct + EdgeRatio float64 + func NewEdgeJointLink(body *Body, edgeIndex int, edgeRatio ...float64) *EdgeJointLink + func (b *EdgeJointLink) Body() *Body + func (e *EdgeJointLink) AddVelocity(velocity Vec2) + func (e *EdgeJointLink) ApplyForce(force Vec2) + func (e *EdgeJointLink) IsStatic() bool + func (e *EdgeJointLink) Mass() (totalMass float64) + func (e *EdgeJointLink) Position() Vec2 + func (e *EdgeJointLink) Translate(offset Vec2) + func (e *EdgeJointLink) Velocity() Vec2 + type GravityComponent struct + Gravity Vec2 + Relaxable bool + func NewGravityComponent(gravityX, gravityY float64, relaxable bool) *GravityComponent + func (b *GravityComponent) AccumulateInternalForces(body *Body, worldRelaxing bool) + func (b *GravityComponent) Disabled() bool + func (b *GravityComponent) Prepare(body *Body) + func (g *GravityComponent) AccumulateExternalForces(body *Body, world *World) + type InternalSpring struct + PointMassA int + PointMassB int + func NewInternalSpring(pmA int, pmB int, distance RestDistance, stiffness float64, damping float64, ...) *InternalSpring + type Joint interface + CollisionsAllowed func() bool + LinkA func() JointLink + LinkB func() JointLink + Resolve func(dt float64) + type JointLink interface + AddVelocity func(velocity Vec2) + ApplyForce func(force Vec2) + Body func() *Body + IsStatic func() bool + Mass func() float64 + Position func() Vec2 + Translate func(offset Vec2) + Velocity func() Vec2 + type LineIntersectResult struct + HitPt Vec2 + Ua float64 + Ub float64 + func LineIntersect(aStart, aEnd, bStart, bEnd Vec2) (LineIntersectResult, bool) + type MaterialPair struct + Collide bool + CollisionFilterFunc func(info CollisionInfo, normalVelocity float64) bool + Elasticity float64 + Friction float64 + func DefaultMaterialPair() MaterialPair + type Matrix3x3 struct + func NewMatrix3x3(scale Vec2, angle float64, pos Vec2) Matrix3x3 + func (g *Matrix3x3) Clear() + func (g *Matrix3x3) Rotate(theta float64) + func (g *Matrix3x3) Scale(x, y float64) + func (g *Matrix3x3) Translate(tx, ty float64) + func (g Matrix3x3) Apply(v Vec2) Vec2 + type PinJoint struct + MaxCorrection float64 + func NewPinJoint(a, b JointLink, maxCorrection float64) *PinJoint + func (j *PinJoint) CollisionsAllowed() bool + func (j *PinJoint) LinkA() JointLink + func (j *PinJoint) LinkB() JointLink + func (j *PinJoint) Resolve(dt float64) + type PointJointLink struct + func NewPointJointLink(body *Body, pointMassIndex int) *PointJointLink + func (b *PointJointLink) Body() *Body + func (p *PointJointLink) AddVelocity(velocity Vec2) + func (p *PointJointLink) ApplyForce(force Vec2) + func (p *PointJointLink) IsStatic() bool + func (p *PointJointLink) Mass() (totalMass float64) + func (p *PointJointLink) Position() Vec2 + func (p *PointJointLink) Translate(offset Vec2) + func (p *PointJointLink) Velocity() Vec2 + type PointMass struct + Force Vec2 + Mass float64 + Normal Vec2 + Position Vec2 + Velocity Vec2 + func NewPointMass(mass float64, position Vec2) *PointMass + func (p *PointMass) ApplyForce(force Vec2) + func (p *PointMass) Integrate(elapsed float64) + type PressureComponent struct + GasPressure float64 + Volume float64 + func NewPressureComponent(gasPressure float64) *PressureComponent + func (b *PressureComponent) AccumulateExternalForces(body *Body, world *World) + func (b *PressureComponent) Disabled() bool + func (b *PressureComponent) Prepare(body *Body) + func (p *PressureComponent) AccumulateInternalForces(body *Body, relaxing bool) + type Resolver interface + Resolve func(dt float64) + type RestDistance struct + Fixed float64 + IsRanged bool + func CalcPlasticity(dist float64, rd RestDistance, sp *SpringPlasticity) RestDistance + func NewFixedRestDistance(value float64) RestDistance + func NewRangedRestDistance(min, max float64) RestDistance + func (r *RestDistance) MaxDist() float64 + func (r *RestDistance) MinDist() float64 + func (r *RestDistance) SetMaxDist(value float64) + func (r *RestDistance) SetMinDist(value float64) + func (r RestDistance) Clamp(value float64) float64 + func (r RestDistance) InRange(value float64) bool + func (r RestDistance) Squared() RestDistance + type Shape []Vec2 + func Rectangle(w, h float64, cornerRatio ...float64) (s Shape) + func RegularPolygon(radius float64, n int) (s Shape) + func ShapeFromCoords(coords ...float64) (s Shape) + func ShapeFromSVGPath(path string) Shape + func ShapeFromSVGPolygonPoints(points string) (s Shape) + func Square(length float64) Shape + func (c *Shape) AddVertex(pos Vec2) + func (c *Shape) AddVertexXY(x, y float64) + func (c *Shape) Clone() Shape + func (c *Shape) FitHeight(h float64) + func (c *Shape) FitWidth(w float64) + func (c *Shape) Recenter() + func (c *Shape) Reverse() + func (c *Shape) Scale(x, y float64) + func (c *Shape) TransformByMatrix(m Matrix3x3) + func (c *Shape) TransformByMatrixToTarget(target []Vec2, matrix Matrix3x3) + func (c *Shape) TranslateVerticesToTarget(target Shape, pos Vec2) + func (c Shape) IsCCW() bool + func (s Shape) PolygonPointsString(precision int) string + type ShapeJointLink struct + Indexes []int + Offset Vec2 + func NewShapeJointLink(body *Body, pointMassIndexes []int) *ShapeJointLink + func (b *ShapeJointLink) Body() *Body + func (s *ShapeJointLink) AddVelocity(velocity Vec2) + func (s *ShapeJointLink) ApplyForce(force Vec2) + func (s *ShapeJointLink) IsStatic() bool + func (s *ShapeJointLink) Mass() (mass float64) + func (s *ShapeJointLink) Position() Vec2 + func (s *ShapeJointLink) SubDerivedAngle() float64 + func (s *ShapeJointLink) Translate(offset Vec2) + func (s *ShapeJointLink) Velocity() (vel Vec2) + type ShapeMatchComponent struct + Damping float64 + Stiffness float64 + TargetIndices []int + func DefaultShapeMatchComponent() *ShapeMatchComponent + func NewShapeMatchComponent(stiffness, damping float64, indices []int) *ShapeMatchComponent + func (b *ShapeMatchComponent) AccumulateExternalForces(body *Body, world *World) + func (b *ShapeMatchComponent) Disabled() bool + func (b *ShapeMatchComponent) Prepare(body *Body) + func (s *ShapeMatchComponent) AccumulateInternalForces(body *Body, relaxing bool) + func (s *ShapeMatchComponent) SetTarget(indices []int) + type Spring struct + Damping float64 + Plasticity *SpringPlasticity + RestDistance RestDistance + Stiffness float64 + Type SpringType + func (s *Spring) UpdatePlasticity(distance float64) + type SpringComponent struct + DefaultDamping float64 + DefaultStiffness float64 + EdgeSpringsCount int + Springs []*InternalSpring + func DefaultSpringComponent() *SpringComponent + func NewSpringComponent(stiffness, damping float64) *SpringComponent + func (b *SpringComponent) AccumulateExternalForces(body *Body, world *World) + func (b *SpringComponent) Disabled() bool + func (s *SpringComponent) AccumulateInternalForces(body *Body, relaxing bool) + func (s *SpringComponent) AddExtraSpring(body *Body, pointA, pointB int, stiffness, damping float64, ...) *InternalSpring + func (s *SpringComponent) ApplyDefaults() + func (s *SpringComponent) ClearAllSprings(body *Body) + func (s *SpringComponent) Prepare(body *Body) + func (s *SpringComponent) SetAll(stiffness, damping float64) + func (s *SpringComponent) SetAllEdges(stiffness, damping float64) + func (s *SpringComponent) SetExtraAt(relativeIndex int, stiffness, damping float64) + func (s *SpringComponent) SetSpringPlasticity(relativeIndex int, plasticity *SpringPlasticity) + type SpringJoint struct + func NewSpringJoint(a, b JointLink, coefficient, damping float64, distance ...RestDistance) *SpringJoint + func (j *SpringJoint) CollisionsAllowed() bool + func (j *SpringJoint) LinkA() JointLink + func (j *SpringJoint) LinkB() JointLink + func (j *SpringJoint) Resolve(dt float64) + func (j *SpringJoint) SetPlasticity(p *SpringPlasticity) + type SpringPlasticity struct + Limit float64 + Rate float64 + YieldRatio float64 + func DefaultSpringPlasticity() *SpringPlasticity + func NewSpringPlasticity(yieldRatio float64, rate float64, limit float64) *SpringPlasticity + type SpringType uint8 + const EdgeSpring + const ExtraSpring + const JointSpring + type StickyRayComponent struct + Damping float64 + IgnoreJoinedBodies bool + RayLength float64 + Stiffness float64 + func DefaultStickyRayComponent() *StickyRayComponent + func NewStickyRayComponent(rayLength, stiffness, damping float64, ignoreJoinedBodies bool) *StickyRayComponent + func (b *StickyRayComponent) AccumulateInternalForces(body *Body, worldRelaxing bool) + func (b *StickyRayComponent) Disabled() bool + func (b *StickyRayComponent) Prepare(body *Body) + func (s *StickyRayComponent) AccumulateExternalForces(body *Body, world *World) + type UnimplementedCollisionObserver struct + func (u *UnimplementedCollisionObserver) BodiesDidCollide(infos []CollisionInfo) + func (u *UnimplementedCollisionObserver) BodyCollision(info CollisionInfo, penetrationThreshold float64) + type Vec2 struct + X float64 + Y float64 + func AveragePointMassPosition(pointMasses []*PointMass) (centroid Vec2) + func AveragePointMassVelocity(pointMasses []*PointMass) (average Vec2) + func AverageVec2(vectors []Vec2) (average Vec2) + func CalcSpringForce(posA, velA, posB, velB Vec2, distance, stiffness, damping float64) Vec2 + func FromAngle(angle float64) Vec2 + func (v Vec2) Abs() Vec2 + func (v Vec2) AbsX() float64 + func (v Vec2) AbsY() float64 + func (v Vec2) Add(a Vec2) Vec2 + func (v Vec2) AddX(n float64) Vec2 + func (v Vec2) AddY(n float64) Vec2 + func (v Vec2) Angle() float64 + func (v Vec2) AngleTo(other Vec2) float64 + func (v Vec2) Ceil() Vec2 + func (v Vec2) Cross(other Vec2) float64 + func (v Vec2) Dist(other Vec2) float64 + func (v Vec2) DistSq(other Vec2) float64 + func (v Vec2) Div(a Vec2) Vec2 + func (v Vec2) DivS(s float64) Vec2 + func (v Vec2) Dot(other Vec2) float64 + func (v Vec2) Equals(other Vec2) bool + func (v Vec2) EqualsPr(other Vec2, allowedDelta float64) bool + func (v Vec2) Floor() Vec2 + func (v Vec2) IsZero() bool + func (v Vec2) Lerp(other Vec2, t float64) Vec2 + func (v Vec2) Limit(max float64) Vec2 + func (v Vec2) Mag() float64 + func (v Vec2) MagSq() float64 + func (v Vec2) Max(other Vec2) Vec2 + func (v Vec2) Min(other Vec2) Vec2 + func (v Vec2) Mul(a Vec2) Vec2 + func (v Vec2) Neg() Vec2 + func (v Vec2) NegX() Vec2 + func (v Vec2) NegY() Vec2 + func (v Vec2) Perp() Vec2 + func (v Vec2) Project(other Vec2) Vec2 + func (v Vec2) Reflect(normal Vec2) Vec2 + func (v Vec2) Rotate(angle float64) Vec2 + func (v Vec2) Round() Vec2 + func (v Vec2) Scale(s float64) Vec2 + func (v Vec2) SetMag(m float64) Vec2 + func (v Vec2) Slerp(to Vec2, weight float64) Vec2 + func (v Vec2) String() string + func (v Vec2) Sub(a Vec2) Vec2 + func (v Vec2) Unit() Vec2 + type World struct + Bodies []*Body + CollisionObserver CollisionObserver + DefaultMatPair MaterialPair + Joints []Joint + MaterialPairs [][]MaterialPair + PenetrationThreshold float64 + func NewWorld() *World + func (w *World) AddBodies(bodies ...*Body) + func (w *World) AddBody(body *Body) + func (w *World) AddJoint(joint Joint) + func (w *World) AddMaterial() int + func (w *World) AreBodiesJoined(body1, body2 *Body) bool + func (w *World) BodiesIntersectingLine(start, end Vec2, bitmask Bitmask) []*Body + func (w *World) BodiesIntersectingShape(shape Shape, worldPos Vec2, ignoreTest func(*Body) bool, outResults []*Body, ...) []*Body + func (w *World) BodiesUnder(pt Vec2, bitmask Bitmask) []*Body + func (w *World) BodyUnder(pt Vec2, bitmask Bitmask) *Body + func (w *World) ClosestPoint(pt Vec2, ignoreFunction func(*Body) bool) (closestBody *Body, closestHitPoint Vec2, found bool) + func (w *World) ClosestPointMass(pt Vec2, ignoreFunction func(*Body, int) bool) (*Body, int, bool) + func (w *World) IsRelaxing() bool + func (w *World) RayCast(start, end Vec2, bitmask Bitmask, ignoreTest func(*Body) bool) (retPt Vec2, body *Body) + func (w *World) RelaxBodies(bodies []*Body, timestep float64, iterations int) + func (w *World) RelaxWorld(timestep float64, iterations int) + func (w *World) RemoveBody(body *Body) + func (w *World) RemoveJoint(joint Joint) + func (w *World) Reset() + func (w *World) SetMaterialPairCollide(a, b int, collide bool) + func (w *World) SetMaterialPairData(a, b int, friction, elasticity float64) + func (w *World) SetMaterialPairFilterCallback(a, b int, filter func(CollisionInfo, float64) bool) + func (w *World) SetWorldLimits(min, max Vec2) + func (w *World) Update(elapsed float64) + func (w *World) WorldLimits() AABB