public void Setup()
        {
            _graph = new ConversionGraph();

            var meter = SI.Length.Meter;
            var mile  = US.Length.Mile;
            var feet  = US.Length.Foot;

            feet.PluralizeAs("feet");

            var kilometer = SI.Length.Kilometer.HasCounterPart(mile);

            var nanofoot  = new Unit("nanofoot").SystemIs("US");
            var nanometer = new Unit("nanometer").SystemIs("metric");
            var picometer = new Unit("picometer").SystemIs("metric");

            nanofoot.HasCounterPart(nanometer);

            _graph.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));
            _graph.AddConversion(Conversions.One(kilometer).In(meter).Is(1000M));
            _graph.AddConversion(Conversions.One(mile).In(feet).Is(5280M));
            _graph.AddConversion(Conversions.From(feet).To(nanofoot).MultiplyBy(0.000000001M));
            _graph.AddConversion(Conversions.From(picometer).To(nanometer).MultiplyBy(0.001M));
            _graph
            .RoundUsing(MidpointRounding.AwayFromZero)
            .RoundToDecimalPlaces(4);
        }
Exemplo n.º 2
0
        public void Setup()
        {
            _graph = new ConversionGraph();

            var meter = SI.Length.Meter;

            meter
            .UsePluralFormat("{0}s")
            .CanBeAbbreviated("mtr")
            .IsAlsoCalled("Metres");

            var feet = US.Length.Foot;

            feet.PluralizeAs("feet");

            Conversion c = Conversions.One(meter).In(feet).Is(3.28084M);

            _graph.AddConversion(c);

            Conversion x = Conversions.One(SI.Length.Kilometer).In(meter).Is(1000M);

            _graph.AddConversion(x);

            _graph
            .RoundUsing(MidpointRounding.AwayFromZero)
            .RoundToDecimalPlaces(4);
        }
Exemplo n.º 3
0
        public void Setup()
        {
            _graph = new ConversionGraph();

            var meter = SI.Length.Meter;
            var mile = US.Length.Mile;
            var feet = US.Length.Foot;
            feet.PluralizeAs("feet");

            var kilometer = SI.Length.Kilometer.HasCounterPart(mile);

            var nanofoot = new Unit("nanofoot").SystemIs("US");
            var nanometer = new Unit("nanometer").SystemIs("metric");
            var picometer = new Unit("picometer").SystemIs("metric");
            nanofoot.HasCounterPart(nanometer);

            _graph.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));
            _graph.AddConversion(Conversions.One(kilometer).In(meter).Is(1000M));
            _graph.AddConversion(Conversions.One(mile).In(feet).Is(5280M));
            _graph.AddConversion(Conversions.From(feet).To(nanofoot).MultiplyBy(0.000000001M));
            _graph.AddConversion(Conversions.From(picometer).To(nanometer).MultiplyBy(0.001M));
            _graph
                .RoundUsing(MidpointRounding.AwayFromZero)
                .RoundToDecimalPlaces(4);
        }
Exemplo n.º 4
0
        public void UnitNames()
        {
            var meter = new Unit("meter")
                        .IsAlsoCalled("metre")
                        .CanBeAbbreviated("m", "mtr")
                        .UsePluralFormat("{0}s");

            var feet = new Unit("foot")
                       .PluralizeAs("feet")
                       .CanBeAbbreviated("ft");

            var system = new ConversionGraph()
                         .RoundToDecimalPlaces(5);

            system.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));

            var meterMeasurement = new Measurement(meter, 1);
            var feetMeasurement  = new Measurement(feet, 2);

            var x = system.Convert(meterMeasurement, feet);

            Assert.That(system.Convert(meterMeasurement, feet) == 3.28084M);
            Assert.That(system.Convert(meterMeasurement, "ft") == 3.28084M);
            Assert.That(system.Convert(feetMeasurement, "metre") == 0.6096M);
            Assert.That(system.Convert(feetMeasurement, "mtr") == 0.6096M);
            Assert.That(system.Convert(feetMeasurement, "m") == 0.6096M);

            Assert.That(meterMeasurement.ToAbbreviatedString() == "1 m");
            Assert.That(meterMeasurement.ToString() == "1 meter");

            Assert.That(feetMeasurement.ToAbbreviatedString() == "2 ft");
            Assert.That(feetMeasurement.ToString() == "2 feet");
        }
