Skip to content

Commit

Permalink
Merge pull request #30 from setanarut/master
Browse files Browse the repository at this point in the history
Fixes (go-staticcheck problems)
  • Loading branch information
setanarut authored Jan 6, 2024
2 parents 8f52a70 + 93cd6aa commit e672e20
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion bbtree_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cp

import "testing"
import (
"testing"
)

func TestBBTree_GetMasterTree(t *testing.T) {
bbTree := &BBTree{}
Expand All @@ -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()
}

Expand Down
6 changes: 3 additions & 3 deletions constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +25,7 @@ type Constraint struct {
PreSolve ConstraintPreSolveFunc
PostSolve ConstraintPostSolveFunc

userData interface{}
UserData interface{}
}

func NewConstraint(class Constrainer, a, b *Body) *Constraint {
Expand Down Expand Up @@ -91,4 +91,4 @@ func (c *Constraint) Next(body *Body) *Constraint {
func (c *Constraint) SetCollideBodies(collideBodies bool) {
c.ActivateBodies()
c.collideBodies = collideBodies
}
}
4 changes: 1 addition & 3 deletions draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cp

import "fmt"

//Draw flags
// Draw flags
const (
DRAW_SHAPES = 1 << 0
DRAW_CONSTRAINTS = 1 << 1
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jakecoffman/cp/v2

go 1.18
go 1.21.5
4 changes: 2 additions & 2 deletions march.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions polyline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions space.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e672e20

Please sign in to comment.