Geo.Turf.Math (geo_turf v0.6.0)

Copy Markdown View Source

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.

Types

area_unit()

@type area_unit() ::
  :acres
  | :centimeters
  | :centimetres
  | :feet
  | :inches
  | :kilometers
  | :kilometres
  | :meters
  | :metres
  | :miles
  | :millimeters
  | :millimetres
  | :yards

Unit accepted by area conversions.

imperial_length()

@type imperial_length() :: :miles | :nauticalmiles | :inches | :yards | :feet

Imperial and nautical length units.

length_unit()

@type length_unit() ::
  si_length_uk() | si_length_us() | imperial_length() | :degrees | :radians

Unit accepted by geodesic length and distance calculations.

si_length_uk()

@type si_length_uk() :: :meters | :kilometers | :centimeters | :millimeters

British-spelling SI length units.

si_length_us()

@type si_length_us() :: :metres | :kilometres | :centimetres | :millimetres

Alternative-spelling SI length units.

Functions

approx(point, precision \\ 4)

@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}}

bearing_to_azimuth(bearing)

@spec bearing_to_azimuth(number()) :: number()

convert_area(area, from \\ :meters, to \\ :kilometers)

@spec convert_area(number(), area_unit(), area_unit()) :: number()

convert_length(length, from \\ :kilometers, to \\ :kilometers)

@spec convert_length(number(), length_unit(), length_unit()) :: number()

degrees_to_radians(degrees)

@spec degrees_to_radians(number()) :: float()

length_to_degrees(length, units \\ :kilometers)

@spec length_to_degrees(number(), length_unit()) :: float()

length_to_radians(length, unit \\ :kilometers)

@spec length_to_radians(number(), length_unit()) :: float()

mod(number, modulus)

@spec mod(number(), number()) :: number()

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

radians_to_degrees(radians)

@spec radians_to_degrees(number()) :: float()

radians_to_length(radians, unit \\ :kilometers)

@spec radians_to_length(number(), length_unit()) :: number()

rounded(number, precision \\ 0)

Round number to precision

Example

iex> Geo.Turf.Math.rounded(120.4321)
120

iex> Geo.Turf.Math.rounded(120.4321, 3)
120.432