-
Notifications
You must be signed in to change notification settings - Fork 34
Closed
Description
File: internal/restapi/shapes_handler.go
Description:
I found a logic bug that causes visual artifacts (lines "shooting off" the map) for routes that loop back on themselves, along with a performance inefficiency.
The Issue:
- Broken Rendering: The current implementation splits a shape into multiple segments if it detects a repeated edge (e.g., a round trip). It then concatenates the encoded polyline strings. Since polyline encoding relies on delta offsets from the previous point, concatenating separate strings resets this offset. The decoder interprets the start of the second segment (an absolute coordinate) as a delta, causing massive coordinate jumps.
- Performance: The loop appends points to
currentLineone by one without pre-allocation, causing unnecessary memory re-allocations for large shapes.
Proposed Solution:
Standard GTFS shapes are defined as a single continuous sequence. We should remove the edge-splitting logic and encode the entire shape in one pass. This fixes the rendering bug and allows us to pre-allocate memory.
Suggested Fix:
Refactor the loop to pre-allocate the slice and remove the edges map check:
// Optimization: Pre-allocate slice to avoid resizing
lineCoords := make([][]float64, 0, len(shapes))
for _, point := range shapes {
lineCoords = append(lineCoords, []float64{point.Lat, point.Lon})
}
// Encode as a single continuous polyline to ensure valid delta offsets
encodedPoints := string(polyline.EncodeCoords(lineCoords))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels