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); }
public static bool HaveSameDimensions(UnitDimensions dim1, UnitDimensions dim2) { for (int i = 0; i < FundamentalUnitCount; i++) { if (dim1[i] != dim2[i]) { return(false); } } return(true); }
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); }
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; }
protected static bool _HaveTheSameDimensions(Unit unit1, Unit unit2) { return(UnitDimensions.HaveSameDimensions(unit1.UnitType.Dimensions, unit2.UnitType.Dimensions)); }