mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-09 12:45:28 +00:00
Added preventing of division-by-zero cases when normalizing.
This commit is contained in:
parent
754e577623
commit
e4ec841e7a
|
@ -114,23 +114,28 @@ module Vector3 =
|
||||||
let v = Vector3(a, b, c)
|
let v = Vector3(a, b, c)
|
||||||
let l = v.Length
|
let l = v.Length
|
||||||
|
|
||||||
let norm = v.Normalized()
|
// Dividing by zero is not supported
|
||||||
|
if not (approxEq l 0.0f) then
|
||||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
let norm = v.Normalized()
|
||||||
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
|
||||||
Assert.ApproximatelyEqual(v.Z / l, norm.Z)
|
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||||
|
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
||||||
|
Assert.ApproximatelyEqual(v.Z / l, norm.Z)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Normalization of instance works`` (a, b, c) =
|
let ``Normalization of instance works`` (a, b, c) =
|
||||||
let v = Vector3(a, b, c)
|
let v = Vector3(a, b, c)
|
||||||
let norm = Vector3(a, b, c)
|
|
||||||
norm.Normalize()
|
|
||||||
|
|
||||||
let l = v.Length
|
let l = v.Length
|
||||||
|
|
||||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
if not (approxEq l 0.0f) then
|
||||||
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
let norm = Vector3(a, b, c)
|
||||||
Assert.ApproximatelyEqual(v.Z / l, norm.Z)
|
norm.Normalize()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||||
|
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
||||||
|
Assert.ApproximatelyEqual(v.Z / l, norm.Z)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Fast approximate normalization of instance works`` (a, b, c) =
|
let ``Fast approximate normalization of instance works`` (a, b, c) =
|
||||||
|
@ -146,18 +151,20 @@ module Vector3 =
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Normalization by reference works`` (a : Vector3) =
|
let ``Normalization by reference works`` (a : Vector3) =
|
||||||
let scale = 1.0f / a.Length
|
if not (approxEq a.Length 0.0f) then
|
||||||
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
let scale = 1.0f / a.Length
|
||||||
let vRes = Vector3.Normalize(ref a)
|
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
||||||
|
let vRes = Vector3.Normalize(ref a)
|
||||||
Assert.ApproximatelyEqual(norm, vRes)
|
|
||||||
|
Assert.ApproximatelyEqual(norm, vRes)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Normalization works`` (a : Vector3) =
|
let ``Normalization works`` (a : Vector3) =
|
||||||
let scale = 1.0f / a.Length
|
if not (approxEq a.Length 0.0f) then
|
||||||
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
let scale = 1.0f / a.Length
|
||||||
|
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
||||||
Assert.ApproximatelyEqual(norm, Vector3.Normalize(a));
|
|
||||||
|
Assert.ApproximatelyEqual(norm, Vector3.Normalize(a));
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Fast approximate normalization by reference works`` (a : Vector3) =
|
let ``Fast approximate normalization by reference works`` (a : Vector3) =
|
||||||
|
|
Loading…
Reference in a new issue