Skip to content

Commit

Permalink
Change replacement token in json files from x to {x}
Browse files Browse the repository at this point in the history
To distinguish from constant fields and other names with `x` in them.
  • Loading branch information
tmilnthorp authored Feb 3, 2022
1 parent 2ef6659 commit 8d2eeb6
Show file tree
Hide file tree
Showing 116 changed files with 1,270 additions and 1,270 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ For a fairly complete summary of the unit definition JSON schema, see [Meter of
### Conversion functions
Converting from unit A to B is achieved by first converting from unit A to the base unit, then from the base unit to unit B. To achieve this, each unit defines two conversion functions.

* Prefer multiplication for `FromUnitToBaseFunc` (`x*2.54e-2` for `Inch` to `Meter`)
* Prefer division for `FromBaseToUnitFunc` (`x/2.54e-2` for `Meter` to `Inch`)
* Prefer multiplication for `FromUnitToBaseFunc` (`{x}*2.54e-2` for `Inch` to `Meter`)
* Prefer division for `FromBaseToUnitFunc` (`{x}/2.54e-2` for `Meter` to `Inch`)
* Prefer scientific notation `1e3` and `1e-5` instead of `1000` and `0.00001`
* Prefer a constant if the conversion factor is finite (`x*2.54e-2` for `Inch`)
* Prefer a calculation if the conversion factor is infinite (`(x/72.27)*2.54e-2` for `PrinterPoint`)
* Prefer a constant if the conversion factor is finite (`{x}*2.54e-2` for `Inch`)
* Prefer a calculation if the conversion factor is infinite (`({x}/72.27)*2.54e-2` for `PrinterPoint`)

### Units
Generally we try to name the units as what is the most widely used.
Expand Down
4 changes: 2 additions & 2 deletions CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void GenerateConversionMethods()
{{");
foreach (var unit in _quantity.Units)
{
var func = unit.FromUnitToBaseFunc.Replace("x", "_value");
var func = unit.FromUnitToBaseFunc.Replace("{x}", "_value");
Writer.WL($@"
case {_unitEnumName}.{unit.SingularName}: return {func};");
}
Expand All @@ -230,7 +230,7 @@ private void GenerateConversionMethods()
{{");
foreach (var unit in _quantity.Units)
{
var func = unit.FromBaseToUnitFunc.Replace("x", "baseUnitValue");
var func = unit.FromBaseToUnitFunc.Replace("{x}", "baseUnitValue");
Writer.WL($@"
case {_unitEnumName}.{unit.SingularName}: return {func};");
}
Expand Down
4 changes: 2 additions & 2 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ IQuantity IQuantity.ToUnit(Enum unit)
{{");
foreach (var unit in _quantity.Units)
{
var func = unit.FromUnitToBaseFunc.Replace("x", "_value");
var func = unit.FromUnitToBaseFunc.Replace("{x}", "_value");
Writer.WL($@"
case {_unitEnumName}.{unit.SingularName}: return {func};");
}
Expand Down Expand Up @@ -987,7 +987,7 @@ IQuantity IQuantity.ToUnit(Enum unit)
{{");
foreach (var unit in _quantity.Units)
{
var func = unit.FromBaseToUnitFunc.Replace("x", "baseUnitValue");
var func = unit.FromBaseToUnitFunc.Replace("{x}", "baseUnitValue");
Writer.WL($@"
case {_unitEnumName}.{unit.SingularName}: return {func};");
}
Expand Down
4 changes: 2 additions & 2 deletions CodeGen/Generators/UnitsNetWrcGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public double As({_unitEnumName} unit)
{{");
foreach (var unit in _quantity.Units)
{
var func = unit.FromUnitToBaseFunc.Replace("x", "_value");
var func = unit.FromUnitToBaseFunc.Replace("{x}", "_value");
Writer.WL($@"
case {_unitEnumName}.{unit.SingularName}: return {func};");
}
Expand All @@ -661,7 +661,7 @@ public double As({_unitEnumName} unit)
{{");
foreach (var unit in _quantity.Units)
{
var func = unit.FromBaseToUnitFunc.Replace("x", "baseUnitValue");
var func = unit.FromBaseToUnitFunc.Replace("{x}", "baseUnitValue");
Writer.WL($@"
case {_unitEnumName}.{unit.SingularName}: return {func};");
}
Expand Down
28 changes: 14 additions & 14 deletions Common/UnitDefinitions/Acceleration.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"L": "Meter",
"T": "Second"
},
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Kilo" ],
"Localization": [
{
Expand All @@ -35,8 +35,8 @@
"L": "Inch",
"T": "Second"
},
"FromUnitToBaseFunc": "x*0.0254",
"FromBaseToUnitFunc": "x/0.0254",
"FromUnitToBaseFunc": "{x}*0.0254",
"FromBaseToUnitFunc": "{x}/0.0254",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -55,8 +55,8 @@
"L": "Foot",
"T": "Second"
},
"FromUnitToBaseFunc": "x*0.304800",
"FromBaseToUnitFunc": "x/0.304800",
"FromUnitToBaseFunc": "{x}*0.304800",
"FromBaseToUnitFunc": "{x}/0.304800",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -75,8 +75,8 @@
"L": "NauticalMile",
"T": "Second"
},
"FromUnitToBaseFunc": "x*0.5144444444444",
"FromBaseToUnitFunc": "x/0.5144444444444",
"FromUnitToBaseFunc": "{x}*0.5144444444444",
"FromBaseToUnitFunc": "{x}/0.5144444444444",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -95,8 +95,8 @@
"L": "NauticalMile",
"T": "Minute"
},
"FromUnitToBaseFunc": "x*0.5144444444444/60",
"FromBaseToUnitFunc": "x/0.5144444444444*60",
"FromUnitToBaseFunc": "{x}*0.5144444444444/60",
"FromBaseToUnitFunc": "{x}/0.5144444444444*60",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -115,8 +115,8 @@
"L": "NauticalMile",
"T": "Hour"
},
"FromUnitToBaseFunc": "x*0.5144444444444/3600",
"FromBaseToUnitFunc": "x/0.5144444444444*3600",
"FromUnitToBaseFunc": "{x}*0.5144444444444/3600",
"FromBaseToUnitFunc": "{x}/0.5144444444444*3600",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -135,8 +135,8 @@
"L": "Meter",
"T": "Second"
},
"FromUnitToBaseFunc": "x*9.80665",
"FromBaseToUnitFunc": "x/9.80665",
"FromUnitToBaseFunc": "{x}*9.80665",
"FromBaseToUnitFunc": "{x}/9.80665",
"Prefixes": [ "Milli"],
"Localization": [
{
Expand Down
8 changes: 4 additions & 4 deletions Common/UnitDefinitions/AmountOfSubstance.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{
"SingularName": "Mole",
"PluralName": "Moles",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"BaseUnits": {
"N": "Mole"
},
Expand All @@ -28,8 +28,8 @@
"BaseUnits": {
"N": "PoundMole"
},
"FromUnitToBaseFunc": "x*453.59237",
"FromBaseToUnitFunc": "x/453.59237",
"FromUnitToBaseFunc": "{x}*453.59237",
"FromBaseToUnitFunc": "{x}/453.59237",
"Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Kilo" ],
"Localization": [
{
Expand Down
16 changes: 8 additions & 8 deletions Common/UnitDefinitions/AmplitudeRatio.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
{
"SingularName": "DecibelVolt",
"PluralName": "DecibelVolts",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -20,8 +20,8 @@
{
"SingularName": "DecibelMicrovolt",
"PluralName": "DecibelMicrovolts",
"FromUnitToBaseFunc": "x - 120",
"FromBaseToUnitFunc": "x + 120",
"FromUnitToBaseFunc": "{x} - 120",
"FromBaseToUnitFunc": "{x} + 120",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -32,8 +32,8 @@
{
"SingularName": "DecibelMillivolt",
"PluralName": "DecibelMillivolts",
"FromUnitToBaseFunc": "x - 60",
"FromBaseToUnitFunc": "x + 60",
"FromUnitToBaseFunc": "{x} - 60",
"FromBaseToUnitFunc": "{x} + 60",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -44,8 +44,8 @@
{
"SingularName": "DecibelUnloaded",
"PluralName": "DecibelsUnloaded",
"FromUnitToBaseFunc": "x - 2.218487499",
"FromBaseToUnitFunc": "x + 2.218487499",
"FromUnitToBaseFunc": "{x} - 2.218487499",
"FromBaseToUnitFunc": "{x} + 2.218487499",
"Localization": [
{
"Culture": "en-US",
Expand Down
32 changes: 16 additions & 16 deletions Common/UnitDefinitions/Angle.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{
"SingularName": "Radian",
"PluralName": "Radians",
"FromUnitToBaseFunc": "x*180/Math.PI",
"FromBaseToUnitFunc": "x/180*Math.PI",
"FromUnitToBaseFunc": "{x}*180/Math.PI",
"FromBaseToUnitFunc": "{x}/180*Math.PI",
"Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci" ],
"Localization": [
{
Expand All @@ -24,8 +24,8 @@
"SingularName": "Degree",
"PluralName": "Degrees",
"Prefixes": [ "Nano", "Micro", "Milli" ],
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -40,8 +40,8 @@
{
"SingularName": "Arcminute",
"PluralName": "Arcminutes",
"FromUnitToBaseFunc": "x/60",
"FromBaseToUnitFunc": "x*60",
"FromUnitToBaseFunc": "{x}/60",
"FromBaseToUnitFunc": "{x}*60",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -52,8 +52,8 @@
{
"SingularName": "Arcsecond",
"PluralName": "Arcseconds",
"FromUnitToBaseFunc": "x/3600",
"FromBaseToUnitFunc": "x*3600",
"FromUnitToBaseFunc": "{x}/3600",
"FromBaseToUnitFunc": "{x}*3600",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -64,8 +64,8 @@
{
"SingularName": "Gradian",
"PluralName": "Gradians",
"FromUnitToBaseFunc": "x*0.9",
"FromBaseToUnitFunc": "x/0.9",
"FromUnitToBaseFunc": "{x}*0.9",
"FromBaseToUnitFunc": "{x}/0.9",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -80,8 +80,8 @@
{
"SingularName": "NatoMil",
"PluralName": "NatoMils",
"FromUnitToBaseFunc": "x*9/160",
"FromBaseToUnitFunc": "x*160/9",
"FromUnitToBaseFunc": "{x}*9/160",
"FromBaseToUnitFunc": "{x}*160/9",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -92,8 +92,8 @@
{
"SingularName": "Revolution",
"PluralName": "Revolutions",
"FromUnitToBaseFunc": "x*360",
"FromBaseToUnitFunc": "x/360",
"FromUnitToBaseFunc": "{x}*360",
"FromBaseToUnitFunc": "{x}/360",
"Localization": [
{
"Culture": "en-US",
Expand All @@ -108,8 +108,8 @@
{
"SingularName": "Tilt",
"PluralName": "Tilt",
"FromUnitToBaseFunc": "Math.Asin(x)*180/Math.PI",
"FromBaseToUnitFunc": "Math.Sin(x/180*Math.PI)",
"FromUnitToBaseFunc": "Math.Asin({x})*180/Math.PI",
"FromBaseToUnitFunc": "Math.Sin({x}/180*Math.PI)",
"Localization": [
{
"Culture": "en-US",
Expand Down
4 changes: 2 additions & 2 deletions Common/UnitDefinitions/ApparentEnergy.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{
"SingularName": "VoltampereHour",
"PluralName": "VoltampereHours",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Prefixes": [ "Kilo", "Mega" ],
"Localization": [
{
Expand Down
4 changes: 2 additions & 2 deletions Common/UnitDefinitions/ApparentPower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{
"SingularName": "Voltampere",
"PluralName": "Voltamperes",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Prefixes": [ "Kilo", "Mega", "Giga" ],
"Localization": [
{
Expand Down
Loading

0 comments on commit 8d2eeb6

Please sign in to comment.