Exemplo n.º 1
0
 internal static Range Include(Range x, float p)
 {
     float min = x.min;
     float max = x.max;
     if (x.min > p) min = p;
     if (x.max < p) max = p;
     return new Range(min, max);
 }
Exemplo n.º 2
0
 internal static Range Expand(Range x, float p)
 {
     float min = x.min;
     float max = x.max;
     min -= p;
     max += p;
     return new Range(min, max);
 }
Exemplo n.º 3
0
 void IDefinition.FromArray(byte[] buffer)
 {
     BinaryReader bin = new BinaryReader(new MemoryStream(buffer));
     X = bin.ReadRange();
     Y = bin.ReadRange();
     Z = bin.ReadRange();
     U = bin.ReadRange();
     V = bin.ReadRange();
 }
Exemplo n.º 4
0
 void IDefinition.FromArray(byte[] buffer)
 {
     BinaryReader bin = new BinaryReader(new MemoryStream(buffer));
     x = bin.ReadRange();
     y = bin.ReadRange();
     z = bin.ReadRange();
 }
Exemplo n.º 5
0
 protected static float Inflate(float value_in_range, Range range)
 {
     const float ushort_max_inverse = 1.0f / ushort.MaxValue;
     return (((value_in_range + short.MaxValue) * ushort_max_inverse) * (range.max - range.min)) + range.min;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Takes a float-value and converts it into a range then stores the range ratio in a short
 /// </summary>
 /// <param name="input_range"></param>
 /// <param name="value"></param>
 /// <returns>returns the ratio of 'value' in 'input_range' represented as a short<returns>
 protected static short Deflate(Range input_range, float value)
 {
     value = Range.Truncate(input_range, value);                             // Ensure input value is within the expected range
     var delta = (value - input_range.min);                                  // This projects value into the range with 0 as the lowest value in the range
     var range_span = input_range.max - input_range.min;                     // The total width of values the range covers
     var ratio = delta / range_span;                                         // The location in the range which this value resides at
     var short_value = (short)(ratio * ushort.MaxValue - short.MaxValue);    /* ratio { 0.0 -> 1.0 } * 65535 - 32767
                                                                              * the subtration at the end is to maintain a signed value */
     #if DEBUG
     var compression_delta = Inflate(short_value, input_range) - value;      // Crappy unit testing
     if (compression_delta > 0.001) throw new Exception();
     #endif
     return short_value;
 }
Exemplo n.º 7
0
 internal void Expand(float p)
 {
     X = Range.Expand(X, p);
     Y = Range.Expand(Y, p);
     Z = Range.Expand(Z, p);
     U = Range.Expand(U, p);
     V = Range.Expand(V, p);
 }
Exemplo n.º 8
0
 private float UpdateRotation(bool allow_wrap, Range rotation_contraints, float rotation_field, float rotation_degrees)
 {
     var rotation_sum = rotation_field + rotation_degrees;
     if (allow_wrap)
         return Range.Wrap(rotation_contraints, rotation_sum);
     else
         return Range.Truncate(rotation_contraints, rotation_sum);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Maps values outside of the range back into the range using the magnitude of the 
 /// value from the closest range-boundary (min or max)
 /// [min₁..max₁][min₂..max₂] .. [minₓ..maxₓ]
 /// </summary>
 /// <param name="range"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 internal static float Wrap(Range range, float value)
 {
     var wrapped_value = value < range.min ? range.max + (value - range.min) % (range.max - range.min):
         value > range.max ? range.min + (value - range.min) % (range.max - range.min) : value;
     return wrapped_value;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Truncates the passed value to the closest value in range if value is outside of the range (range.min or range.max)
 /// Else returns the value unchanged.
 /// </summary>
 /// <param name="range">The range of values to check against</param>
 /// <param name="value">The value to truncate</param>
 /// <returns>The truncated value</returns>
 internal static float Truncate(Range range, float value)
 {
     if (value < range.min) return range.min;
     if (value > range.max) return range.max;
     return value;
 }
Exemplo n.º 11
0
 internal static float Median(Range range)
 {
     return (range.min + range.max) * 0.5f;
 }