コード例 #1
0
        //Multiplication Operators
        private static DerivedQuantity multiplyDerivedQuantities(DerivedQuantity a, DerivedQuantity b)
        {
            var expression = new DerivedQuantityDimension(a.Dimension.Members
                                                          .Concat(b.Dimension.Members).ToArray());

            return(new DerivedQuantity(expression));
        }
コード例 #2
0
        private static DerivedQuantity exponentiateDerivedQuantity(DerivedQuantity a, double b)
        {
            var members = a.Dimension.Members.Select(m => new DerivedQuantityDimensionMember(m.BaseQuantity,
                                                                                             m.Exponent * b)).ToArray();
            var expression = new DerivedQuantityDimension(members);

            return(new DerivedQuantity(expression));
        }
コード例 #3
0
 public DerivedQuantity(string name, string symbol, string uiSymbol, DerivedQuantityDimension dimension)
 {
     _name     = name ?? throw new ArgumentNullException(nameof(name));
     _symbol   = symbol ?? throw new ArgumentNullException(nameof(symbol));
     _uiSymbol = uiSymbol;
     Dimension = dimension;
     IsNamed   = true;
 }
コード例 #4
0
 public DerivedQuantity(DerivedQuantityDimension dimension)
 {
     _name     = null;
     _symbol   = null;
     _uiSymbol = null;
     Dimension = dimension ?? throw new ArgumentNullException(nameof(dimension));
     IsNamed   = false;
 }
コード例 #5
0
        static Quantity()
        {
            //Multiplication Operators
            Func <DerivedQuantity, DerivedQuantity, DerivedQuantity> multiplyDerivedQuantities = (a, b) =>
            {
                var expression = new DerivedQuantityDimension(a.Dimension.Members
                                                              .Concat(b.Dimension.Members).ToArray());
                return(new DerivedQuantity(expression));
            };

            Func <BaseQuantity, BaseQuantity, DerivedQuantity> multiplyBaseQuantities = (a, b) =>
            {
                var derivedA = new DerivedQuantity(a, 1);
                var derivedB = new DerivedQuantity(b, 1);
                return(multiplyDerivedQuantities(derivedA, derivedB));
            };

            Func <BaseQuantity, DerivedQuantity, DerivedQuantity> multiplyBaseByDerivedQuantities = (a, b) =>
            {
                var derivedA = new DerivedQuantity(a, 1);
                return(multiplyDerivedQuantities(derivedA, b));
            };

            Func <DerivedQuantity, BaseQuantity, DerivedQuantity> multiplyDerivedByBaseQuantities = (a, b) =>
            {
                var derivedB = new DerivedQuantity(b, 1);
                return(multiplyDerivedQuantities(a, derivedB));
            };

            //Exponentiation Operators
            Func <BaseQuantity, double, DerivedQuantity> exponentiateBaseQuantity = (a, b) => new DerivedQuantity(a, b);

            Func <DerivedQuantity, double, DerivedQuantity> exponentiateDerivedQuantity = (a, b) =>
            {
                var members = a.Dimension.Members.Select(m => new DerivedQuantityDimensionMember(m.BaseQuantity,
                                                                                                 m.Exponent * b)).ToArray();
                var expression = new DerivedQuantityDimension(members);
                return(new DerivedQuantity(expression));
            };

            MathOperationManager.RegisterMany(new MathOperation[] {
                new Multiplication <BaseQuantity, BaseQuantity, DerivedQuantity>(multiplyBaseQuantities),
                new Multiplication <DerivedQuantity, DerivedQuantity, DerivedQuantity>(multiplyDerivedQuantities),
                new Multiplication <BaseQuantity, DerivedQuantity, DerivedQuantity>(multiplyBaseByDerivedQuantities),
                new Multiplication <DerivedQuantity, BaseQuantity, DerivedQuantity>(multiplyDerivedByBaseQuantities),
                new Exponentiation <BaseQuantity, double, DerivedQuantity>(exponentiateBaseQuantity),
                new Exponentiation <DerivedQuantity, double, DerivedQuantity>(exponentiateDerivedQuantity)
            });
        }