Exemplo n.º 5
0
        public void UnitNames()
        {
            var meter = new Unit("meter")
                .IsAlsoCalled("metre")
                .CanBeAbbreviated("m", "mtr")
                .UsePluralFormat("{0}s");

            var feet = new Unit("foot")
                .PluralizeAs("feet")
                .CanBeAbbreviated("ft");

            var system = new ConversionGraph()
                .RoundToDecimalPlaces(5);

            system.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));

            var meterMeasurement = new Measurement(meter, 1);
            var feetMeasurement = new Measurement(feet, 2);

            var x = system.Convert(meterMeasurement, feet);

            Assert.That(system.Convert(meterMeasurement, feet) == 3.28084M);
            Assert.That(system.Convert(meterMeasurement, "ft") == 3.28084M);
            Assert.That(system.Convert(feetMeasurement, "metre") == 0.6096M);
            Assert.That(system.Convert(feetMeasurement, "mtr") == 0.6096M);
            Assert.That(system.Convert(feetMeasurement, "m") == 0.6096M);

            Assert.That(meterMeasurement.ToAbbreviatedString() == "1 m");
            Assert.That(meterMeasurement.ToString() == "1 meter");

            Assert.That(feetMeasurement.ToAbbreviatedString() == "2 ft");
            Assert.That(feetMeasurement.ToString() == "2 feet");
        }
Exemplo n.º 6
0
        public static double ConvertToMetre(double d, string unitMeasure)
        {
            Unit meter             = new Unit("meter").IsAlsoCalled("metre").CanBeAbbreviated("m");
            Unit angstrom          = new Unit("ångström").CanBeAbbreviated("Å");
            Unit nanometer         = new Unit("nanometer").CanBeAbbreviated("nm");
            Unit astronomical_unit = new Unit("astronomical unit").CanBeAbbreviated("ua");
            Unit chain             = new Unit("chain").CanBeAbbreviated("ch");
            Unit fathom            = new Unit("fathom");
            Unit femtometer        = new Unit("femtometer").CanBeAbbreviated("fm");
            Unit fermi             = new Unit("fermi");
            Unit foot       = new Unit("foot").CanBeAbbreviated("ft");
            Unit inch       = new Unit("inch").CanBeAbbreviated("in");
            Unit light_year = new Unit("light year").CanBeAbbreviated("l. y.");
            Unit microinch  = new Unit("microinch");
            Unit micrometer = new Unit("micrometer").CanBeAbbreviated("μm");
            Unit micron     = new Unit("micron").CanBeAbbreviated("μ");
            Unit mil        = new Unit("mil");
            Unit mile       = new Unit("mile").CanBeAbbreviated("mi");
            Unit kilometer  = new Unit("kilometer").CanBeAbbreviated("km");
            Unit parsec     = new Unit("parsec").CanBeAbbreviated("pc");
            Unit pica       = new Unit("pica");
            Unit millimeter = new Unit("millimeter").CanBeAbbreviated("mm");
            Unit point      = new Unit("point");
            Unit rod        = new Unit("rod").CanBeAbbreviated("rd");
            Unit yard       = new Unit("yard").CanBeAbbreviated("yd");

            ConversionGraph system = new ConversionGraph();

            system.AddConversion(
                Conversions.From(angstrom).To(meter).MultiplyBy(1.0E-10m),
                Conversions.From(angstrom).To(nanometer).MultiplyBy(1.0E-01m),
                Conversions.From(astronomical_unit).To(meter).MultiplyBy(1.495979E+11m),
                Conversions.From(chain).To(meter).MultiplyBy(2.011684E+1m),
                Conversions.From(fathom).To(meter).MultiplyBy(1.828804E+00m),
                Conversions.From(fermi).To(meter).MultiplyBy(1.0E-15m),
                Conversions.From(fermi).To(femtometer).MultiplyBy(1.0E+00m),
                Conversions.From(foot).To(meter).MultiplyBy(3.048E-01m),
                Conversions.From(inch).To(meter).MultiplyBy(2.54E-02m),
                Conversions.From(light_year).To(meter).MultiplyBy(9.46073E+15m),
                Conversions.From(microinch).To(meter).MultiplyBy(2.54E-08m),
                Conversions.From(microinch).To(micrometer).MultiplyBy(2.54E-02m),
                Conversions.From(micron).To(meter).MultiplyBy(1.0E-06m),
                Conversions.From(micron).To(micrometer).MultiplyBy(1.0E+00m),
                Conversions.From(mil).To(meter).MultiplyBy(2.54E-05m),
                Conversions.From(mil).To(millimeter).MultiplyBy(2.54E-02m),
                Conversions.From(mile).To(meter).MultiplyBy(1.609344E+03m),
                Conversions.From(mile).To(kilometer).MultiplyBy(1.609344E+00m),
                Conversions.From(parsec).To(meter).MultiplyBy(3.085678E+16m),
                Conversions.From(pica).To(meter).MultiplyBy(4.233333E-03m),
                Conversions.From(pica).To(millimeter).MultiplyBy(4.233333E+00m),
                Conversions.From(point).To(meter).MultiplyBy(3.527778E-04m),
                Conversions.From(point).To(millimeter).MultiplyBy(3.527778E-01m),
                Conversions.From(rod).To(meter).MultiplyBy(5.029210E+00m),
                Conversions.From(yard).To(meter).MultiplyBy(9.144E-01m));

            Measurement measurement = new Measurement(unitMeasure, (decimal)d);

            return((double)system.Convert(measurement, meter));
        }
