Skip to content

Commit

Permalink
fix: Update Realtime.Shape's pattern-matching so that it can accept…
Browse files Browse the repository at this point in the history
… `Util.Location.From`'s (#2694)

Co-authored-by: Kayla Firestack <kfirestack@mbta.com>
  • Loading branch information
joshlarson and firestack authored Jul 16, 2024
1 parent 8864272 commit 8928579
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions lib/realtime/shape.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,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

0 comments on commit 8928579

Please sign in to comment.