269 lines
8.1 KiB
Markdown
269 lines
8.1 KiB
Markdown
# <a id="CapyKit_Helpers_CalculationHelper"></a> Class CalculationHelper
|
|
|
|
Namespace: [CapyKit.Helpers](CapyKit.Helpers.md)
|
|
Assembly: CapyKit.dll
|
|
|
|
Static class providing helper methods for various calculations.
|
|
|
|
```csharp
|
|
public static class CalculationHelper
|
|
```
|
|
|
|
#### Inheritance
|
|
|
|
[object](https://learn.microsoft.com/dotnet/api/system.object) ←
|
|
[CalculationHelper](CapyKit.Helpers.CalculationHelper.md)
|
|
|
|
#### Inherited Members
|
|
|
|
[object.Equals\(object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\)),
|
|
[object.Equals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\-system\-object\)),
|
|
[object.GetHashCode\(\)](https://learn.microsoft.com/dotnet/api/system.object.gethashcode),
|
|
[object.GetType\(\)](https://learn.microsoft.com/dotnet/api/system.object.gettype),
|
|
[object.MemberwiseClone\(\)](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone),
|
|
[object.ReferenceEquals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals),
|
|
[object.ToString\(\)](https://learn.microsoft.com/dotnet/api/system.object.tostring)
|
|
|
|
#### Extension Methods
|
|
|
|
[ObjectExtensions.UpdateProperties\(object, object\)](CapyKit.Extensions.ObjectExtensions.md\#CapyKit\_Extensions\_ObjectExtensions\_UpdateProperties\_System\_Object\_System\_Object\_)
|
|
|
|
## Fields
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_EARTH_RADIUS_KILOMETERS"></a> EARTH\_RADIUS\_KILOMETERS
|
|
|
|
The earth's radius in kilometers.
|
|
|
|
```csharp
|
|
public const int EARTH_RADIUS_KILOMETERS = 6371
|
|
```
|
|
|
|
#### Field Value
|
|
|
|
[int](https://learn.microsoft.com/dotnet/api/system.int32)
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_MILES_PER_KILOMETER"></a> MILES\_PER\_KILOMETER
|
|
|
|
Ratio of miles per kilometer .
|
|
|
|
```csharp
|
|
public const double MILES_PER_KILOMETER = 0.621371
|
|
```
|
|
|
|
#### Field Value
|
|
|
|
[double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
## Methods
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_CalculateHash_System_String_"></a> CalculateHash\(string\)
|
|
|
|
Calculates the hash of a given string using an <xref href="System.Security.Cryptography.MD5" data-throw-if-not-resolved="false"></xref> value as the first 32 bits.
|
|
|
|
```csharp
|
|
public static int CalculateHash(string str)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`str` [string](https://learn.microsoft.com/dotnet/api/system.string)
|
|
|
|
The string to be hashed.
|
|
|
|
#### Returns
|
|
|
|
[int](https://learn.microsoft.com/dotnet/api/system.int32)
|
|
|
|
The calculated hash.
|
|
|
|
#### Remarks
|
|
|
|
This method is used for a quick and consistent hash function. It should not be considered
|
|
cryptographically sound or used in security contexts.
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_CalculateHexHash_System_String_"></a> CalculateHexHash\(string\)
|
|
|
|
Calculates the hexadecimal hash.
|
|
|
|
```csharp
|
|
public static string CalculateHexHash(string str)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`str` [string](https://learn.microsoft.com/dotnet/api/system.string)
|
|
|
|
The string to be hashed.
|
|
|
|
#### Returns
|
|
|
|
[string](https://learn.microsoft.com/dotnet/api/system.string)
|
|
|
|
The calculated 16 character hexadecimal hash.
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_DegreesToRadians_System_Double_"></a> DegreesToRadians\(double\)
|
|
|
|
Convers degrees to radians.
|
|
|
|
```csharp
|
|
public static double DegreesToRadians(double degrees)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`degrees` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The degree value.
|
|
|
|
#### Returns
|
|
|
|
[double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The value as radians.
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_GetDistance_System_Decimal_System_Decimal_System_Decimal_System_Decimal_CapyKit_Enumerations_MeasurementSystem_"></a> GetDistance\(decimal, decimal, decimal, decimal, MeasurementSystem\)
|
|
|
|
Gets the distance between two points on earth using the <code>haversine</code> formula.
|
|
|
|
```csharp
|
|
public static decimal GetDistance(decimal latitudeOrigin, decimal longitudeOrigin, decimal latitudeDestination, decimal longitudeDestination, MeasurementSystem measurementSystem = MeasurementSystem.Imperial)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`latitudeOrigin` [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)
|
|
|
|
The latitude origin.
|
|
|
|
`longitudeOrigin` [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)
|
|
|
|
The longitude origin.
|
|
|
|
`latitudeDestination` [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)
|
|
|
|
The latitude destination.
|
|
|
|
`longitudeDestination` [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)
|
|
|
|
The longitude destination.
|
|
|
|
`measurementSystem` [MeasurementSystem](CapyKit.Enumerations.MeasurementSystem.md)
|
|
|
|
(Optional) The measurement system.
|
|
|
|
#### Returns
|
|
|
|
[decimal](https://learn.microsoft.com/dotnet/api/system.decimal)
|
|
|
|
The distance.
|
|
|
|
#### Remarks
|
|
|
|
Uses the <a href="https://www.movable-type.co.uk/scripts/latlong.html">haversine</a> formula
|
|
to calculate the "as-the-crow-flies" distance between two points on earth.
|
|
|
|
#### See Also
|
|
|
|
[CalculationHelper](CapyKit.Helpers.CalculationHelper.md).[GetDistance](CapyKit.Helpers.CalculationHelper.md\#CapyKit\_Helpers\_CalculationHelper\_GetDistance\_System\_Double\_System\_Double\_System\_Double\_System\_Double\_CapyKit\_Enumerations\_MeasurementSystem\_)\([double](https://learn.microsoft.com/dotnet/api/system.double), [double](https://learn.microsoft.com/dotnet/api/system.double), [double](https://learn.microsoft.com/dotnet/api/system.double), [double](https://learn.microsoft.com/dotnet/api/system.double), [MeasurementSystem](CapyKit.Enumerations.MeasurementSystem.md)\)
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_GetDistance_System_Double_System_Double_System_Double_System_Double_CapyKit_Enumerations_MeasurementSystem_"></a> GetDistance\(double, double, double, double, MeasurementSystem\)
|
|
|
|
Gets the distance between two points on earth using the <code>haversine</code> formula.
|
|
|
|
```csharp
|
|
public static double GetDistance(double latitudeOrigin, double longitudeOrigin, double latitudeDestination, double longitudeDestination, MeasurementSystem measurementSystem = MeasurementSystem.Imperial)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`latitudeOrigin` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The latitude of the origin.
|
|
|
|
`longitudeOrigin` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The longitude of the origin.
|
|
|
|
`latitudeDestination` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The latitude destination.
|
|
|
|
`longitudeDestination` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The longitude destination.
|
|
|
|
`measurementSystem` [MeasurementSystem](CapyKit.Enumerations.MeasurementSystem.md)
|
|
|
|
(Optional) The measurement system.
|
|
|
|
#### Returns
|
|
|
|
[double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The distance.
|
|
|
|
#### Remarks
|
|
|
|
Uses the <a href="https://www.movable-type.co.uk/scripts/latlong.html">haversine</a> formula
|
|
to calculate the "as-the-crow-flies" distance between two points on earth.
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_KilometersToMiles_System_Double_"></a> KilometersToMiles\(double\)
|
|
|
|
Converts kilometers to miles.
|
|
|
|
```csharp
|
|
public static double KilometersToMiles(double kilometers)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`kilometers` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The value in kilometers.
|
|
|
|
#### Returns
|
|
|
|
[double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The value in miles.
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_MilesToKilometers_System_Double_"></a> MilesToKilometers\(double\)
|
|
|
|
Converts miles to kilometers.
|
|
|
|
```csharp
|
|
public static double MilesToKilometers(double miles)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`miles` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The value in miles.
|
|
|
|
#### Returns
|
|
|
|
[double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The value in kilometers.
|
|
|
|
### <a id="CapyKit_Helpers_CalculationHelper_RadiansToDegrees_System_Double_"></a> RadiansToDegrees\(double\)
|
|
|
|
Converts radians to degrees.
|
|
|
|
```csharp
|
|
public static double RadiansToDegrees(double radians)
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
`radians` [double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The radian value.
|
|
|
|
#### Returns
|
|
|
|
[double](https://learn.microsoft.com/dotnet/api/system.double)
|
|
|
|
The value as degrees.
|
|
|