private VariableIntPacker(int smallBits, int mediumBits, int largeBits, bool throwIfOverLarge) { this.throwIfOverLarge = throwIfOverLarge; if (smallBits == 0) { throw new ArgumentException("Small value can not be zero", nameof(smallBits)); } if (smallBits >= mediumBits) { throw new ArgumentException("Medium value must be greater than small value", nameof(mediumBits)); } if (mediumBits >= largeBits) { throw new ArgumentException("Large value must be greater than medium value", nameof(largeBits)); } if (largeBits > 64) { throw new ArgumentException("Large bits must be 64 or less", nameof(largeBits)); } // force medium to also be 62 or less so we can use 1 write call (2 bits to say its medium + 62 value bits if (mediumBits > 62) { throw new ArgumentException("Medium bits must be 62 or less", nameof(mediumBits)); } this.smallBitCount = smallBits; this.mediumBitsCount = mediumBits; this.largeBitsCount = largeBits; // mask is also max value for n bits this.smallValue = BitMask.Mask(smallBits); this.mediumValue = BitMask.Mask(mediumBits); this.largeValue = BitMask.Mask(largeBits); }
/// <param name="quaternionBitLength">10 per "smallest 3" is good enough for most people</param> public QuaternionPacker(int quaternionBitLength = 10) { // (this.BitLength - 1) because pack sign by itself this.bitCountPerElement = quaternionBitLength; this.totalBitCount = 2 + (quaternionBitLength * 3); this.floatPacker = new FloatPacker(MaxValue, quaternionBitLength); this.readMask = (uint)BitMask.Mask(this.bitCountPerElement); }