Exemplo n.º 7
0
        public void Setup()
        {
            _graph = new ConversionGraph()
                .RoundUsing(MidpointRounding.AwayFromZero)
                .RoundToDecimalPlaces(4);

            var fahrenheit = US.Temperature.Fahrenheit;
            var celcius = SI.Temperature.Celcius;

            _graph.AddConversion(
                Conversions.From(fahrenheit).To(celcius).Subtract(32).MultiplyBy(5M / 9M));

            _graph.AddConversion(Conversions.From(celcius).To(new Unit("Kelvin")).Add(273.15M));

            SI.Temperature.Celcius
                .CanBeAbbreviated("C", "°C")
                .IsAlsoCalled("centigrade", "celcius", "Centigrade");
        }
Exemplo n.º 8
0
        public void Setup()
        {
            _graph = new ConversionGraph()
                     .RoundUsing(MidpointRounding.AwayFromZero)
                     .RoundToDecimalPlaces(4);

            var fahrenheit = US.Temperature.Fahrenheit;
            var celcius    = SI.Temperature.Celcius;

            _graph.AddConversion(
                Conversions.From(fahrenheit).To(celcius).Subtract(32).MultiplyBy(5M / 9M));

            _graph.AddConversion(Conversions.From(celcius).To(new Unit("Kelvin")).Add(273.15M));

            SI.Temperature.Celcius
            .CanBeAbbreviated("C", "°C")
            .IsAlsoCalled("centigrade", "celcius", "Centigrade");
        }
Exemplo n.º 9
0
        public void Setup()
        {
            _graph = new ConversionGraph();

            var meter = SI.Length.Meter;
            var feet = US.Length.Foot;
            var kilometer = SI.Length.Kilometer;

            Conversion c = Conversions.One(meter).In(feet).Is(3.28084M);

            _graph.AddConversion(c);

            Conversion x = Conversions.One(kilometer).In(meter).Is(1000M);

            _graph.AddConversion(x);

            _graph
                .RoundUsing(MidpointRounding.AwayFromZero)
                .RoundToDecimalPlaces(4);
        }
