/// <summary> /// Gets abbreviated name of the length units. /// </summary> public static string GetAbbreviatedName(this LengthUnits units) { switch (units) { case LengthUnits.DecimalDegrees: return("deg."); case LengthUnits.Milimeters: return("mm"); case LengthUnits.Centimeters: return("cm"); case LengthUnits.Inches: return("in"); case LengthUnits.Feet: return("ft"); case LengthUnits.Yards: return("yd"); case LengthUnits.Meters: return("m"); case LengthUnits.Miles: return("mi"); case LengthUnits.Kilometers: return("km"); default: throw new ArgumentOutOfRangeException("units"); } }
private void ChangeToLenght(object sender, SelectionChangedEventArgs e) { var selectedIndex = ToLength.SelectedIndex; if (selectedIndex == 0) { ToLUnit = LengthUnits.Millimeter; } else if (selectedIndex == 1) { ToLUnit = LengthUnits.Centimeter; } else if (selectedIndex == 2) { ToLUnit = LengthUnits.Meter; } else if (selectedIndex == 3) { ToLUnit = LengthUnits.Kilometer; } else if (selectedIndex == 4) { ToLUnit = LengthUnits.Inch; } else if (selectedIndex == 5) { ToLUnit = LengthUnits.Feet; } }
/// <summary> /// Gets the conversion factor which defines a number of inches in a given length unit. /// </summary> public static double GetConversionFactor(this LengthUnits units) { switch (units) { case LengthUnits.DecimalDegrees: return(4366141.73); case LengthUnits.Milimeters: return(0.0393700787); case LengthUnits.Centimeters: return(0.393700787); case LengthUnits.Inches: return(1); case LengthUnits.Feet: return(12); case LengthUnits.Yards: return(36); case LengthUnits.Meters: return(39.3700787); case LengthUnits.Miles: return(63360); case LengthUnits.Kilometers: return(39370.0787); default: throw new ArgumentOutOfRangeException("units"); } }
public static string GetResult(LengthUnits method) { if (method == LengthUnits.Centimeter) { return("cm"); } else if (method == LengthUnits.Feet) { return("ft"); } else if (method == LengthUnits.Inch) { return("inch"); } else if (method == LengthUnits.Kilometer) { return("km"); } else if (method == LengthUnits.Meter) { return("m"); } else if (method == LengthUnits.Millimeter) { return("mm"); } return(""); }
static double ToPixel(double unit, LengthUnits type) { switch (type) { case LengthUnits.Inches: return(unit * 96.0); case LengthUnits.Feets: return(unit * 1152.0); case LengthUnits.Yards: return(unit * 3456.0); case LengthUnits.Miles: return(unit * 6082560.0); case LengthUnits.Millimeters: return(unit * 3.7795275590551185); case LengthUnits.Centimeters: return(unit * 37.795275590551185); case LengthUnits.Meters: return(unit * 3779.5275590551187); case LengthUnits.Kilometers: return(unit * 377952.75590551185); } return(unit); }
static double ToUnit(double pixel, LengthUnits type) { switch (type) { case LengthUnits.Inches: return(pixel / 96.0); case LengthUnits.Feets: return(pixel / 1152.0); case LengthUnits.Yards: return(pixel / 3456.0); case LengthUnits.Miles: return(pixel / 6082560.0); case LengthUnits.Millimeters: return(pixel / 3.7795275590551185); case LengthUnits.Centimeters: return(pixel / 37.795275590551185); case LengthUnits.Meters: return(pixel / 3779.5275590551187); case LengthUnits.Kilometers: return(pixel / 377952.75590551185); } return(pixel); }
protected esriUnits EsriUnits(LengthUnits unit) { switch (unit) { case LengthUnits.km: return(esriUnits.esriKilometers); case LengthUnits.m: return(esriUnits.esriMeters); case LengthUnits.dm: return(esriUnits.esriDecimeters); case LengthUnits.cm: return(esriUnits.esriCentimeters); case LengthUnits.mm: return(esriUnits.esriMillimeters); default: throw new ArgumentOutOfRangeException(nameof(unit), unit, string.Format("Unknown length units: {0}", unit)); } }
public static string GetLengthAbbreviationFromUnit(LengthUnits _unit) { string abbreviation = ""; switch (_unit) { case LengthUnits.Centimeters: abbreviation = "cm"; break; case LengthUnits.Meters: abbreviation = "m"; break; case LengthUnits.Inches: abbreviation = "in"; break; case LengthUnits.Feet: abbreviation = "ft"; break; case LengthUnits.Yards: abbreviation = "yd"; break; case LengthUnits.Pixels: default: abbreviation = "px"; break; } return(abbreviation); }
public static List<WeatherDetail> GetDetails (WuLocation location, TemperatureUnits temp, SpeedUnits speed, LengthUnits length, DistanceUnits distance, PressureUnits pressure) { var list = new List<WeatherDetail> (); for (int i = 0; i < Count; i++) list.Add (GetDetail (i, location, temp, speed, length, distance, pressure)); return list; }
public static WeatherDetail GetDetail (int row, WuLocation location, TemperatureUnits temp, SpeedUnits speed, LengthUnits length, DistanceUnits distance, PressureUnits pressure) { return new WeatherDetail { DetailLabel = GetLabel (row), DetailValue = GetValue (row, location, temp, speed, length, distance, pressure), IsSectionTop = IsSectionTop (row) }; }
private void inventorUnitsSelector_SelectedIndexChanged(object sender, EventArgs e) { var comboBox = sender as SfComboBox; if (comboBox != null) { _lengthUnits = (LengthUnits)comboBox.SelectedIndex; } }
/// <summary> /// The get page size. /// </summary> /// <param name="width"> /// The width. /// </param> /// <param name="height"> /// The height. /// </param> /// <param name="lengthUnits"> /// The length units. /// </param> /// <returns> /// The <see cref="Size"/>. /// </returns> private Size GetPageSize(double width, double height, LengthUnits lengthUnits) { if (this.PageOrientation == PageOrientation.Landscape) { return(new Size(this.Convert(width, lengthUnits), this.Convert(height, lengthUnits))); } return(new Size(this.Convert(height, lengthUnits), this.Convert(width, lengthUnits))); }
public static string FormatDistance(LengthUnits units, double distance) { if (units == LengthUnits.Meters) { return(distance > 1000.0 ? (distance / 1000.0).ToString("0.0 km") : distance.ToString("0.0 m")); } // TODO: format as well return(distance.ToString("0.0")); }
/// <summary> /// Should initialize all private data members which aren't set by deserialization. /// </summary> protected override void SetDefaults() { Name = "Scale Bar"; _font = new Font("Arial", 10); _color = Color.Black; _unit = LengthUnits.Kilometers; _numBreaks = 4; _textHint = TextRenderingHint.AntiAliasGridFit; _showScale = true; ResizeStyle = ResizeStyle.HandledInternally; }
public static double Convert(LengthUnits from, LengthUnits to, double value) { if (from == to) { return(value); } GeodesicUtils.ConvertDistance(from, to, ref value); return(value); }
public static string GetResult(string input, LengthUnits from, LengthUnits to) { var convertFrom = LengthUnitAsString.GetResult(from); var convertTo = LengthUnitAsString.GetResult(to); //convert input to mxParser string; input = $"{input}*[{convertFrom}] / [{convertTo}]"; Expression e = new Expression(input); return(e.calculate().ToString()); }
private Size GetPageSize( double width, double height, LengthUnits lengthUnits) { if (PageOrientation == PageOrientation.Landscape) { return new Size(Convert(width, lengthUnits), Convert(height, lengthUnits)); } else { return new Size(Convert(height, lengthUnits), Convert(width, lengthUnits)); } }
public static decimal ToMeter(this LengthUnits unit) { if (Ratio.ContainsKey(unit)) { return(Ratio[unit]); } var attribute = unit.GetType().GetField(Enum.GetName(typeof(LengthUnits), unit)).GetCustomAttribute <ToMeter>(); Ratio.GetOrAdd(unit, attribute.Meter); return(attribute.Meter); }
public void GeometryInfoMeasure(bool validTransform, bool cartesian, string name, List <NuGenGeometryWindowItem> rInfo, LengthUnits units) { int pNextRow = 0; foreach (NuGenPointSet pointset in measureList) { if (pointset.Name.Equals(name)) { pointset.GeometryInfo(validTransform, cartesian, ref pNextRow, rInfo, units); } } }
// return the geometry info for this pointset public void GeometryInfo(bool validTransform, bool cartesian, ref int pNextRow, List <NuGenGeometryWindowItem> rInfo, LengthUnits units) { rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, "Name:")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, name)); pNextRow++; rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, "Units:")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, validTransform ? units.ToString() + "s" : "Pixels")); pNextRow++; GeometryInfoArea(ref pNextRow, rInfo); GeometryInfoDistance(ref pNextRow, rInfo, cartesian); }
private static uint ComposeRawValue(LengthUnits lengthUnits, int len) { switch (lengthUnits) { case LengthUnits.BaseUnits: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len & 134217727)); case LengthUnits.Twips: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len * 8 & 134217727)); case LengthUnits.Points: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len * 160 & 134217727)); case LengthUnits.Picas: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len * 1920 & 134217727)); case LengthUnits.Inches: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len * 11520 & 134217727)); case LengthUnits.Centimeters: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len * 4535 & 134217727)); case LengthUnits.Millimeters: return(PropertyValue.GetRawType(PropertyType.AbsLength) | (uint)(len * 453 & 134217727)); case LengthUnits.HtmlFontUnits: return(PropertyValue.GetRawType(PropertyType.HtmlFontUnits) | (uint)(len & 134217727)); case LengthUnits.Pixels: return(PropertyValue.GetRawType(PropertyType.Pixels) | (uint)(len * 96 & 134217727)); case LengthUnits.Ems: return(PropertyValue.GetRawType(PropertyType.Ems) | (uint)(len * 160 & 134217727)); case LengthUnits.Exs: return(PropertyValue.GetRawType(PropertyType.Exs) | (uint)(len * 160 & 134217727)); case LengthUnits.RelativeHtmlFontUnits: return(PropertyValue.GetRawType(PropertyType.RelHtmlFontUnits) | (uint)(len & 134217727)); case LengthUnits.Percents: return(PropertyValue.GetRawType(PropertyType.Percentage) | (uint)(len & 134217727)); default: return(0U); } }
public static string GetValue (int row, WuLocation location, TemperatureUnits temp, SpeedUnits speed, LengthUnits length, DistanceUnits distance, PressureUnits pressure) { var conditions = location?.Conditions; if (conditions == null) return string.Empty; switch (row) { case 0: return conditions.FeelsLikeString (temp, true, true); case 1: return location.SunriseString (); case 2: return location.SunsetString (); case 3: return location.ProbabilityPercipString (); case 4: return conditions.relative_humidity; case 5: return conditions.WindString (speed); case 6: return conditions.GustString (speed); case 7: return conditions.PrecipTodayString (length); case 8: return conditions.PressureString (pressure); case 9: return conditions.VisibilityString (distance); case 10: return location.Conditions.UV.ToString (); default: return string.Empty; } }
public void SetLocation(LengthUnits unit, Double?left = null, Double?right = null, Double?top = null, Double?bottom = null, ElementPositions?position = null) { if (position != null) { Style.Position = position.Value; } if (left != null) { Style.Left = new LengthDescriptor(left.Value, unit); } if (right != null) { Style.Right = new LengthDescriptor(right.Value, unit); } if (top != null) { Style.Top = new LengthDescriptor(top.Value, unit); } if (bottom != null) { Style.Bottom = new LengthDescriptor(bottom.Value, unit); } }
public static double Unit( [ExcelArgument("Value")] double value, [ExcelArgument("Previous unit", Name = "previous_Unit")] string _prevUnit, [ExcelArgument("New unit", Name = "new_Unit")] string _newUnit) { double prevUnit; double newUnit; if (ForceUnits.TryGetValue(_prevUnit, out prevUnit) && ForceUnits.TryGetValue(_newUnit, out newUnit)) { return(value * newUnit / prevUnit); } else if (LengthUnits.TryGetValue(_prevUnit, out prevUnit) && LengthUnits.TryGetValue(_newUnit, out newUnit)) { return(value * newUnit / prevUnit); } else if (AreaUnits.TryGetValue(_prevUnit, out prevUnit) && AreaUnits.TryGetValue(_newUnit, out newUnit)) { return(value * newUnit / prevUnit); } else if (MomentUnits.TryGetValue(_prevUnit, out prevUnit) && MomentUnits.TryGetValue(_newUnit, out newUnit)) { return(value * newUnit / prevUnit); } else if (PressureUnits.TryGetValue(_prevUnit, out prevUnit) && PressureUnits.TryGetValue(_newUnit, out newUnit)) { return(value * newUnit / prevUnit); } else { return(double.NaN); } }
/// <summary> /// Converts the passed in length into the specified units /// </summary> /// <param name="len">The length to convert, in meters</param> /// <param name="units">The units to convert the length to</param> public static double?ConvertLength(double?len, LengthUnits units) { if (len == null) { return(null); } switch (units) { case LengthUnits.UnitsCentimeters: return(len * 100); case LengthUnits.UnitsMeters: return(len); case LengthUnits.UnitsKilometers: return(len * 0.001); case LengthUnits.UnitsInches: return(len * 39.3700787); case LengthUnits.UnitsFeet: return(len * 3.2808399); case LengthUnits.UnitsYards: return(len * 1.0936133); case LengthUnits.UnitsMiles: return(len * 0.0006213700922); case LengthUnits.UnitsNauticalMiles: return(len * 0.000539956803); } return(len); }
static double getValueInUnits (LengthUnits units, double? imperial, double? metric, bool round = false) => getValueInUnits (units.IsImperial (), imperial, metric, round);
private double ConvertLengthForSpeedUnit(double _fLength, LengthUnits _lengthUnit, SpeedUnits _speedUnits) { // Convert from one length unit to another. // For example: user calibrated the screen using centimeters and wants a speed in km/h. // We get a distance in centimeters, we convert it to kilometers. // http://en.wikipedia.org/wiki/Conversion_of_units // 1 inch = 0.0254 m. // 1 foot = 0.3048 m. // 1 yard = 0.9144 m. // 1 mile = 1 609.344 m. // 1 nautical mile = 1 852 m. double fLength2 = 0; switch (_lengthUnit) { case LengthUnits.Centimeters: switch (_speedUnits) { case SpeedUnits.FeetPerSecond: // Centimeters to feet. fLength2 = _fLength / 30.48; break; case SpeedUnits.MetersPerSecond: // Centimeters to meters. fLength2 = _fLength / 100; break; case SpeedUnits.KilometersPerHour: // Centimeters to kilometers. fLength2 = _fLength / 100000; break; case SpeedUnits.MilesPerHour: // Centimeters to miles fLength2 = _fLength / 160934.4; break; case SpeedUnits.Knots: // Centimeters to nautical miles fLength2 = _fLength / 185200; break; case SpeedUnits.PixelsPerFrame: default: // Centimeters to Pixels. (?) // User has calibrated the image but now wants the speed in px/f. fLength2 = _fLength / m_fPixelToUnit; break; } break; case LengthUnits.Meters: switch (_speedUnits) { case SpeedUnits.FeetPerSecond: // Meters to feet. fLength2 = _fLength / 0.3048; break; case SpeedUnits.MetersPerSecond: // Meters to meters. fLength2 = _fLength; break; case SpeedUnits.KilometersPerHour: // Meters to kilometers. fLength2 = _fLength / 1000; break; case SpeedUnits.MilesPerHour: // Meters to miles. fLength2 = _fLength / 1609.344; break; case SpeedUnits.Knots: // Meters to nautical miles. fLength2 = _fLength / 1852; break; case SpeedUnits.PixelsPerFrame: default: // Meters to Pixels. (revert) fLength2 = _fLength / m_fPixelToUnit; break; } break; case LengthUnits.Inches: switch (_speedUnits) { case SpeedUnits.FeetPerSecond: // Inches to feet. fLength2 = _fLength / 12; break; case SpeedUnits.MetersPerSecond: // Inches to meters. fLength2 = _fLength / 39.3700787; break; case SpeedUnits.KilometersPerHour: // Inches to kilometers. fLength2 = _fLength / 39370.0787; break; case SpeedUnits.MilesPerHour: // Inches to miles. fLength2 = _fLength / 63360; break; case SpeedUnits.Knots: // Inches to nautical miles. fLength2 = _fLength / 72913.3858; break; case SpeedUnits.PixelsPerFrame: default: // Inches to Pixels. (revert) fLength2 = _fLength / m_fPixelToUnit; break; } break; case LengthUnits.Feet: switch (_speedUnits) { case SpeedUnits.FeetPerSecond: // Feet to feet. fLength2 = _fLength; break; case SpeedUnits.MetersPerSecond: // Feet to meters. fLength2 = _fLength / 3.2808399; break; case SpeedUnits.KilometersPerHour: // Feet to kilometers. fLength2 = _fLength / 3280.8399; break; case SpeedUnits.MilesPerHour: // Feet to miles. fLength2 = _fLength / 5280; break; case SpeedUnits.Knots: // Feet to nautical miles. fLength2 = _fLength / 6076.11549; break; case SpeedUnits.PixelsPerFrame: default: // Feet to Pixels. (revert) fLength2 = _fLength / m_fPixelToUnit; break; } break; case LengthUnits.Yards: switch (_speedUnits) { case SpeedUnits.FeetPerSecond: // Yards to feet. fLength2 = _fLength * 3; break; case SpeedUnits.MetersPerSecond: // Yards to meters. fLength2 = _fLength / 1.0936133; break; case SpeedUnits.KilometersPerHour: // Yards to kilometers. fLength2 = _fLength / 1093.6133; break; case SpeedUnits.MilesPerHour: // Yards to miles. fLength2 = _fLength / 1760; break; case SpeedUnits.Knots: // Yards to nautical miles. fLength2 = _fLength / 2025.37183; break; case SpeedUnits.PixelsPerFrame: default: // Yards to Pixels. (revert) fLength2 = _fLength / m_fPixelToUnit; break; } break; case LengthUnits.Pixels: default: // If input length is in pixel, this means the image is not calibrated. // Unless the target speed unit is pixel per frame, we can't compute the speed. if (_speedUnits != SpeedUnits.PixelsPerFrame) { fLength2 = 0; log.Error("Can't compute speed : image is not calibrated and speed is required in real world units."); } else { fLength2 = _fLength; } break; } return(fLength2); }
public LengthDescriptor(double value = 0.0, LengthUnits unit = LengthUnits.Unknown) { Value = value; Unit = unit; }
public double Convert(double value, LengthUnits from, LengthUnits to) { return(ToUnit(ToPixel(value, from), to)); }
private double Convert(double value, LengthUnits from) { LengthUnit unit = Unit as LengthUnit; return(unit.Convert(value, from, SelectedUnit)); }
public static double PrecipToday (this CurrentObservation observation, LengthUnits units, bool round = false) => getValueInUnits (units, observation?.precip_today_in, observation?.precip_today_metric, round);
public static bool ConvertDistance(LengthUnits sourceUnit, LengthUnits targetUnit, ref double value) { return(GisUtils.Instance.GetInternal().ConvertDistance((tkUnitsOfMeasure)sourceUnit, (tkUnitsOfMeasure)targetUnit, ref value)); }
public static string PrecipTodayString (this CurrentObservation observation, LengthUnits units, bool round = false) => getValueStringInUnits (observation.PrecipToday (units, round), units);
public Length(LengthUnits currentUnit = LengthUnits.m) : base(currentUnit) { DefaultUnit = LengthUnits.m; }
// Called when map units are retrieved private void OnGetMapUnitsCompleted(LengthUnits units) { // Update map units and calculate result extent width _mapUnits = units; if (_mapUnits == LengthUnits.UnitsDecimalDegrees) // calculate in meters if map units are decimal degrees _extentWidthInMapUnits = Utils.ConvertLength(ExtentWidth, WidthUnit, LengthUnits.UnitsMeters); else _extentWidthInMapUnits = Utils.ConvertLength(ExtentWidth, WidthUnit, _mapUnits); // set flag indicating retrieval has completed _gotMapUnits = true; // handle any results that were returned while map units were being retrieved if (_queuedResults.Count > 0) { LocatorResultViewModel result = _queuedResults.Dequeue(); while (result != null) { initializeResultExtent(result); _results.Add(result); result = _queuedResults.Dequeue(); } } }
public Length(double quantity, LengthUnits units) { Quantity = quantity; Units = units; }
// return the geometry info for this pointset public void GeometryInfo(bool validTransform, bool cartesian, ref int pNextRow, List<NuGenGeometryWindowItem> rInfo, LengthUnits units) { rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, "Name:")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, name)); pNextRow++; rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 0, "Units:")); rInfo.Add(new NuGenGeometryWindowItem(pNextRow, 1, validTransform ? units.ToString() + "s" : "Pixels")); pNextRow++; GeometryInfoArea(ref pNextRow, rInfo); GeometryInfoDistance(ref pNextRow, rInfo, cartesian); }
static string getValueStringInUnits (double value, LengthUnits unit) => $"{value} {unit.getUnitString ()}";
public PointPair(LengthUnits units, int index) { _units = units; Index = index; }
private string Abbreviation(LengthUnits lengthUnits) { switch (lengthUnits) { case LengthUnits.Angstrom : return "Å"; case LengthUnits.AstronomicalUnit: return "AU"; case LengthUnits.Centimeter : return "cm"; case LengthUnits.Decimeter : return "dm"; case LengthUnits.Fathom: return "fathom"; case LengthUnits.Foot: return "ft"; case LengthUnits.Inch: return "in"; case LengthUnits.Kilometer: return "km"; case LengthUnits.LightYear: return "ly"; case LengthUnits.Meter: return "m"; case LengthUnits.Micrometer: return "mµ"; case LengthUnits.Mile: return "mile"; case LengthUnits.Milimeter: return "mm"; case LengthUnits.Nanometer: return "nm"; case LengthUnits.Parsec: return "parsec"; case LengthUnits.Picometer: return "pm"; case LengthUnits.Unitless: return ""; case LengthUnits.Yard: return "yd"; } return ""; }