-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add readme to nuget, add solid angle units
- Loading branch information
1 parent
ef14c70
commit b945cbd
Showing
8 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Gehtsoft.Measurements | ||
{ | ||
/// <summary> | ||
/// Solid angle units | ||
/// </summary> | ||
public enum SolidAngularUnit | ||
{ | ||
/// <summary> | ||
/// Steradian/square radian (4π per full sphere) | ||
/// </summary> | ||
[Unit("sr", 6)] | ||
[Conversion(ConversionOperation.Base)] | ||
Steradian = 0, | ||
|
||
/// <summary> | ||
/// Square degree | ||
/// </summary> | ||
[Unit("deg2", "sqdeg", 6)] | ||
[Conversion(ConversionOperation.Multiply, 3.0461741978670859934674354937889e-4)] | ||
SquareDegree = 1, | ||
|
||
/// <summary> | ||
/// Square degree | ||
/// </summary> | ||
[Unit("moa2", "sqmoa", 6)] | ||
[Conversion(ConversionOperation.Multiply, 8.4615949940752388707428763716359e-8)] | ||
SquareMinute = 2, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
cd .. | ||
nuget restore Gehtsoft.Measurements.sln | ||
msbuild Gehtsoft.Measurements.sln -p:Configuration="Release" | ||
cd nuget | ||
msbuild nuget.proj -t:Prepare | ||
msbuild nuget.proj -t:NuSpec,NuPack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,72 @@ | ||
# About | ||
|
||
This package is a C# library to manipulate with various measurements (e.g. distances, weight, angles, temperatures, and so on) expressed in various units (e.g. distances in inches, yards, meters) | ||
Currently, distance/length, velocity, weight, angular measurements, and energy units are supported. | ||
The C# library to manipulate and convert with various measurements/units (e.g. distances, weight, angles, temperatures, and so on) | ||
expressed in various units (e.g. distances in inches, yards, meters). | ||
|
||
The library may be useful for calculations, for example, in math, | ||
physic or GIS that does not depend from the system of units used (e.g. SI/Metric or Imperial) | ||
or to create a unit convertor application. | ||
|
||
Currently, distance/length, velocity, weight, angular measurements, and | ||
energy units are supported. | ||
|
||
The library is shared under LGPL license. | ||
|
||
# Using Library | ||
## Using Library | ||
|
||
The core class of the library is the generic structure `Measurement`. The structure accepts an enumeration as a parameter and this enumeration defines the measurement unit to be used: | ||
The core class of the library is the generic structure `Measurement`. | ||
The structure accepts an enumeration as a parameter and this enumeration | ||
defines the measurement unit to be used: | ||
|
||
```cs | ||
Measurement<DistanceUnit> v = new Measurement<DistanceUnit>(10, DistanceUnit.Feet); | ||
```csharp | ||
var v = new Measurement<DistanceUnit>(10, DistanceUnit.Feet); | ||
``` | ||
|
||
You can then manipulate this value using C# operator, format them or convert it into another unit: | ||
You can then manipulate this value using C# operator, format them or | ||
convert it into another unit: | ||
|
||
```cs | ||
```csharp | ||
var v1 = v * 2; | ||
string v = v.ToString("N3"); | ||
var v2 = v1.To(DistanceUnit.Meter); | ||
``` | ||
|
||
Read more on https://docs.gehtsoftusa.com/Gehtsoft.Measurements/index.html#main.html | ||
or | ||
|
||
```csharp | ||
var x = (10.As(DistanceUnit.Yard) + 36.As(DistanceUnit.Inch)).To(DistanceUnit.Meter); | ||
``` | ||
|
||
The class fully supports serialization using `System.Text.Json` | ||
and `Binaron.Serializer` (see https://github.com/zachsaw/Binaron.Serializer). | ||
`XmlSerializer` cannot be implemented for a readonly structures without | ||
introducing of non-safe code. Please refer to tests for an example | ||
how to implement an XML serialization | ||
(https://github.com/gehtsoft-usa/Gehtsoft.Measurements/blob/76fc639a657186dc91615839ca9ded4c14af7bc2/Gehtsoft.Measurements.Test/CoreClassesTest.cs#L181). | ||
|
||
Read more on http://docs.gehtsoftusa.com/Gehtsoft.Measurements/web-content.html#index.html | ||
|
||
## Defining your own units | ||
|
||
You can define your own measurment units by | ||
creating a enumeration and mark it using `Unit` and `Conversion` | ||
attributes. The first attribute defines the unit name and the | ||
default accuracy of the values. The second attribute defines the | ||
rules of the conversion. One unit must always be a "base" unit, and | ||
conversion rules for other units defines how to convert the | ||
specified unit into a base unit. | ||
|
||
```csharp | ||
enum MyWeightUnit | ||
{ | ||
//1 gram | ||
[Unit("g", 3)] | ||
[Conversion(ConversionOperation.Base)] | ||
Gram, | ||
|
||
//1 kilogram (1 kilogram = 1000 gram) | ||
[Unit("kg", 3)] | ||
[Conversion(ConversionOperation.Multiply, 1000)] | ||
Kilogram, | ||
} | ||
``` |