Used to represent combined units -- temporary and defined.
Inheritance: PhysicalUnit
Beispiel #1
0
        public static UnitValue DivUU(Value a, Value b)
        {
            var left  = (UnitValue)a;
            var right = (UnitValue)b;
            var unit  = new CombinedUnit(left.Unit).Divide(right.Unit).Simplify();

            return(new UnitValue(unit.Factor * left / right, unit.Unpack()));
        }
Beispiel #2
0
        public CombinedUnit CreateFrom(string unit)
        {
            var name = Unpack();
            var obj  = new CombinedUnit(name, factor);

            obj.factor *= GetWeight(unit);
            return(obj);
        }
Beispiel #3
0
        static UnitValue MulUU(Value a, Value b)
        {
            var left  = (UnitValue)a;
            var right = (UnitValue)b;
            var unit  = new CombinedUnit(left.Unit).Multiply(right.Unit).Simplify();

            return(new UnitValue(unit.Factor * left * right, unit.Unpack()));
        }
Beispiel #4
0
        /// <summary>
        /// Divides the given combined unit by another unit.
        /// </summary>
        /// <param name="unit">The combined unit to divide the current unit.</param>
        /// <returns>The (current) modified unit.</returns>
        public CombinedUnit Divide(CombinedUnit unit)
        {
            foreach (var element in unit.ElementaryUnits)
            {
                AddUnit(units, element.Key, -element.Value);
            }

            return(this);
        }
Beispiel #5
0
        /// <summary>
        /// Multiplies the given combined unit with another combined unit.
        /// </summary>
        /// <param name="unit">The combined unit which is multiplied to the current unit.</param>
        /// <returns>The (current) modified unit.</returns>
        public CombinedUnit Multiply(CombinedUnit unit)
        {
            foreach (var element in unit.ElementaryUnits)
            {
                AddUnit(_units, element.Key, element.Value);
            }

            return(this);
        }
Beispiel #6
0
        public static UnitValue Convert(UnitValue fromValue, String targetUnit)
        {
            var cu          = new CombinedUnit(fromValue.Unit);
            var conversions = cu.ConvertTo(targetUnit);
            var re          = fromValue.Re;

            foreach (var conversation in conversions)
            {
                re = conversation(re);
            }

            return(new UnitValue(cu.Factor * re, cu.Unit));
        }
Beispiel #7
0
        public static UnitValue Convert(UnitValue fromValue, String targetUnit)
        {
            var cu = new CombinedUnit(fromValue.Unit);
            var conversions = cu.ConvertTo(targetUnit);
            var re = fromValue.Re;

            foreach (var conversation in conversions)
            {
                re = conversation(re);
            }

            return new UnitValue(cu.Factor * re, cu.Unit);
        }
Beispiel #8
0
        double GetChanges(CombinedUnit unit, out bool reversed)
        {
            var misses     = 0.0;
            var posCatches = 0.0;
            var negCatches = 0.0;

            reversed = false;

            foreach (var b in unit.units)
            {
                var found = false;

                foreach (var a in units)
                {
                    if (a.Key == b.Key)
                    {
                        found       = true;
                        posCatches += Math.Abs(b.Value - a.Value);
                        negCatches += Math.Abs(b.Value + a.Value);
                        break;
                    }
                }

                if (!found)
                {
                    misses += Math.Abs(b.Value);
                }
            }

            if (negCatches < posCatches)
            {
                reversed = true;
                return(misses + negCatches);
            }

            return(misses + posCatches);
        }
Beispiel #9
0
        Double GetChanges(CombinedUnit unit, out Boolean reversed)
        {
            var misses = 0.0;
            var posCatches = 0.0;
            var negCatches = 0.0;
            reversed = false;

            foreach (var b in unit._units)
            {
                var found = false;

                foreach (var a in _units)
                {
                    if (a.Key == b.Key)
                    {
                        found = true;
                        posCatches += Math.Abs(b.Value - a.Value);
                        negCatches += Math.Abs(b.Value + a.Value);
                        break;
                    }
                }

                if (!found)
                {
                    misses += Math.Abs(b.Value);
                }
            }

            if (negCatches < posCatches)
            {
                reversed = true;
                return misses + negCatches;
            }

            return misses + posCatches;
        }
Beispiel #10
0
        /// <summary>
        /// Multiplies the given combined unit with another combined unit.
        /// </summary>
        /// <param name="unit">The combined unit which is multiplied to the current unit.</param>
        /// <returns>The (current) modified unit.</returns>
        public CombinedUnit Multiply(CombinedUnit unit)
        {
            foreach (var element in unit.ElementaryUnits)
            {
                AddUnit(_units, element.Key, element.Value);
            }

            return this;
        }
Beispiel #11
0
 public CombinedUnit CreateFrom(String unit)
 {
     var name = Unpack();
     var obj = new CombinedUnit(name, _factor);
     obj._factor *= GetWeight(unit);
     return obj;
 }
Beispiel #12
0
 static UnitValue MulUU(Value a, Value b)
 {
     var left = (UnitValue)a;
     var right = (UnitValue)b;
     var unit = new CombinedUnit(left.Unit).Multiply(right.Unit).Simplify();
     return new UnitValue(unit.Factor * left * right, unit.Unpack());
 }
Beispiel #13
0
 static UnitValue DivUU(Value a, Value b)
 {
     var left = (UnitValue)a;
     var right = (UnitValue)b;
     var unit = new CombinedUnit(left.Unit).Divide(right.Unit).Simplify();
     return new UnitValue(unit.Factor * left / right, unit.Unpack());
 }