From 56d2a8046311dc55e14dc1718c895ad19ad7a38a Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Mon, 17 Jun 2024 16:45:28 -0400 Subject: [PATCH] refactor: Have `get_index_by_min_dist` just return the index (#2664) --- lib/skate/detours/missed_stops.ex | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/skate/detours/missed_stops.ex b/lib/skate/detours/missed_stops.ex index 2572f0b4c..354ae309f 100644 --- a/lib/skate/detours/missed_stops.ex +++ b/lib/skate/detours/missed_stops.ex @@ -72,12 +72,11 @@ defmodule Skate.Detours.MissedStops do connection_end_segment: Skate.Detours.ShapeSegment.t() | nil } defp missed_segments({connection_start, connection_end}, segmented_shape) do - %{index: start_index} = get_index_by_min_dist(segmented_shape, connection_start) + start_index = get_index_by_min_dist(segmented_shape, connection_start) {first_segments, remaining_segments} = Enum.split(segmented_shape, start_index) - %{index: end_count} = - get_index_by_min_dist(remaining_segments, connection_end) + end_count = get_index_by_min_dist(remaining_segments, connection_end) {missed_stop_segments, end_segments} = Enum.split(remaining_segments, end_count) @@ -149,18 +148,14 @@ defmodule Skate.Detours.MissedStops do @spec get_index_by_min_dist( shape_segments :: [Skate.Detours.ShapeSegment.t()], reference :: Util.Location.From.t() - ) :: - %{ - segment: Skate.Detours.ShapeSegment.t(), - closest: Util.Location.From.t(), - index: non_neg_integer() - } + ) :: non_neg_integer() defp get_index_by_min_dist(shape_segments, reference) do shape_segments |> Enum.with_index(fn %Skate.Detours.ShapeSegment{points: points} = segment, idx -> %{segment: segment, closest: closest_point(points, reference), index: idx} end) |> Enum.min_by(fn %{closest: %{dist: dist}} -> dist end) + |> Map.fetch!(:index) end @type point_dist_index :: %{