Exemplo n.º 10
0
        public void Setup()
        {
            _graph = new ConversionGraph();

            var meter     = SI.Length.Meter;
            var feet      = US.Length.Foot;
            var kilometer = SI.Length.Kilometer;

            Conversion c = Conversions.One(meter).In(feet).Is(3.28084M);

            _graph.AddConversion(c);

            Conversion x = Conversions.One(kilometer).In(meter).Is(1000M);

            _graph.AddConversion(x);

            _graph
            .RoundUsing(MidpointRounding.AwayFromZero)
            .RoundToDecimalPlaces(4);
        }
Exemplo n.º 11
0
        public static ConversionGraph Volume()
        {
            var graph = new ConversionGraph();

            var gallons = US.Volume.Gallon;
            var liter = SI.Volume.Liter;

            graph.AddConversion(
                Conversions.From(gallons).To(liter).MultiplyBy(3.78541M));

            return graph;
        }
Exemplo n.º 12
0
        public static ConversionGraph Time()
        {
            var graph = new ConversionGraph();

            var seconds = SI.Time.Second;
            var minutes = SI.Time.Minute;
            var hours = SI.Time.Hour;

            graph.AddConversion(
                Conversions.From(hours).To(minutes).MultiplyBy(60),
                Conversions.From(minutes).To(seconds).MultiplyBy(60)
                );

            return graph;
        }
Exemplo n.º 13
0
        public void DollarsToYen()
        {
            var dollar = new Unit("dollar")
                .UsePluralFormat("{0}s");

            var yen = new Unit("yen");

            var system = new ConversionGraph().RoundToDecimalPlaces(2);

            system.AddConversion(Conversions.One(dollar).In(yen).Is(78.5300M));

            var dollarAmount = new Measurement(dollar, 10);
            var yenAmount = new Measurement(yen, 10000);

            Assert.That(system.Convert(dollarAmount, yen) == 785.30M);
            Assert.That(system.Convert(yenAmount, dollar) == 127.34M);
        }
Exemplo n.º 14
0
        public void DollarsToYen()
        {
            var dollar = new Unit("dollar")
                         .UsePluralFormat("{0}s");

            var yen = new Unit("yen");

            var system = new ConversionGraph().RoundToDecimalPlaces(2);

            system.AddConversion(Conversions.One(dollar).In(yen).Is(78.5300M));

            var dollarAmount = new Measurement(dollar, 10);
            var yenAmount    = new Measurement(yen, 10000);

            Assert.That(system.Convert(dollarAmount, yen) == 785.30M);
            Assert.That(system.Convert(yenAmount, dollar) == 127.34M);
        }
Exemplo n.º 15
0
        public void IndirectConversion()
        {
            var system = new ConversionGraph();

            var meter = new Unit("meter");
            var kilometer = new Unit("kilometer");
            var foot = new Unit("foot");

            system.AddConversion(
                Conversions.From(kilometer).To(meter).MultiplyBy(1000M),
                Conversions.From(meter).To(foot).MultiplyBy(3.28084M)
                );

            var measurement = new Measurement(kilometer, 100M);

            Assert.That(system.Convert(measurement, foot) == 328084M);

            Assert.That(system.Convert(new Measurement(foot, 328084M), kilometer) == 100M);
        }
Exemplo n.º 16
0
        public void IndirectConversion()
        {
            var system = new ConversionGraph();

            var meter     = new Unit("meter");
            var kilometer = new Unit("kilometer");
            var foot      = new Unit("foot");

            system.AddConversion(
                Conversions.From(kilometer).To(meter).MultiplyBy(1000M),
                Conversions.From(meter).To(foot).MultiplyBy(3.28084M)
                );

            var measurement = new Measurement(kilometer, 100M);

            Assert.That(system.Convert(measurement, foot) == 328084M);

            Assert.That(system.Convert(new Measurement(foot, 328084M), kilometer) == 100M);
        }
