Пример #1
0
func Vector3_xf_FromVector(v Vector) Vector3_xf {
	return Vector3_xf{
		X: exactfloat.NewExactFloat(v.X),
		Y: exactfloat.NewExactFloat(v.Y),
		Z: exactfloat.NewExactFloat(v.Z),
	}
}
Пример #2
0
func TestMul(t *testing.T) {
	tests := []struct {
		v    Vector
		m    float64
		want Vector
	}{
		{Vector{0, 0, 0}, 3, Vector{0, 0, 0}},
		{Vector{1, 0, 0}, 1, Vector{1, 0, 0}},
		{Vector{1, 0, 0}, 0, Vector{0, 0, 0}},
		{Vector{1, 0, 0}, 3, Vector{3, 0, 0}},
		{Vector{1, -3, 5}, -1, Vector{-1, 3, -5}},
		{Vector{1, -3, 5}, 2, Vector{2, -6, 10}},
	}
	for _, test := range tests {
		if !test.v.Mul(test.m).ApproxEqual(test.want) {
			t.Errorf("%v%v = %v, want %v", test.m, test.v, test.v.Mul(test.m), test.want)
		}

		vxf := Vector3_xf_FromVector(test.v)
		wxf := Vector3_xf_FromVector(test.want)
		mxf := exactfloat.NewExactFloat(test.m)
		if !vxf.Mul(mxf).ApproxEqual(wxf) {
			t.Errorf("%v%v = %v, want %v", mxf, vxf, vxf.Mul(mxf), wxf)
		}
	}
}
Пример #3
0
func (a Vector3_xf) ApproxEqual(b Vector3_xf) bool {
	epsilon := exactfloat.NewExactFloat(1e-14)
	return exactfloat.Abs(a.X.Sub(b.X)).LessThan(epsilon) &&
		exactfloat.Abs(a.Y.Sub(b.Y)).LessThan(epsilon) &&
		exactfloat.Abs(a.Z.Sub(b.Z)).LessThan(epsilon)
}