public void TestFixtureSetUp()
 {
     DmsConversion = new SexagesimalDmsToDecimalDegreesConversion(new SimpleUnit("Sexagesimal DMS"), new SimpleUnit("degrees"));
     DmsInverse = DmsConversion.GetInverse();
     DmConversion = new SexagesimalDmToDecimalDegreesConversion(new SimpleUnit("Sexagesimal DM"), DmsConversion.To);
     DmInverse = DmConversion.GetInverse();
 }
Example #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="mass"></param>
 /// <param name="acceleration"></param>
 protected ForceBase(string abbreviation,
     IUnitConversion toBase, IUnitConversion fromBase,
     IMass mass, IAcceleration acceleration)
     : base(abbreviation, toBase, fromBase, mass, acceleration)
 {
     VerifyDimensions();
 }
 public BinaryUnitConversionMap(IUnitConversion<double> forwardOperation, IEqualityComparer<IUnit> unitEqualityComparer = null)
     : base(unitEqualityComparer)
 {
     if (null == forwardOperation) throw new ArgumentNullException("forwardOperation");
     Contract.EndContractBlock();
     _forwardOperation = forwardOperation;
 }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="mass"></param>
 /// <param name="acceleration"></param>
 protected ForceBase(string abbreviation,
                     IUnitConversion toBase, IUnitConversion fromBase,
                     IMass mass, IAcceleration acceleration)
     : base(abbreviation, toBase, fromBase, mass, acceleration)
 {
     VerifyDimensions();
 }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="surfaceArea"></param>
 /// <param name="squareRadius"></param>
 protected SolidAngleBase(string abbreviation,
                          IUnitConversion toBase, IUnitConversion fromBase,
                          IArea surfaceArea, ILength squareRadius)
     : base(abbreviation, toBase, fromBase, surfaceArea, squareRadius)
 {
     VerifyDimensions();
 }
        private static void VerifyUnitConversion(IUnitConversion conversion, int exponent, double result)
        {
            Assert.That(conversion, Is.Not.Null);
            var actual = conversion.Convert(BaseConversionStartValue, exponent);

            Assert.That(actual, Is.EqualTo(result).Within(Epsilon));
        }
