Skip to content

Commit

Permalink
Merge pull request #17 from gabstv/nodestroy
Browse files Browse the repository at this point in the history
Fixes BBTree NodeFromPool() and removes ObjectiveC `Destroy()` methods
  • Loading branch information
jakecoffman authored May 20, 2020
2 parents 71b6e83 + 1516094 commit 75dd8f3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 36 deletions.
8 changes: 3 additions & 5 deletions bbtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ func NewBBTree(bbfunc SpatialIndexBB, staticIndex *SpatialIndex) *SpatialIndex {
return bbtree.spatialIndex
}

func (tree *BBTree) Destroy() {
panic("implement me")
}

func (tree *BBTree) Count() int {
return int(tree.leaves.Count())
}
Expand Down Expand Up @@ -518,7 +514,9 @@ func (tree *BBTree) NodeFromPool() *Node {
tree.RecycleNode(&Node{})
}

return &Node{}
return &Node{
parent: tree.pooledNodes,
}
}

func (tree *BBTree) RecycleNode(node *Node) {
Expand Down
6 changes: 1 addition & 5 deletions circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func (circle *Circle) CacheData(transform Transform) BB {
return NewBBForCircle(circle.tc, circle.r)
}

func (*Circle) Destroy() {
panic("implement me")
}

func (circle *Circle) Radius() float64 {
return circle.r
}
Expand Down Expand Up @@ -83,7 +79,7 @@ func CircleSegmentQuery(shape *Shape, center Vector, r1 float64, a, b Vector, r2
det := qb*qb - qa*(da.Dot(da)-rsum*rsum)

if det >= 0 {
t := (-qb - math.Sqrt(det))/qa
t := (-qb - math.Sqrt(det)) / qa
if 0 <= t && t <= 1 {
n := da.Lerp(db, t).Normalize()

Expand Down
26 changes: 11 additions & 15 deletions poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func (poly *PolyShape) CacheData(transform Transform) BB {
return poly.Shape.bb
}

func (poly *PolyShape) Destroy() {
panic("implement me")
}

func (poly *PolyShape) PointQuery(p Vector, info *PointQueryInfo) {
count := poly.count
planes := poly.planes
Expand All @@ -78,7 +74,7 @@ func (poly *PolyShape) PointQuery(p Vector, info *PointQueryInfo) {
closestNormal := Vector{}
outside := false

for i := 0; i<count; i++ {
for i := 0; i < count; i++ {
v1 := planes[i].v0
if !outside {
outside = planes[i].n.Dot(p.Sub(v1)) > 0
Expand All @@ -102,15 +98,15 @@ func (poly *PolyShape) PointQuery(p Vector, info *PointQueryInfo) {
} else {
dist = -minDist
}
g := p.Sub(closestPoint).Mult(1.0/dist)
g := p.Sub(closestPoint).Mult(1.0 / dist)

info.Shape = poly.Shape
info.Point = closestPoint.Add(g.Mult(r))
info.Distance = dist-r
info.Distance = dist - r

if minDist > MAGIC_EPSILON {
info.Gradient = g
} else {
} else {
info.Gradient = closestNormal
}
}
Expand All @@ -119,9 +115,9 @@ func (poly *PolyShape) SegmentQuery(a, b Vector, r2 float64, info *SegmentQueryI
planes := poly.planes
count := poly.count
r := poly.r
rsum := r+r2
rsum := r + r2

for i:=0; i<count; i++ {
for i := 0; i < count; i++ {
n := planes[i].n
an := a.Dot(n)
d := an - planes[i].v0.Dot(n) - rsum
Expand All @@ -130,7 +126,7 @@ func (poly *PolyShape) SegmentQuery(a, b Vector, r2 float64, info *SegmentQueryI
}

bn := b.Dot(n)
t := d/(an-bn)
t := d / (an - bn)
if t < 0 || 1 < t {
continue
}
Expand All @@ -150,7 +146,7 @@ func (poly *PolyShape) SegmentQuery(a, b Vector, r2 float64, info *SegmentQueryI

// Also check against the beveled vertexes
if rsum > 0 {
for i := 0; i<count; i++ {
for i := 0; i < count; i++ {
circleInfo := SegmentQueryInfo{nil, b, Vector{}, 1}
CircleSegmentQuery(poly.Shape, planes[i].v0, r, a, b, r2, &circleInfo)
if circleInfo.Alpha < info.Alpha {
Expand All @@ -163,7 +159,7 @@ func (poly *PolyShape) SegmentQuery(a, b Vector, r2 float64, info *SegmentQueryI
func NewPolyShape(body *Body, vectCount int, verts []Vector, transform Transform, radius float64) *Shape {
hullVerts := []Vector{}
// Transform the verts before building the hull in case of a negative scale.
for i:=0; i<vectCount; i++ {
for i := 0; i < vectCount; i++ {
hullVerts = append(hullVerts, transform.Point(verts[i]))
}

Expand Down Expand Up @@ -222,7 +218,7 @@ func (p *PolyShape) SetVerts(count int, verts []Vector) {
func (p *PolyShape) SetVertsUnsafe(count int, verts []Vector, transform Transform) {
hullVerts := make([]Vector, count)

for i:=0; i<count; i++ {
for i := 0; i < count; i++ {
hullVerts[i] = transform.Point(verts[i])
}

Expand Down Expand Up @@ -307,7 +303,7 @@ func QHullReduce(tol float64, verts []Vector, count int, a, pivot, b Vector, res

leftCount := QHullPartition(verts, count, a, pivot, tol)
var index int
if leftCount - 1 >= 0 {
if leftCount-1 >= 0 {
index = QHullReduce(tol, verts[1:], leftCount-1, a, verts[0], pivot, result)
}

Expand Down
4 changes: 0 additions & 4 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func (seg *Segment) CacheData(transform Transform) BB {
return BB{l - rad, b - rad, r + rad, t + rad}
}

func (seg *Segment) Destroy() {
panic("implement me")
}

func (seg *Segment) SetRadius(r float64) {
seg.r = r

Expand Down
1 change: 0 additions & 1 deletion shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Shaper interface {

type ShapeClass interface {
CacheData(transform Transform) BB
Destroy()
PointQuery(p Vector, info *PointQueryInfo)
SegmentQuery(a, b Vector, radius float64, info *SegmentQueryInfo)
}
Expand Down
6 changes: 1 addition & 5 deletions spacehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ func (hash *SpaceHash) hashHandle(hand *Handle, bb BB) {
}
}

func (hash *SpaceHash) Destroy() {
panic("implement me")
}

func (hash *SpaceHash) Count() int {
return int(hash.handleSet.Count())
}
Expand Down Expand Up @@ -155,7 +151,7 @@ restart:
func floor(f float64) int {
i := int(f)
if f < 0 && float64(i) != f {
return i-1
return i - 1
}
return i
}
Expand Down
1 change: 0 additions & 1 deletion spatialindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type SpatialIndexSegmentQuery func(obj1 interface{}, obj2 *Shape, data interface

// implemented by BBTree
type SpatialIndexer interface {
Destroy()
Count() int
Each(f SpatialIndexIterator)
Contains(obj *Shape, hashId HashValue) bool
Expand Down

0 comments on commit 75dd8f3

Please sign in to comment.