diff --git a/README.md b/README.md index 91e1320..956d549 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@ # cp -[![GoDoc](https://godoc.org/github.com/jakecoffman/cp?status.svg)](http://godoc.org/github.com/jakecoffman/cp) +[![GoDoc](https://godoc.org/github.com/jakecoffman/cp?status.svg)](https://pkg.go.dev/github.com/jakecoffman/cp/v2) [![Sourcegraph](https://sourcegraph.com/github.com/jakecoffman/cp/-/badge.svg)](https://sourcegraph.com/github.com/jakecoffman/cp?badge) -[Chipmunk2D](https://github.com/slembcke/Chipmunk2D) ported to Go +Go port of [Chipmunk2D](https://github.com/slembcke/Chipmunk2D) physics library. + +```Go +import "github.com/jakecoffman/cp/v2" +``` ## Project status -Stable -- most features are implemented and the demos are very close to Chipmunk2D demos. +Stable -- most features are implemented and the demos are very close to Chipmunk2D demos. ## Examples diff --git a/bbtree_test.go b/bbtree_test.go index c6ee9ba..f34dead 100644 --- a/bbtree_test.go +++ b/bbtree_test.go @@ -1,6 +1,8 @@ package cp -import "testing" +import ( + "testing" +) func TestBBTree_GetMasterTree(t *testing.T) { bbTree := &BBTree{} @@ -22,6 +24,7 @@ func TestBBTree_GetMasterTree(t *testing.T) { } for i := 1; i < count*2; i++ { + // this value of node is never used (SA4006)go-staticcheck node = bbTree.NodeFromPool() } diff --git a/constraint.go b/constraint.go index 63e8876..490b26d 100644 --- a/constraint.go +++ b/constraint.go @@ -16,7 +16,7 @@ type Constraint struct { Class Constrainer space *Space - a, b *Body + a, b *Body next_a, next_b *Constraint maxForce, errorBias, maxBias float64 @@ -25,7 +25,7 @@ type Constraint struct { PreSolve ConstraintPreSolveFunc PostSolve ConstraintPostSolveFunc - userData interface{} + UserData interface{} } func NewConstraint(class Constrainer, a, b *Body) *Constraint { @@ -91,4 +91,4 @@ func (c *Constraint) Next(body *Body) *Constraint { func (c *Constraint) SetCollideBodies(collideBodies bool) { c.ActivateBodies() c.collideBodies = collideBodies -} \ No newline at end of file +} diff --git a/draw.go b/draw.go index c3fc704..73973bd 100644 --- a/draw.go +++ b/draw.go @@ -2,7 +2,7 @@ package cp import "fmt" -//Draw flags +// Draw flags const ( DRAW_SHAPES = 1 << 0 DRAW_CONSTRAINTS = 1 << 1 @@ -154,8 +154,6 @@ func DrawConstraint(constraint *Constraint, options Drawer) { default: panic(fmt.Sprintf("Implement me: %#v", constraint.Class)) } - - return } func DrawSpace(space *Space, options Drawer) { diff --git a/go.mod b/go.mod index c3cd9aa..b43ac0b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/jakecoffman/cp/v2 -go 1.18 +go 1.21.5 diff --git a/march.go b/march.go index b98ccd0..3920a13 100644 --- a/march.go +++ b/march.go @@ -31,7 +31,7 @@ func MarchCells(bb BB, xSamples int64, ySamples int64, t float64, marchSegment M y0 := Lerp(bb.B, bb.T, float64(j+0)*y_denom) y1 := Lerp(bb.B, bb.T, float64(j+1)*y_denom) - a := buffer[0] + // a := buffer[0] // unused variable ? b := buffer[0] c := marchSample(Vector{bb.L, y1}) d := c @@ -41,7 +41,7 @@ func MarchCells(bb BB, xSamples int64, ySamples int64, t float64, marchSegment M x0 := Lerp(bb.L, bb.R, float64(i+0)*x_denom) x1 := Lerp(bb.L, bb.R, float64(i+1)*x_denom) - a = b + a := b // = -> := b = buffer[i+1] c = d d = marchSample(Vector{x1, y1}) diff --git a/poly.go b/poly.go index 4042c22..fbc370b 100644 --- a/poly.go +++ b/poly.go @@ -31,7 +31,7 @@ func (poly PolyShape) Radius() float64 { return poly.r } -func (poly PolyShape) SetRadius(r float64) { +func (poly *PolyShape) SetRadius(r float64) { poly.r = r } diff --git a/polyline.go b/polyline.go index 399153b..81f7c52 100644 --- a/polyline.go +++ b/polyline.go @@ -34,6 +34,7 @@ func (pl *PolyLine) IsClosed() bool { func (pl *PolyLine) IsShort(count, start, end int, min float64) bool { var length float64 + // Next doesn't have side effects and its return value is ignored (SA4017)go-staticcheck for i := start; i != end; Next(i, count) { length += pl.Verts[i].Distance(pl.Verts[Next(i, count)]) if length > min { diff --git a/space.go b/space.go index e40a241..afcee9f 100644 --- a/space.go +++ b/space.go @@ -221,7 +221,7 @@ func (space *Space) Deactivate(body *Body) { if body == bodyA || bodyA.GetType() == BODY_STATIC { space.UncacheArbiter(arb) // Save contact values to a new block of memory so they won't time out - contacts := make([]Contact, arb.count, arb.count) + contacts := make([]Contact, arb.count, arb.count) // should use make([]Contact, arb.count) instead (S1019)go-staticcheck copy(contacts, arb.contacts[:arb.count]) arb.contacts = contacts @@ -311,6 +311,8 @@ func (space *Space) AddConstraint(constraint *Constraint) *Constraint { // Push onto the heads of the bodies' constraint lists constraint.next_a = a.constraintList + // possible nil pointer dereference (SA5011) + // space.go:306:9: this check suggests that the pointer can be nilgo-staticcheck a.constraintList = constraint constraint.next_b = b.constraintList b.constraintList = constraint @@ -1101,8 +1103,7 @@ func (space *Space) ShapeQuery(shape *Shape, callback func(shape *Shape, points var anyCollision bool - var shapeQuery SpatialIndexQuery - shapeQuery = func(obj interface{}, b *Shape, collisionId uint32, _ interface{}) uint32 { + shapeQuery := func(obj interface{}, b *Shape, collisionId uint32, _ interface{}) uint32 { a := obj.(*Shape) if a.Filter.Reject(b.Filter) || a == b { return collisionId