spatial/{r2,r3}: remove deprecated method functions
MODIFY
spatial/barneshut/barneshut3.go
spatial/barneshut/barneshut3.go
@@ -37,7 +37,7 @@ func Gravity3(_, _ Particle3, m1, m2 float64, v r3.Vec) r3.Vec {
if d2 == 0 {
return r3.Vec{}
}
- return v.Scale((m1 * m2) / (d2 * math.Sqrt(d2)))
+ return r3.Scale((m1*m2)/(d2*math.Sqrt(d2)), v)
}
// Volume implements Barnes-Hut force approximation calculations.
@@ -141,7 +141,7 @@ func (q *Volume) ForceOn(p Particle3, theta float64, f Force3) (force r3.Vec) {
m := p.Mass()
pv := p.Coord3()
for _, e := range q.Particles {
- v = v.Add(f(p, e, m, e.Mass(), e.Coord3().Sub(pv)))
+ v = r3.Add(v, f(p, e, m, e.Mass(), r3.Sub(e.Coord3(), pv)))
}
return v
}
@@ -311,7 +311,7 @@ func (b *bucket) forceOn(p Particle3, pt r3.Vec, m, theta float64, f Force3) (ve
s := ((b.bounds.Max.X - b.bounds.Min.X) + (b.bounds.Max.Y - b.bounds.Min.Y) + (b.bounds.Max.Z - b.bounds.Min.Z)) / 3
d := math.Hypot(math.Hypot(pt.X-b.center.X, pt.Y-b.center.Y), pt.Z-b.center.Z)
if s/d < theta || b.particle != nil {
- return f(p, b.particle, m, b.mass, b.center.Sub(pt))
+ return f(p, b.particle, m, b.mass, r3.Sub(b.center, pt))
}
var v r3.Vec
@@ -319,7 +319,7 @@ func (b *bucket) forceOn(p Particle3, pt r3.Vec, m, theta float64, f Force3) (ve
if d == nil {
continue
}
- v = v.Add(d.forceOn(p, pt, m, theta, f))
+ v = r3.Add(v, d.forceOn(p, pt, m, theta, f))
}
return v
}

MODIFY
spatial/barneshut/barneshut3_test.go
spatial/barneshut/barneshut3_test.go
@@ -424,9 +424,9 @@ func TestVolumeForceOn(t *testing.T) {
m := p.Mass()
pv := p.Coord3()
for _, e := range particles {
- v = v.Add(Gravity3(p, e, m, e.Mass(), e.Coord3().Sub(pv)))
+ v = r3.Add(v, Gravity3(p, e, m, e.Mass(), r3.Sub(e.Coord3(), pv)))
}
- moved[i] = p.Coord3().Add(v)
+ moved[i] = r3.Add(p.Coord3(), v)
}
volume, err := NewVolume(particles)
@@ -445,8 +445,8 @@ func TestVolumeForceOn(t *testing.T) {
calls++
return Gravity3(p1, p2, m1, m2, v)
})
- pos := p.Coord3().Add(v)
- d := moved[i].Sub(pos)
+ pos := r3.Add(p.Coord3(), v)
+ d := r3.Sub(moved[i], pos)
ssd += d.X*d.X + d.Y*d.Y + d.Z*d.Z
sd += math.Hypot(math.Hypot(d.X, d.Y), d.Z)
}

MODIFY
spatial/barneshut/galaxy_example_test.go
spatial/barneshut/galaxy_example_test.go
@@ -22,8 +22,8 @@ type mass struct {
func (m *mass) Coord2() r2.Vec { return m.d }
func (m *mass) Mass() float64 { return m.m }
func (m *mass) move(f r2.Vec) {
- m.v = m.v.Add(f.Scale(1 / m.m))
- m.d = m.d.Add(m.v)
+ m.v = r2.Add(m.v, r2.Scale(1/m.m, f))
+ m.d = r2.Add(m.d, m.v)
}
func Example_galaxy() {
@@ -69,7 +69,7 @@ func Example_galaxy() {
// and an imaginary gravitational constant.
const G = 10
for j, s := range stars {
- vectors[j] = plane.ForceOn(s, theta, barneshut.Gravity2).Scale(G)
+ vectors[j] = r2.Scale(G, plane.ForceOn(s, theta, barneshut.Gravity2))
}
// Update positions.

MODIFY
spatial/r3/mat_test.go
spatial/r3/mat_test.go
@@ -109,7 +109,7 @@ func TestSkew(t *testing.T) {
sk.Skew(v1)
want := Cross(v1, v2)
got := sk.MulVec(v2)
- if d := want.Sub(got); d.Dot(d) > tol {
+ if d := Sub(want, got); Dot(d, d) > tol {
t.Errorf("r3.Cross(v1,v2) does not agree with r3.Skew(v1)*v2: got:%v want:%v", got, want)
}
}
@@ -135,7 +135,7 @@ func TestTranspose(t *testing.T) {
vd.MulVec(dt, vd)
want := Vec{X: vd.AtVec(0), Y: vd.AtVec(1), Z: vd.AtVec(2)}
got := m.MulVecTrans(v)
- if d := want.Sub(got); d.Dot(d) > tol {
+ if d := Sub(want, got); Dot(d, d) > tol {
t.Errorf("VecDense.MulVec(dense.T()) not agree with r3.Mat.MulVec(r3.Vec): got:%v want:%v", got, want)
}
}

spatial/{r2,r3}: remove deprecated method functions