/// <summary> /// Utility method that checks if the dimensions of the two units match. /// If the dimensions do not match, an error string that can be put into /// an exception is produced. If they match, null is returned. /// </summary> /// <param name="q1">First quantity to check</param> /// <param name="q2">Second quantity to check</param> /// <returns>Null if matching, otherwise an error string.</returns> public static string CheckIfDimensionsMatch(IQuantity q1, IQuantity q2) { IDimension dim1 = q1.Unit.Dimension; IDimension dim2 = q2.Unit.Dimension; int count = 0; string error = "Dimensions does not match:"; foreach (DimensionBase dimBase in Enum.GetValues(typeof(DimensionBase))) { double dimbaseval1 = dim1.GetPower(dimBase); double dimbaseval2 = dim2.GetPower(dimBase); if (dimbaseval1 != dimbaseval2) { count++; error += string.Format(" ({0},{1},{2})", dimBase, dimbaseval1.ToString(System.Globalization.CultureInfo.InvariantCulture), dimbaseval2.ToString(System.Globalization.CultureInfo.InvariantCulture)); } } if (count == 0) { return(null); } return(error); }
/// <summary> /// Determines whether two dimensions are equal. /// </summary> /// <param name="dimension1">Dimension one</param> /// <param name="dimension2">Dimension two</param> /// <returns>Returns <c>true</c> if powers of all dimension bases are same, otherwise returns <c>false</c>.</returns> public static bool CompareDimensions(IDimension dimension1, IDimension dimension2) { for (int i = 0; i < (int)DimensionBase.NUM_BASE_DIMENSIONS; i++) if (dimension1.GetPower((DimensionBase) i) != dimension2.GetPower((DimensionBase) i)) return( false ); return( true ); }
/// <summary> /// Determines whether two dimensions are equal. /// </summary> /// <param name="dimension1">Dimension one</param> /// <param name="dimension2">Dimension two</param> /// <returns>Returns <c>true</c> if powers of all dimension bases are same, otherwise returns <c>false</c>.</returns> public static bool CompareDimensions(IDimension dimension1, IDimension dimension2) { for (int i = 0; i < (int)DimensionBase.NUM_BASE_DIMENSIONS; i++) { if (dimension1.GetPower((DimensionBase)i) != dimension2.GetPower((DimensionBase)i)) { return(false); } } return(true); }
/// <summary> /// Determines whether two dimensions are equal. /// </summary> /// <param name="dimension1">Dimension one</param> /// <param name="dimension2">Dimension two</param> /// <returns>Returns <c>true</c> if powers of all dimension bases are same, otherwise returns <c>false</c>.</returns> public static bool CompareDimensions(IDimension dimension1, IDimension dimension2) { for (int i = 0; i < (int)Enum.GetValues(typeof(DimensionBase)).Length; i++) { if (dimension1.GetPower((DimensionBase)i) != dimension2.GetPower((DimensionBase)i)) { return(false); } } return(true); }
private bool CompareDimensions(IDimension dimension1, IDimension dimension2) { bool isSameDimension = true; for (int i = 0; i < (int)DimensionBase.NUM_BASE_DIMENSIONS; i++) { if (dimension1.GetPower((DimensionBase)i) != dimension2.GetPower((DimensionBase)i)) { isSameDimension = false; } } return(isSameDimension); }
///<summary> /// Check if the current instance equals another instance of this class. ///</summary> ///<param name="dim1">The instance to compare the current instance with.</param> ///<returns><code>true</code> if the instances are the same instance or have the same content.</returns> public static bool DescribesSameAs(IDimension dim1, IDimension dim2) { if (dim1 == null || dim2 == null) { return(false); } foreach (DimensionBase dimBase in Enum.GetValues(typeof(DimensionBase))) { if (dim1.GetPower(dimBase) != dim2.GetPower(dimBase)) { return(false); } } return(true); }
///<summary> /// Check if the current instance equals another instance of this class. ///</summary> ///<param name="dim1">The instance to compare the current instance with.</param> ///<returns><code>true</code> if the instances are the same instance or have the same content.</returns> public static bool DescribesSameAs(IDimension dim1, IDimension dim2) { if (dim1 == null || dim2 == null) return false; foreach (DimensionBase dimBase in Enum.GetValues(typeof(DimensionBase))) { if (dim1.GetPower(dimBase) != dim2.GetPower(dimBase)) return false; } return true; }
private bool CompareDimensions(IDimension dimension1, IDimension dimension2) { bool isSameDimension = true; for (int i = 0; i < (int)DimensionBase.NUM_BASE_DIMENSIONS; i++) { if (dimension1.GetPower((DimensionBase) i) != dimension2.GetPower((DimensionBase) i)) { isSameDimension = false; } } return isSameDimension; }