Exemple #1
0
        public Unit Multiply(DerivedUnit d, bool isDivide = false)
        {
            if (isDivide)
            {
                if (d == this)
                {
                    return(new BaseUnit());
                }
            }
            var a = new UnitTerms();

            foreach (var e in Terms)
            {
                var c = new UnitTerm {
                    Unit = e.Unit, Power = e.Power
                };
                a.Add(c);
            }
            foreach (var e in d.Terms)
            {
                var c = new UnitTerm {
                    Unit = e.Unit, Power = e.Power
                };
                c.Power = isDivide ? -c.Power : c.Power;
                a.Add(c);
            }
            a.RemoveAll(x => x.Power == 0);
            var b = new DerivedUnit(a);
            var f = (DerivedMeasure)measure;

            b.measure = isDivide ? f.Divide((DerivedMeasure)d.measure) : f.Multiply((DerivedMeasure)d.measure);
            b.Factor  = Factor * d.Factor;
            return(b);
        }
Exemple #2
0
        public Unit Multiply(DerivedUnit m)
        {
            var t = new UnitTerms();

            t.Add(new UnitTerm(this, 1));
            foreach (var e in m.Terms)
            {
                t.Add(new UnitTerm(e.Unit as BaseUnit, e.Power));
            }
            var a = new DerivedUnit(t);
            var b = (BaseMeasure)measure;

            a.Measure = b.Multiply((DerivedMeasure)m.Measure);
            return(a);
        }
Exemple #3
0
        public static UnitTerms Random()
        {
            var t = new UnitTerms();

            for (var i = 0; i < GetRandom.Count(); i++)
            {
                t.Add(UnitTerm.Random());
            }
            return(t);
        }
Exemple #4
0
        public Unit Reciprocal()
        {
            var a = new UnitTerms();

            foreach (var e in Terms)
            {
                var c = Clone(e);
                c.Power = c.Power * -1;
                a.Add(c);
            }
            var b = new DerivedUnit(a);
            var d = (DerivedMeasure)measure;

            b.measure = d.Reciprocal();
            return(b);
        }
Exemple #5
0
        public Unit Reciprocal()
        {
            var a = new UnitTerms();

            foreach (var e in Terms)
            {
                var c = new UnitTerm {
                    Unit = e.Unit, Power = e.Power
                };
                c.Power *= -1;
                a.Add(c);
            }
            var b = new DerivedUnit(a);
            var d = (DerivedMeasure)measure;

            b.measure = d.Reciprocal();
            return(b);
        }
Exemple #6
0
        public Unit Exponentiation(int i)
        {
            if (i == 0)
            {
                return(Empty);
            }
            var a = new UnitTerms();

            foreach (var e in Terms)
            {
                var c = Clone(e);
                c.Power = c.Power * i;
                a.Add(c);
            }
            var b = new DerivedUnit(a);
            var d = (DerivedMeasure)this.measure;

            b.measure = d.Exponentiation(i);
            return(b);
        }
Exemple #7
0
        public Unit Exponentiation(int i)
        {
            if (i == 0)
            {
                return(new BaseUnit());
            }
            var a = new UnitTerms();

            foreach (var e in Terms)
            {
                var c = new UnitTerm {
                    Unit = e.Unit, Power = e.Power
                };
                c.Power *= i;
                a.Add(c);
            }
            var b = new DerivedUnit(a);
            var d = (DerivedMeasure)this.measure;

            b.measure = d.Exponentiation(i);
            return(b);
        }