Example #7
0
 public void TestFixtureSetUp()
 {
     DmsConversion = new SexagesimalDmsToDecimalDegreesConversion(new SimpleUnit("Sexagesimal DMS"), new SimpleUnit("degrees"));
     DmsInverse    = DmsConversion.GetInverse();
     DmConversion  = new SexagesimalDmToDecimalDegreesConversion(new SimpleUnit("Sexagesimal DM"), DmsConversion.To);
     DmInverse     = DmConversion.GetInverse();
 }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="surfaceArea"></param>
 /// <param name="squareRadius"></param>
 protected SolidAngleBase(string abbreviation,
     IUnitConversion toBase, IUnitConversion fromBase,
     IArea surfaceArea, ILength squareRadius)
     : base(abbreviation, toBase, fromBase, surfaceArea, squareRadius)
 {
     VerifyDimensions();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="dimensions"></param>
 protected DerivedDimension(string abbreviation,
     IUnitConversion toBase, IUnitConversion fromBase,
     params IDimension[] dimensions)
     : base(abbreviation)
 {
     //TODO: may order these, by exponent?
     _dimensions.AddRange(dimensions);
     ToBase = toBase ?? new DerivedUnitConversion(() => Dimensions, d => d.ToBase);
     FromBase = fromBase ?? new DerivedUnitConversion(() => Dimensions, d => d.FromBase);
 }
 public BinaryUnitConversionMap(IUnitConversion <double> forwardOperation, IEqualityComparer <IUnit> unitEqualityComparer = null)
     : base(unitEqualityComparer)
 {
     if (null == forwardOperation)
     {
         throw new ArgumentNullException("forwardOperation");
     }
     Contract.EndContractBlock();
     _forwardOperation = forwardOperation;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="dimensions"></param>
 protected DerivedDimension(string abbreviation,
                            IUnitConversion toBase, IUnitConversion fromBase,
                            params IDimension[] dimensions)
     : base(abbreviation)
 {
     //TODO: may order these, by exponent?
     _dimensions.AddRange(dimensions);
     ToBase   = toBase ?? new DerivedUnitConversion(() => Dimensions, d => d.ToBase);
     FromBase = fromBase ?? new DerivedUnitConversion(() => Dimensions, d => d.FromBase);
 }
Example #12
0
        private IEnumerable <IUnitConversion <double> > Linearize(IUnitConversion <double> conversion)
        {
            Contract.Requires(conversion != null);
            Contract.Ensures(Contract.Result <IEnumerable <IUnitConversion <double> > >() != null);
            Contract.Ensures(Contract.ForAll(Contract.Result <IEnumerable <IUnitConversion <double> > >(), x => x != null));
            var catConv = conversion as ConcatenatedUnitConversion;

            if (null == catConv)
            {
                return(ArrayUtil.CreateSingleElementArray(conversion));
            }
            return(Linearize(catConv.Conversions));
        }
Example #13
0
            public ConvertorInstance(IUnitConversion conversionEntry, IServiceLocator locator)
            {
                if (!string.IsNullOrWhiteSpace(conversionEntry.ConvertorClass))
                {
                    m_convertor = locator.InstantiateNow <IUnitConvertor>(conversionEntry.ConvertorClass);
                }
                else
                {
                    if (conversionEntry.Multiplier == null)
                    {
                        throw new InvalidOperationException("Conversion must have convertor class or mutiplier");
                    }

                    m_convertor = new DefaultConvertor(conversionEntry.Multiplier.Value);
                }
            }
        public ReadOnlyUnitConversionMap(IEnumerable<IUnitConversion<double>> conversions, IEqualityComparer<IUnit> unitEqualityComparer = null)
            : base(unitEqualityComparer)
        {
            if (null == conversions) throw new ArgumentNullException("conversions");
            Contract.EndContractBlock();

            _allConversions = conversions.ToArray();
            _allDistinctUnits = _allConversions
                .Select(x => x.From)
                .Concat(_allConversions.Select(x => x.To))
                .Distinct(EqualityComparer)
                .ToArray();
            _fromMap = _allConversions
                .ToLookup(x => x.From, EqualityComparer)
                .ToDictionary(x => x.Key, x => x.ToArray(), EqualityComparer);
            _toMap = _allConversions
                .ToLookup(x => x.To, EqualityComparer)
                .ToDictionary(x => x.Key, x => x.ToArray(), EqualityComparer);
        }
Example #15
0
        public IMaterialUnit GetSmallestCompatibleUnit(IMaterialUnit u)
        {
            IUnitConversion smallest = null;

            foreach (var conversion in GetAllConversions().Where(c => c.SourceUnitId == u.Id))
            {
                if ((smallest?.Multiplier ?? 1) < conversion.Multiplier)
                {
                    smallest = conversion;
                }
            }

            if (smallest == null)
            {
                return(u);
            }

            return(m_unitRepository.GetUnit(smallest.TargetUnitId));
        }
Example #16
0
        private bool ConversionIsUnity(IUnitConversion <double> conversion)
        {
            if (conversion == null)
            {
                return(false);
            }
            if (conversion is UnitUnityConversion)
            {
                return(true);
            }

            var scalar = conversion as IUnitScalarConversion <double>;

            if (scalar != null)
            {
                return(scalar.Factor == 1.0);
            }

            return(false);
        }
Example #17
0
 private Length(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #18
0
 /// <summary>
 /// Protected Constructor
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 protected Dimension(string abbreviation, IUnitConversion toBase = null, IUnitConversion fromBase = null)
     : this(abbreviation)
 {
     ToBase   = toBase ?? BaseDimensionUnitConversion.DefaultConversion;
     FromBase = fromBase ?? BaseDimensionUnitConversion.DefaultConversion;
 }
Example #19
0
 private Prefix(string abbreviation = null, IUnitConversion toBase = null, IUnitConversion fromBase = null)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #20
0
 private SubstanceAmount(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #21
0
 /// <summary>
 /// Protected Constructor
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="arc"></param>
 /// <param name="radius"></param>
 protected PlanarAngleBase(string abbreviation,
                           IUnitConversion toBase, IUnitConversion fromBase,
                           ILength arc, ILength radius)
     : base(abbreviation, toBase, fromBase, arc, radius)
 {
 }
 public SpheroidLinearUnitConversionWrapper(ISpheroidInfo spheroid, IUnitConversion <double> conversion)
     : this(spheroid, conversion.To, conversion.TransformValue(spheroid.A), conversion.TransformValue(spheroid.B))
 {
     Contract.Requires(spheroid != null);
     Contract.Requires(conversion != null);
 }
Example #23
0
 private Prefix(string abbreviation = null, IUnitConversion toBase = null, IUnitConversion fromBase = null)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #24
0
 /// <summary>
 /// Private Constructor
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="mass"></param>
 /// <param name="acceleration"></param>
 private Force(string abbreviation,
     IUnitConversion toBase, IUnitConversion fromBase,
     IMass mass, IAcceleration acceleration)
     : base(abbreviation, toBase, fromBase, mass, acceleration)
 {
 }
Example #25
0
 private Length(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #26
0
 private Temperature(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #27
0
 public InvertedConversion(IUnitConversion source)
 {
     Multiplier   = 1m / (source.Multiplier ?? 1m);
     SourceUnitId = source.TargetUnitId;
     TargetUnitId = source.SourceUnitId;
 }
Example #28
0
 private Temperature(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #29
0
 private SubstanceAmount(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #30
0
 private SolidAngle(string abbreviation,
     IUnitConversion toBase, IUnitConversion fromBase,
     IArea surfaceArea, ILength squareRadius)
     : base(abbreviation, toBase, fromBase, surfaceArea, squareRadius)
 {
 }
Example #31
0
 private Force(string abbreviation,
               IUnitConversion toBase, IUnitConversion fromBase,
               IMass mass, IAcceleration acceleration)
     : base(abbreviation, toBase, fromBase, mass, acceleration)
 {
 }
 public SpheroidLinearUnitConversionWrapper(ISpheroidInfo spheroid, IUnitConversion<double> conversion)
     : this(spheroid, conversion.To, conversion.TransformValue(spheroid.A), conversion.TransformValue(spheroid.B))
 {
     Contract.Requires(spheroid != null);
     Contract.Requires(conversion != null);
 }
Example #33
0
 /// <summary>
 /// Protected Constructor
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 /// <param name="arc"></param>
 /// <param name="radius"></param>
 protected PlanarAngleBase(string abbreviation,
     IUnitConversion toBase, IUnitConversion fromBase,
     ILength arc, ILength radius)
     : base(abbreviation, toBase, fromBase, arc, radius)
 {
 }
Example #34
0
 private SolidAngle(string abbreviation,
                    IUnitConversion toBase, IUnitConversion fromBase,
                    IArea surfaceArea, ILength squareRadius)
     : base(abbreviation, toBase, fromBase, surfaceArea, squareRadius)
 {
 }
Example #35
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 protected BaseDimension(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #36
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 protected EnergyBase(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #37
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 protected BaseDimension(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }
Example #38
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="abbreviation"></param>
 /// <param name="toBase"></param>
 /// <param name="fromBase"></param>
 protected EnergyBase(string abbreviation, IUnitConversion toBase, IUnitConversion fromBase)
     : base(abbreviation, toBase, fromBase)
 {
 }