Exemplo n.º 17
0
        public static double ConvertToSquareMetre(double d, string unitMeasure)
        {
            Unit square_meter              = new Unit("square meter").CanBeAbbreviated("m2", "m^2");
            Unit acre                      = new Unit("acre");
            Unit are                       = new Unit("are").CanBeAbbreviated("a");
            Unit barn                      = new Unit("barn").CanBeAbbreviated("b");
            Unit circular_mil              = new Unit("circular mil");
            Unit square_millimeter         = new Unit("square millimeter").CanBeAbbreviated("mm2", "mm^2");
            Unit foot_to_the_fourth_power  = new Unit("foot to the fourth power").CanBeAbbreviated("ft4", "ft^4");
            Unit meter_to_the_fourth_power = new Unit("meter to the fourth power").CanBeAbbreviated("m4", "m^4");
            Unit hectare                   = new Unit("hectare").CanBeAbbreviated("ha");
            Unit inch_to_the_fourth_power  = new Unit("inch to the fourth power").CanBeAbbreviated("in4", "in^4");
            Unit square_foot               = new Unit("square foot").CanBeAbbreviated("ft2", "ft^2");
            Unit square_inch               = new Unit("square inch").CanBeAbbreviated("in2", "in^2");
            Unit square_centimeter         = new Unit("square centimeter").CanBeAbbreviated("cm2", "cm^2");
            Unit square_mile               = new Unit("square mile").CanBeAbbreviated("mi2", "mi^2");
            Unit square_kilometer          = new Unit("square kilometer").CanBeAbbreviated("km2", "km^2");
            Unit square_yard               = new Unit("square yard ").CanBeAbbreviated("yd2", "yd^2");

            ConversionGraph system = new ConversionGraph();

            system.AddConversion(
                Conversions.From(acre).To(square_meter).MultiplyBy(4.046873E+03m),
                Conversions.From(are).To(square_meter).MultiplyBy(1.0E+02m),
                Conversions.From(barn).To(square_meter).MultiplyBy(1.0E-28m),
                Conversions.From(circular_mil).To(square_meter).MultiplyBy(5.067075E-10m),
                Conversions.From(circular_mil).To(square_millimeter).MultiplyBy(5.067075E-04m),
                Conversions.From(foot_to_the_fourth_power).To(meter_to_the_fourth_power).MultiplyBy(8.630975E-03m),
                Conversions.From(hectare).To(square_meter).MultiplyBy(1.0E+04m),
                Conversions.From(inch_to_the_fourth_power).To(meter_to_the_fourth_power).MultiplyBy(4.162314E-07m),
                Conversions.From(square_foot).To(square_meter).MultiplyBy(9.290304E-02m),
                Conversions.From(square_inch).To(square_meter).MultiplyBy(6.4516E-04m),
                Conversions.From(square_inch).To(square_centimeter).MultiplyBy(6.4516E+00m),
                Conversions.From(square_mile).To(square_meter).MultiplyBy(2.589988E+06m),
                Conversions.From(square_mile).To(square_kilometer).MultiplyBy(2.589988E+00m),
                Conversions.From(square_yard).To(square_meter).MultiplyBy(8.361274E-01m));

            Measurement measurement = new Measurement(unitMeasure, (decimal)d);

            return((double)system.Convert(measurement, square_meter));
        }
