Ejemplo n.º 1
0
 public Unit(T type, Unit unitToConvert)
 {
     if (!UnitDimensions.HaveSameDimensions(type.Dimensions, unitToConvert.Dimensions))
     {
         throw new Exception("Units do not have the same Dimensions");
     }
     this.UnitType    = type;
     this.Measurement = unitToConvert.MeasurementIn(type);
 }
Ejemplo n.º 2
0
 public static bool HaveSameDimensions(UnitDimensions dim1, UnitDimensions dim2)
 {
     for (int i = 0; i < FundamentalUnitCount; i++)
     {
         if (dim1[i] != dim2[i])
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
        internal UnitDimensions ToThe(int power)
        {
            var newDim = new int[FundamentalUnitCount];

            for (int i = 0; i < FundamentalUnitCount; i++)
            {
                newDim[i] = this[i] * power;
            }
            var dim = new UnitDimensions
            {
                ConversionFactor = Math.Pow(this.ConversionFactor, power),
                _dimensions      = newDim,
            };

            return(dim);
        }
Ejemplo n.º 4
0
        public UnitDimensions Divide(UnitDimensions dimensions)
        {
            var newDim = new int[FundamentalUnitCount];

            for (int i = 0; i < FundamentalUnitCount; i++)
            {
                newDim[i] = this[i] - dimensions[i];
            }
            var dim = new UnitDimensions
            {
                ConversionFactor = this.ConversionFactor / dimensions.ConversionFactor,
                _dimensions      = newDim,
            };

            return(dim);
        }
 internal UnitDimensions ToThe(int power)
 {
     var newDim = new int[FundamentalUnitCount];
     for (int i = 0; i < FundamentalUnitCount; i++)
     {
         newDim[i] = this[i]*power;
     }
     var dim = new UnitDimensions
     {
         ConversionFactor = Math.Pow( this.ConversionFactor, power),
         _dimensions = newDim,
     };
     return dim;
 }
        public UnitDimensions Divide(UnitDimensions dimensions)
        {
            var newDim = new int[FundamentalUnitCount];
            for (int i = 0; i < FundamentalUnitCount; i++)
            {
                newDim[i] = this[i] - dimensions[i];
            }
            var dim = new UnitDimensions
            {
                ConversionFactor = this.ConversionFactor / dimensions.ConversionFactor,
                _dimensions = newDim,
            };

            return dim;
        }
 public static bool HaveSameDimensions(UnitDimensions dim1, UnitDimensions dim2)
 {
     for (int i = 0; i < FundamentalUnitCount; i++)
     {
         if (dim1[i] != dim2[i])
         {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 protected static bool _HaveTheSameDimensions(Unit unit1, Unit unit2)
 {
     return(UnitDimensions.HaveSameDimensions(unit1.UnitType.Dimensions, unit2.UnitType.Dimensions));
 }