none
Possible bug found in System.Numerics.Vector2.Lerp RRS feed

  • General discussion

  • I tested this code using .NET Framework 4.7 with the "Optimize code" flag active. It is returning 0 but should be 0.5.

    This problem does not happen with Vector3 and Vector4 classes. Compiling without the "Optimize code" flag or calling the Lerp method outside of the Vertex struct also gives the correct result.

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System.Numerics;
    
    namespace Geometries.Tests
    {
        [TestClass()]
        public class VertexTests
        {
            [TestMethod()]
            public void Interpolate_LerpTexcoords()
            {
                var v1 = new Vertex { Value = new Vector2(0) };
                var v2 = new Vertex { Value = new Vector2(1) };
    
                var result = v1.Interpolate(v2, 0.5f);
    
                Assert.AreEqual(0.5f, result.Value.X, 0.001f);
            }
        }
    
        public struct Vertex
        {
            public Vector2 Value;
    
            public Vertex Interpolate(Vertex v2, float t)
            {
                return new Vertex
                {
                    Value = Vector2.Lerp(Value, v2.Value, t)
                };
            }
        }
    }

    Thursday, May 2, 2019 1:08 PM