Exemplo n.º 18
0
        public static ConversionGraph Length()
        {
            var graph = new ConversionGraph();

            var meters = SI.Length.Meter;
            var kilometers = SI.Length.Kilometer;
            var feet = US.Length.Foot;
            var miles = US.Length.Mile;
            var inches = US.Length.Inch;
            var decimeters = SI.Length.Decimeter;
            var centimeters = SI.Length.Centimeter;
            var millimeters = SI.Length.Millimeter;
            var micrometers = SI.Length.Micrometer;
            var nanometers = SI.Length.Nanometer;
            var picometers = SI.Length.Picometer;
            var femtometers = SI.Length.Femtometer;
            var attometers = SI.Length.Attometer;
            var zeptometers = SI.Length.Zeptometer;
            var yoctometers = SI.Length.Yoctometer;

            graph.AddConversion(
                Conversions.From(meters).To(decimeters).MultiplyBy(10M),
                Conversions.From(decimeters).To(centimeters).MultiplyBy(10M),
                Conversions.From(centimeters).To(millimeters).MultiplyBy(10M),
                Conversions.From(millimeters).To(micrometers).MultiplyBy(1000M),
                Conversions.From(micrometers).To(nanometers).MultiplyBy(1000M),
                Conversions.From(nanometers).To(picometers).MultiplyBy(1000M),
                Conversions.From(picometers).To(femtometers).MultiplyBy(1000M),
                Conversions.From(femtometers).To(attometers).MultiplyBy(1000M),
                Conversions.From(attometers).To(zeptometers).MultiplyBy(1000M),
                Conversions.From(zeptometers).To(yoctometers).MultiplyBy(1000M),

                Conversions.From(meters).To(kilometers).DivideBy(1000M),
                Conversions.From(meters).To(feet).MultiplyBy(3.28084M),
                Conversions.From(feet).To(miles).DivideBy(0.000189394M),
                Conversions.From(feet).To(inches).MultiplyBy(12M)
                );

            return graph;
        }
Exemplo n.º 19
0
        private static void Main(string[] args)
        {
            // Quick and dirty example of generating graph images for debugging
            // This assumes you have Graphviz 2.28 installed

            var meter_to_feet = new ConversionGraph();

            var meter = new Unit("meter");
            var feet = new Unit("foot");

            meter_to_feet.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));

            meter_to_feet.ToDotFile("meter_feet.dot", VisualizationOptions.None);

            Process.Start(@"C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe", "-Tpng meter_feet.dot -o meter_feet.png");

            var more_complex = new ConversionGraph();

            var kilometer = new Unit("kilometer");
            var inches = new Unit("inch");

            more_complex.AddConversion(
                Conversions.From(kilometer).To(meter).MultiplyBy(1000M),
                Conversions.From(meter).To(feet).MultiplyBy(3.28084M),
                Conversions.From(feet).To(inches).MultiplyBy(12M)
                );

            more_complex.ToDotFile("more_complex.dot", VisualizationOptions.NumberEdges);

            Process.Start(@"C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe",
                          "-Tpng more_complex.dot -o more_complex.png");

            DefaultConfigurations.Length().ToDotFile("length.dot", VisualizationOptions.NumberEdges | VisualizationOptions.ShowSystem);

            Process.Start(@"C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe",
                          "-Tpng length.dot -o length.png");
        }
Exemplo n.º 20
0
        private static void Main(string[] args)
        {
            // Quick and dirty example of generating graph images for debugging
            // This assumes you have Graphviz 2.28 installed

            var meter_to_feet = new ConversionGraph();

            var meter = new Unit("meter");
            var feet  = new Unit("foot");

            meter_to_feet.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));

            meter_to_feet.ToDotFile("meter_feet.dot", VisualizationOptions.None);

            Process.Start(@"C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe", "-Tpng meter_feet.dot -o meter_feet.png");

            var more_complex = new ConversionGraph();

            var kilometer = new Unit("kilometer");
            var inches    = new Unit("inch");

            more_complex.AddConversion(
                Conversions.From(kilometer).To(meter).MultiplyBy(1000M),
                Conversions.From(meter).To(feet).MultiplyBy(3.28084M),
                Conversions.From(feet).To(inches).MultiplyBy(12M)
                );

            more_complex.ToDotFile("more_complex.dot", VisualizationOptions.NumberEdges);

            Process.Start(@"C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe",
                          "-Tpng more_complex.dot -o more_complex.png");

            DefaultConfigurations.Length().ToDotFile("length.dot", VisualizationOptions.NumberEdges | VisualizationOptions.ShowSystem);

            Process.Start(@"C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe",
                          "-Tpng length.dot -o length.png");
        }
