mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-01 23:56:16 -04:00
029cb62972
* Fixed nil pointer in Copy() * Position added Added Floor() and String() methods to Vector. Also added Position which declares an embedded Vector2 and returns various forms of it. * d2vector.Vector2 renamed to d2vector.BigFloat * vector.go renamed to big_float.go * Float64 stub and more renaming * Vector value getters * Separate vector types with initial methods. * Divide and lint warnings. * Distance and Length. * Scale, Abs and Negate. * CompareFloat64Fuzzy delta direction reversed. * Refactor vector_test.go. * Renamed Approx methods. * Distance and Length. * Distance and Length. * Removed BigFloat and Vector, renamed Float64 to Vector, simplified tests. * Angle, SignedAngle and other small functions. * Receiver rename. * SingedAngle and test fixed * Rotate. * SetLength. * Cross. * NinetyAnti and NinetyClock. * Lerp and Clamp. * Reflect and ReflectSurface. * Cardinal convenience functions. * Comments. * Panic on NaN and Inf in Position. * Lint warnings and comments.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package d2vector
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func validate(t *testing.T, original, got, want, unchanged Vector) {
|
|
if !got.EqualsApprox(want) {
|
|
t.Errorf("want %s: got %s", want, got)
|
|
}
|
|
|
|
if !original.EqualsApprox(unchanged) {
|
|
t.Errorf("Position value %s was incorrectly changed to %s when calling this method", unchanged, original)
|
|
}
|
|
}
|
|
|
|
func TestTile(t *testing.T) {
|
|
p := NewPosition(1.6, 1.6)
|
|
got := p.Tile()
|
|
want := NewVector(1, 1)
|
|
unchanged := NewVector(1.6, 1.6)
|
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
|
}
|
|
|
|
func TestTileOffset(t *testing.T) {
|
|
p := NewPosition(1.6, 1.6)
|
|
got := p.TileOffset()
|
|
want := NewVector(0.6, 0.6)
|
|
unchanged := NewVector(1.6, 1.6)
|
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
|
}
|
|
|
|
func TestSubWorld(t *testing.T) {
|
|
p := NewPosition(1, 1)
|
|
got := p.SubWorld()
|
|
want := NewVector(5, 5)
|
|
unchanged := NewVector(1, 1)
|
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
|
}
|
|
|
|
func TestSubTile(t *testing.T) {
|
|
p := NewPosition(1, 1)
|
|
got := p.SubTile()
|
|
want := NewVector(5, 5)
|
|
unchanged := NewVector(1, 1)
|
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
|
}
|
|
|
|
func TestSubTileOffset(t *testing.T) {
|
|
p := NewPosition(1.1, 1.1)
|
|
got := p.SubTileOffset()
|
|
want := NewVector(0.5, 0.5)
|
|
unchanged := NewVector(1.1, 1.1)
|
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
|
}
|