Example #1
0
        public void WriteBitCoord()
        {
            var random = new Random(0);

            for (int i = 0; i < Iterations; i++)
            {
                int             skip = i % 16;
                BitStreamWriter bsw  = new BitStreamWriter();
                bsw.WriteBitsFromSInt(random.Next(), skip);
                bsw.WriteBitCoord((float)((random.NextDouble() - 0.5) * 100000));
                BitStreamReader bsr = new BitStreamReader(bsw);
                bsr.SkipBits(skip);
                // Write the float back and then read it again, this will constrain it to the precision of a
                // bit coord so we can do a direct equality check.
                float f = bsr.ReadBitCoord();
                // Now do all the same stuff we just did but with the constrained float.
                bsw = new BitStreamWriter();
                bsw.WriteBitsFromSInt(random.Next(), skip);
                bsw.WriteBitCoord(f);
                bsr = new BitStreamReader(bsw);
                bsr.SkipBits(skip);
                Assert.AreEqual(f, bsr.ReadBitCoord(), $"index: {i}");
            }
        }