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

This commit is contained in:
Dan Kortschak
2022-08-05 19:57:37 +09:30
parent 7509ddb1e3
commit 8af7678edb
6 changed files with 13 additions and 111 deletions

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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.

View File

@@ -1,49 +0,0 @@
// Copyright ©2021 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package r2
// TODO(sbinet): remove this file for Gonum-v0.10.0.
// Add returns the vector sum of p and q.
//
// DEPRECATED: use r2.Add.
func (p Vec) Add(q Vec) Vec {
return Add(p, q)
}
// Sub returns the vector sum of p and -q.
//
// DEPRECATED: use r2.Sub.
func (p Vec) Sub(q Vec) Vec {
return Sub(p, q)
}
// Scale returns the vector p scaled by f.
//
// DEPRECATED: use r2.Scale.
func (p Vec) Scale(f float64) Vec {
return Scale(f, p)
}
// Dot returns the dot product p·q.
//
// DEPRECATED: use r2.Dot.
func (p Vec) Dot(q Vec) float64 {
return Dot(p, q)
}
// Cross returns the cross product p×q.
//
// DEPRECATED: use r2.Cross.
func (p Vec) Cross(q Vec) float64 {
return Cross(p, q)
}
// Rotate returns a new vector, rotated by alpha around the provided point, q.
//
// DEPRECATED: use r2.Rotate.
func (p Vec) Rotate(alpha float64, q Vec) Vec {
return Rotate(p, alpha, q)
}

View File

@@ -1,49 +0,0 @@
// Copyright ©2021 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package r3
// TODO(sbinet): remove this file for Gonum-v0.10.0.
// Add returns the vector sum of p and q.
//
// DEPRECATED: use r3.Add.
func (p Vec) Add(q Vec) Vec {
return Add(p, q)
}
// Sub returns the vector sum of p and -q.
//
// DEPRECATED: use r3.Sub.
func (p Vec) Sub(q Vec) Vec {
return Sub(p, q)
}
// Scale returns the vector p scaled by f.
//
// DEPRECATED: use r3.Scale.
func (p Vec) Scale(f float64) Vec {
return Scale(f, p)
}
// Dot returns the dot product p·q.
//
// DEPRECATED: use r3.Dot.
func (p Vec) Dot(q Vec) float64 {
return Dot(p, q)
}
// Cross returns the cross product p×q.
//
// DEPRECATED: use r3.Cross.
func (p Vec) Cross(q Vec) Vec {
return Cross(p, q)
}
// Rotate returns a new vector, rotated by alpha around the provided axis.
//
// DEPRECATED: use r3.Rotate
func (p Vec) Rotate(alpha float64, axis Vec) Vec {
return Rotate(p, alpha, axis)
}

View File

@@ -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)
}
}