All sorts of mathematical functions
Summary
Types
Unit accepted by area conversions.
Imperial and nautical length units.
Unit accepted by geodesic length and distance calculations.
British-spelling SI length units.
Alternative-spelling SI length units.
Functions
Rounds the coordinates of a Point to the given precision. Useful for approximate comparisons in tests. The returned Point preserves the source Point's SRID and properties.
Calculates the modulo of a number (integer or float).
Round number to precision
Types
@type area_unit() ::
:acres
| :centimeters
| :centimetres
| :feet
| :inches
| :kilometers
| :kilometres
| :meters
| :metres
| :miles
| :millimeters
| :millimetres
| :yards
Unit accepted by area conversions.
@type imperial_length() :: :miles | :nauticalmiles | :inches | :yards | :feet
Imperial and nautical length units.
@type length_unit() :: si_length_uk() | si_length_us() | imperial_length() | :degrees | :radians
Unit accepted by geodesic length and distance calculations.
@type si_length_uk() :: :meters | :kilometers | :centimeters | :millimeters
British-spelling SI length units.
@type si_length_us() :: :metres | :kilometres | :centimetres | :millimetres
Alternative-spelling SI length units.
Functions
@spec approx(Geo.Point.t(), non_neg_integer()) :: Geo.Point.t()
Rounds the coordinates of a Point to the given precision. Useful for approximate comparisons in tests. The returned Point preserves the source Point's SRID and properties.
Examples
iex> Geo.Turf.Math.approx(%Geo.Point{coordinates: {1.23456, 7.89012}}, 3)
%Geo.Point{coordinates: {1.235, 7.89}}
@spec convert_length(number(), length_unit(), length_unit()) :: number()
@spec length_to_degrees(number(), length_unit()) :: float()
@spec length_to_radians(number(), length_unit()) :: float()
Calculates the modulo of a number (integer or float).
Note that this function uses floored division whereas the builtin rem
function uses truncated division. See Decimal.rem/2 if you want a
truncated division function for Decimals that will return the same value as
the BIF rem/2 but in Decimal form.
See Wikipedia for an explanation of the difference.
Taken from cldr_utils with thanks and gratitude.
Examples
iex> Geo.Turf.Math.mod(1234.0, 5)
4.0
@spec radians_to_length(number(), length_unit()) :: number()
Round number to precision
Example
iex> Geo.Turf.Math.rounded(120.4321)
120
iex> Geo.Turf.Math.rounded(120.4321, 3)
120.432