Exemplo n.º 21
0
        public static double ConvertToSquareMetre(double d, string unitMeasure) {
            Unit square_meter = new Unit("square meter").CanBeAbbreviated("m2", "m^2");
            Unit acre = new Unit("acre");
            Unit are = new Unit("are").CanBeAbbreviated("a");
            Unit barn = new Unit("barn").CanBeAbbreviated("b");
            Unit circular_mil = new Unit("circular mil");
            Unit square_millimeter = new Unit("square millimeter").CanBeAbbreviated("mm2", "mm^2");
            Unit foot_to_the_fourth_power = new Unit("foot to the fourth power").CanBeAbbreviated("ft4", "ft^4");
            Unit meter_to_the_fourth_power = new Unit("meter to the fourth power").CanBeAbbreviated("m4", "m^4");
            Unit hectare = new Unit("hectare").CanBeAbbreviated("ha");
            Unit inch_to_the_fourth_power = new Unit("inch to the fourth power").CanBeAbbreviated("in4", "in^4");
            Unit square_foot = new Unit("square foot").CanBeAbbreviated("ft2", "ft^2");
            Unit square_inch = new Unit("square inch").CanBeAbbreviated("in2", "in^2");
            Unit square_centimeter = new Unit("square centimeter").CanBeAbbreviated("cm2", "cm^2");
            Unit square_mile = new Unit("square mile").CanBeAbbreviated("mi2", "mi^2");
            Unit square_kilometer = new Unit("square kilometer").CanBeAbbreviated("km2", "km^2");
            Unit square_yard = new Unit("square yard ").CanBeAbbreviated("yd2", "yd^2");

            ConversionGraph system = new ConversionGraph();
            system.AddConversion(
                Conversions.From(acre).To(square_meter).MultiplyBy((decimal)4.046873E+03),
                Conversions.From(are).To(square_meter).MultiplyBy((decimal)1.0E+02),
                Conversions.From(barn).To(square_meter).MultiplyBy((decimal)1.0E-28),
                Conversions.From(circular_mil).To(square_meter).MultiplyBy((decimal)5.067075E-10),
                Conversions.From(circular_mil).To(square_millimeter).MultiplyBy((decimal)5.067075E-04),
                Conversions.From(foot_to_the_fourth_power).To(meter_to_the_fourth_power).MultiplyBy((decimal)8.630975E-03),
                Conversions.From(hectare).To(square_meter).MultiplyBy((decimal)1.0E+04),
                Conversions.From(inch_to_the_fourth_power).To(meter_to_the_fourth_power).MultiplyBy((decimal)4.162314E-07),
                Conversions.From(square_foot).To(square_meter).MultiplyBy((decimal)9.290304E-02),
                Conversions.From(square_inch).To(square_meter).MultiplyBy((decimal)6.4516E-04),
                Conversions.From(square_inch).To(square_centimeter).MultiplyBy((decimal)6.4516E+00),
                Conversions.From(square_mile).To(square_meter).MultiplyBy((decimal)2.589988E+06),
                Conversions.From(square_mile).To(square_kilometer).MultiplyBy((decimal)2.589988E+00),
                Conversions.From(square_yard).To(square_meter).MultiplyBy((decimal)8.361274E-01));

            Measurement measurement = new Measurement(unitMeasure, (decimal)d);
            return (double)system.Convert(measurement, square_meter);
        }
