Exemplo n.º 1
0
    public T Scale <T>(T quantity) where T : QuantityN
    {
        SciNumber scaler = SciNumber.One;

        quantity.units.unitExponents.ForEach(x => scaler *= (unitScales.FirstOrDefault(y => y.unit == x.unit)?.scale ?? SciNumber.One));

        return(QuantityN.CreateQuantityInstance <T>(quantity.values.Select(x => x * scaler).ToList(), quantity.units));
    }
Exemplo n.º 2
0
    protected static bool CheckDimensionCount(QuantityN a, QuantityN b, bool throwException = true)
    {
        bool x = a.values.Count == b.values.Count;

        if (x == false && throwException)
        {
            throw new ArgumentException("Cannot perform this operation on Quantities with different number of values");
        }

        return(x);
    }
Exemplo n.º 3
0
    protected static bool CheckMatchingUnits(QuantityN a, QuantityN b, bool throwException = true)
    {
        bool x = a.units.Equals(b.units);

        if (x == false && throwException)
        {
            throw new ArgumentException("Operation cannot be performed on values with units \n" + a.units + " and " + b.units);
        }

        return(x);
    }