Skip to content

Commit 4ad9728

Browse files
committed
Improve docs and add some types
1 parent b94326b commit 4ad9728

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ Landmark is designed to work with structs provided by the [Geo][geo] library
66

77
## Installation
88

9-
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
10-
by adding `landmark` to your list of dependencies in `mix.exs`:
9+
Add `landmark` to your list of dependencies in `mix.exs`:
1110

1211
```elixir
1312
def deps do
1413
[
15-
{:landmark, "~> 0.1.0"}
14+
{:landmark, "~> 0.3.0"}
1615
]
1716
end
1817
```

lib/landmark.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
defmodule Landmark do
2+
@moduledoc """
3+
Landmark is a geospatial analysis library.
4+
"""
25
end

lib/landmark/helpers.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
defmodule Landmark.Helpers do
22
@earth_radius 6_371_008.8
33

4+
@type length_unit() :: :radians | :meters | :metres | :kilometers | :kilometres
5+
46
@doc """
57
Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
8+
9+
## Examples
10+
11+
iex> Landmark.Helpers.radians_to_length(1, :kilometers)
12+
6371.0088
613
"""
14+
@spec radians_to_length(number(), length_unit()) :: number()
715
def radians_to_length(radians, unit)
816
def radians_to_length(radians, :radians), do: radians
917
def radians_to_length(radians, :meters), do: radians * @earth_radius
10-
def radians_to_length(radians, :metres), do: radians * @earth_radius
18+
def radians_to_length(radians, :metres), do: radians_to_length(radians, :meters)
1119
def radians_to_length(radians, :kilometers), do: radians * @earth_radius / 1000
20+
def radians_to_length(radians, :kilometres), do: radians_to_length(radians, :kilometers)
1221
end

lib/landmark/measurement.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ defmodule Landmark.Measurement do
7777
end
7878

7979
@doc """
80-
Computes the bounding box for an object
80+
Computes the bounding box for an object.
81+
82+
## Examples
83+
iex> Landmark.Measurement.bbox(%Geo.LineString{coordinates: [{1, 2}, {4, 6}]})
84+
{1, 2, 4, 6}
85+
86+
iex> Landmark.Measurement.bbox(%Geo.LineString{coordinates: []})
87+
nil
8188
"""
89+
@spec bbox(Geo.geometry() | list({number(), number()})) ::
90+
{number(), number(), number(), number()} | nil
8291
def bbox(object)
8392

8493
def bbox(%Geo.Point{coordinates: coordinates}), do: bbox([coordinates])

mix.exs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ defmodule Landmark.MixProject do
44
def project do
55
[
66
app: :landmark,
7-
version: "0.3.0",
7+
version: "0.4.0",
88
elixir: "~> 1.14",
99
start_permanent: Mix.env() == :prod,
1010
deps: deps(),
1111
description: description(),
12-
package: package()
12+
package: package(),
13+
name: "Landmark",
14+
source_url: "https://github.com/harrygr/landmark",
15+
docs: &docs/0
1316
]
1417
end
1518

@@ -43,4 +46,10 @@ defmodule Landmark.MixProject do
4346
links: %{"GitHub" => "https://github.com/harrygr/landmark"}
4447
]
4548
end
49+
50+
defp docs do
51+
[
52+
extras: ["README.md"]
53+
]
54+
end
4655
end

test/helpers_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule HelpersTest do
2+
use ExUnit.Case
3+
4+
doctest Landmark.Helpers
5+
end

0 commit comments

Comments
 (0)