mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-04 06:48:17 +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 l = v.Length
|
||||
|
||||
// Dividing by zero is not supported
|
||||
if not (approxEq l 0.0f) then
|
||||
let norm = v.Normalized()
|
||||
|
||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||
|
@ -123,10 +125,13 @@ module Vector3 =
|
|||
[<Property>]
|
||||
let ``Normalization of instance works`` (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)
|
||||
norm.Normalize()
|
||||
|
||||
let l = v.Length
|
||||
|
||||
|
||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
|
||||
|
@ -146,6 +151,7 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization by reference works`` (a : Vector3) =
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let scale = 1.0f / a.Length
|
||||
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
||||
let vRes = Vector3.Normalize(ref a)
|
||||
|
@ -154,6 +160,7 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization works`` (a : Vector3) =
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let scale = 1.0f / a.Length
|
||||
let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale)
|
||||
|
||||
|
|
Loading…
Reference in a new issue