Exemplo n.º 22
0
        public static double ConvertToMetre(double d, string unitMeasure) {
            Unit meter = new Unit("meter").IsAlsoCalled("metre").CanBeAbbreviated("m");
            Unit angstrom = new Unit("ångström").CanBeAbbreviated("Å");
            Unit nanometer = new Unit("nanometer").CanBeAbbreviated("nm");
            Unit astronomical_unit = new Unit("astronomical unit").CanBeAbbreviated("ua");
            Unit chain = new Unit("chain").CanBeAbbreviated("ch");
            Unit fathom = new Unit("fathom");
            Unit femtometer = new Unit("femtometer").CanBeAbbreviated("fm");
            Unit fermi = new Unit("fermi");
            Unit foot = new Unit("foot").CanBeAbbreviated("ft");
            Unit inch = new Unit("inch").CanBeAbbreviated("in");
            Unit light_year = new Unit("light year").CanBeAbbreviated("l. y.");
            Unit microinch = new Unit("microinch");
            Unit micrometer = new Unit("micrometer").CanBeAbbreviated("μm");
            Unit micron = new Unit("micron").CanBeAbbreviated("μ");
            Unit mil = new Unit("mil");
            Unit mile = new Unit("mile").CanBeAbbreviated("mi");
            Unit kilometer = new Unit("kilometer").CanBeAbbreviated("km");
            Unit parsec = new Unit("parsec").CanBeAbbreviated("pc");
            Unit pica = new Unit("pica");
            Unit millimeter = new Unit("millimeter").CanBeAbbreviated("mm");
            Unit point = new Unit("point");
            Unit rod = new Unit("rod").CanBeAbbreviated("rd");
            Unit yard = new Unit("yard").CanBeAbbreviated("yd");

            ConversionGraph system = new ConversionGraph();
            system.AddConversion(
                Conversions.From(angstrom).To(meter).MultiplyBy((decimal)1.0E-10),
                Conversions.From(angstrom).To(nanometer).MultiplyBy((decimal)1.0E-01),
                Conversions.From(astronomical_unit).To(meter).MultiplyBy((decimal)1.495979E+11),
                Conversions.From(chain).To(meter).MultiplyBy((decimal)2.011684E+1),
                Conversions.From(fathom).To(meter).MultiplyBy((decimal)1.828804E+00),
                Conversions.From(fermi).To(meter).MultiplyBy((decimal)1.0E-15),
                Conversions.From(fermi).To(femtometer).MultiplyBy((decimal)1.0E+00),
                Conversions.From(foot).To(meter).MultiplyBy((decimal)3.048E-01),
                Conversions.From(inch).To(meter).MultiplyBy((decimal)2.54E-02),
                Conversions.From(light_year).To(meter).MultiplyBy((decimal)9.46073E+15),
                Conversions.From(microinch).To(meter).MultiplyBy((decimal)2.54E-08),
                Conversions.From(microinch).To(micrometer).MultiplyBy((decimal)2.54E-02),

                Conversions.From(micron).To(meter).MultiplyBy((decimal)1.0E-06),
                Conversions.From(micron).To(micrometer).MultiplyBy((decimal)1.0E+00),
                Conversions.From(mil).To(meter).MultiplyBy((decimal)2.54E-05),
                Conversions.From(mil).To(millimeter).MultiplyBy((decimal)2.54E-02),
                Conversions.From(mile).To(meter).MultiplyBy((decimal)1.609344E+03),
                Conversions.From(mile).To(kilometer).MultiplyBy((decimal)1.609344E+00),
                Conversions.From(parsec).To(meter).MultiplyBy((decimal)3.085678E+16),
                Conversions.From(pica).To(meter).MultiplyBy((decimal)4.233333E-03),
                Conversions.From(pica).To(millimeter).MultiplyBy((decimal)4.233333E+00),
                Conversions.From(point).To(meter).MultiplyBy((decimal)3.527778E-04),
                Conversions.From(point).To(millimeter).MultiplyBy((decimal)3.527778E-01),
                Conversions.From(rod).To(meter).MultiplyBy((decimal)5.029210E+00),
                Conversions.From(yard).To(meter).MultiplyBy((decimal)9.144E-01));

            Measurement measurement = new Measurement(unitMeasure, (decimal)d);
            return (double)system.Convert(measurement, meter);
        }
Exemplo n.º 23
0
        public void Setup()
        {
            _graph = new ConversionGraph();

            var meter = SI.Length.Meter;

            meter
                .UsePluralFormat("{0}s")
                .CanBeAbbreviated("mtr")
                .IsAlsoCalled("Metres");

            var feet = US.Length.Foot;
            feet.PluralizeAs("feet");

            Conversion c = Conversions.One(meter).In(feet).Is(3.28084M);

            _graph.AddConversion(c);

            Conversion x = Conversions.One(SI.Length.Kilometer).In(meter).Is(1000M);

            _graph.AddConversion(x);

            _graph
                .RoundUsing(MidpointRounding.AwayFromZero)
                .RoundToDecimalPlaces(4);
        }