Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Realtime.Shape's pattern-matching so that it can accept Util.Location.From's #2694

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/realtime/shape.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ defmodule Realtime.Shape do
encoded_polyline:
(before_detour ++ detour_coordinates ++ after_detour)
|> Enum.map(fn
# The coordinates that come from the route segments are
# formatted as `Util.Location`'s.
%Location{latitude: latitude, longitude: longitude} ->
# The coordinates that come from the detour shape, from
# `OpenRouteServiceAPI`, are formatted as "lat"/"lon"
# `Map`'s,
%{"lat" => latitude, "lon" => longitude} ->
{longitude, latitude}

# ...but the coordinates that come from the detour shape, from
# `OpenRouteServiceAPI`, are formatted as "lat"/"lon" `Map`'s,
# so we need to handle both cases.
%{"lat" => latitude, "lon" => longitude} ->
# ...but the coordinates that come from the route segments
# are formatted as `Util.Location.From`'s, so we need to
# handle both cases.
point ->
%Location{latitude: latitude, longitude: longitude} =
Util.Location.as_location!(point)

{longitude, latitude}
end)
|> Polyline.encode()
Expand Down
13 changes: 7 additions & 6 deletions test/realtime/shape_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ defmodule Realtime.ShapeTest do
alias Realtime.Shape
alias Skate.Detours.RouteSegments
use ExUnit.Case
import Skate.Factory

doctest Shape

test "translates route segments and detour shape into encoded polyline shape" do
route_segments = %RouteSegments.Result{
before_detour: [
Location.new(42.425, -70.99),
Location.new(42.431, -70.99)
build(:gtfs_stop, %{latitude: 42.425, longitude: -70.99}),
build(:gtfs_stop, %{latitude: 42.431, longitude: -70.99})
],
detour: [
Location.new(42.431, -70.99),
Location.new(42.439, -70.99)
build(:gtfs_stop, %{latitude: 42.431, longitude: -70.99}),
build(:gtfs_stop, %{latitude: 42.439, longitude: -70.99})
],
after_detour: [
Location.new(42.439, -70.99),
Location.new(42.445, -70.99)
build(:gtfs_stop, %{latitude: 42.439, longitude: -70.99}),
build(:gtfs_stop, %{latitude: 42.445, longitude: -70.99})
]
}

Expand Down
Loading