Class CalculationHelper
Static class providing helper methods for various calculations.
Namespace: CapyKit.Helpers
Assembly: CapyKit.dll
Syntax
public static class CalculationHelper
Fields
EARTH_RADIUS_KILOMETERS
The earth's radius in kilometers.
Declaration
public const int EARTH_RADIUS_KILOMETERS = 6371
Field Value
| Type | Description |
|---|---|
| int |
MILES_PER_KILOMETER
Ratio of miles per kilometer .
Declaration
public const double MILES_PER_KILOMETER = 0.621371
Field Value
| Type | Description |
|---|---|
| double |
Methods
CalculateHash(string)
Calculates the hash of a given string using an MD5 value as the first 32 bits.
Declaration
public static int CalculateHash(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The string to be hashed. |
Returns
| Type | Description |
|---|---|
| int | 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.
CalculateHexHash(string)
Calculates the hexadecimal hash.
Declaration
public static string CalculateHexHash(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The string to be hashed. |
Returns
| Type | Description |
|---|---|
| string | The calculated 16 character hexadecimal hash. |
DegreesToRadians(double)
Convers degrees to radians.
Declaration
public static double DegreesToRadians(double degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| double | degrees | The degree value. |
Returns
| Type | Description |
|---|---|
| double | The value as radians. |
GetDistance(decimal, decimal, decimal, decimal, MeasurementSystem)
Gets the distance between two points on earth using the haversine formula.
Declaration
public static decimal GetDistance(decimal latitudeOrigin, decimal longitudeOrigin, decimal latitudeDestination, decimal longitudeDestination, MeasurementSystem measurementSystem = MeasurementSystem.Imperial)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | latitudeOrigin | The latitude origin. |
| decimal | longitudeOrigin | The longitude origin. |
| decimal | latitudeDestination | The latitude destination. |
| decimal | longitudeDestination | The longitude destination. |
| MeasurementSystem | measurementSystem | (Optional) The measurement system. |
Returns
| Type | Description |
|---|---|
| decimal | The distance. |
Remarks
Uses the haversine formula to calculate the "as-the-crow-flies" distance between two points on earth.
See Also
GetDistance(double, double, double, double, MeasurementSystem)
Gets the distance between two points on earth using the haversine formula.
Declaration
public static double GetDistance(double latitudeOrigin, double longitudeOrigin, double latitudeDestination, double longitudeDestination, MeasurementSystem measurementSystem = MeasurementSystem.Imperial)
Parameters
| Type | Name | Description |
|---|---|---|
| double | latitudeOrigin | The latitude of the origin. |
| double | longitudeOrigin | The longitude of the origin. |
| double | latitudeDestination | The latitude destination. |
| double | longitudeDestination | The longitude destination. |
| MeasurementSystem | measurementSystem | (Optional) The measurement system. |
Returns
| Type | Description |
|---|---|
| double | The distance. |
Remarks
Uses the haversine formula to calculate the "as-the-crow-flies" distance between two points on earth.
KilometersToMiles(double)
Converts kilometers to miles.
Declaration
public static double KilometersToMiles(double kilometers)
Parameters
| Type | Name | Description |
|---|---|---|
| double | kilometers | The value in kilometers. |
Returns
| Type | Description |
|---|---|
| double | The value in miles. |
MilesToKilometers(double)
Converts miles to kilometers.
Declaration
public static double MilesToKilometers(double miles)
Parameters
| Type | Name | Description |
|---|---|---|
| double | miles | The value in miles. |
Returns
| Type | Description |
|---|---|
| double | The value in kilometers. |
RadiansToDegrees(double)
Converts radians to degrees.
Declaration
public static double RadiansToDegrees(double radians)
Parameters
| Type | Name | Description |
|---|---|---|
| double | radians | The radian value. |
Returns
| Type | Description |
|---|---|
| double | The value as degrees. |