mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-09 22:25:28 +00:00
Added preventing of division-by-zero cases when normalizing.
This commit is contained in:
parent
754e577623
commit
e4ec841e7a
|
@ -114,6 +114,8 @@ module Vector3 =
|
||||||
let v = Vector3(a, b, c)
|
let v = Vector3(a, b, c)
|
||||||
let l = v.Length
|
let l = v.Length
|
||||||
|
|
||||||
|
// Dividing by zero is not supported
|
||||||
|
if not (approxEq l 0.0f) then
|
||||||
let norm = v.Normalized()
|
let norm = v.Normalized()
|
||||||
|
|
||||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||||
|
@ -123,10 +125,13 @@ module Vector3 =
|
||||||
[<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 l = v.Length
|
||||||
|
|
||||||
|
if not (approxEq l 0.0f) then
|
||||||
let norm = Vector3(a, b, c)
|
let norm = Vector3(a, b, c)
|
||||||
norm.Normalize()
|
norm.Normalize()
|
||||||
|
|
||||||
let l = v.Length
|
|
||||||
|
|
||||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||||
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
||||||
|
@ -146,6 +151,7 @@ module Vector3 =
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Normalization by reference works`` (a : Vector3) =
|
let ``Normalization by reference works`` (a : Vector3) =
|
||||||
|
if not (approxEq a.Length 0.0f) then
|
||||||
let scale = 1.0f / a.Length
|
let scale = 1.0f / a.Length
|
||||||
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
||||||
let vRes = Vector3.Normalize(ref a)
|
let vRes = Vector3.Normalize(ref a)
|
||||||
|
@ -154,6 +160,7 @@ module Vector3 =
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``Normalization works`` (a : Vector3) =
|
let ``Normalization works`` (a : Vector3) =
|
||||||
|
if not (approxEq a.Length 0.0f) then
|
||||||
let scale = 1.0f / a.Length
|
let scale = 1.0f / a.Length
|
||||||
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue