mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 14:01:14 +00:00
1dcd089d39
Promotes 8 operational levers into config keys with defaults that match the prior source literals byte-for-byte: ProcessingConfig: RegionProcessingTimeoutSeconds (300), RouteProcessingPollIntervalSeconds (5), MaxRoutePointSpacingMeters (200), LatLonTolerance (0.0001). MapConfig: TileSizePixels (256), AllowedZoomLevels ([15..19]), RetryBaseDelaySeconds (1), RetryMaxDelaySeconds (30). Sites updated: RegionService, RouteProcessingService, RoutePointGraphBuilder, RouteValidator, RouteService 4-arg ctor, RouteImageRenderer, GoogleMapsDownloaderV2, TileService. Closes LF-2 by forwarding HttpContext.RequestAborted from GetTileByLatLon into the downloader. appsettings.json gains the 8 new keys at default values. Tests: 141 / 141 unit + 5 / 5 smoke green. New ConfigDefaultsTests pins defaults to original literals; new TileService unit test asserts CT identity from caller to downloader (AZ-371 AC-3). Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
3.2 KiB
C#
90 lines
3.2 KiB
C#
using Microsoft.Extensions.Options;
|
|
using SatelliteProvider.Common.Configs;
|
|
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Common.Utils;
|
|
|
|
namespace SatelliteProvider.Services.RouteManagement;
|
|
|
|
public class RoutePointGraphBuilder
|
|
{
|
|
private readonly double _maxPointSpacingMeters;
|
|
|
|
public RoutePointGraphBuilder(IOptions<ProcessingConfig> processingConfig)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(processingConfig);
|
|
_maxPointSpacingMeters = processingConfig.Value.MaxRoutePointSpacingMeters;
|
|
}
|
|
|
|
public RoutePointGraph Build(IReadOnlyList<RoutePoint> userPoints)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(userPoints);
|
|
if (userPoints.Count < 2)
|
|
{
|
|
throw new ArgumentException("Route must have at least 2 points", nameof(userPoints));
|
|
}
|
|
|
|
var allPoints = new List<RoutePointDto>();
|
|
var totalDistance = 0.0;
|
|
var sequenceNumber = 0;
|
|
|
|
for (int segmentIndex = 0; segmentIndex < userPoints.Count; segmentIndex++)
|
|
{
|
|
var current = userPoints[segmentIndex];
|
|
var isStart = segmentIndex == 0;
|
|
var isEnd = segmentIndex == userPoints.Count - 1;
|
|
|
|
var currentGeo = new GeoPoint(current.Latitude, current.Longitude);
|
|
|
|
double? distanceFromPrevious = null;
|
|
if (allPoints.Count > 0)
|
|
{
|
|
var prev = allPoints[^1];
|
|
var prevGeo = new GeoPoint(prev.Latitude, prev.Longitude);
|
|
distanceFromPrevious = GeoUtils.CalculateDistance(prevGeo, currentGeo);
|
|
totalDistance += distanceFromPrevious.Value;
|
|
}
|
|
|
|
allPoints.Add(new RoutePointDto
|
|
{
|
|
Latitude = current.Latitude,
|
|
Longitude = current.Longitude,
|
|
PointType = isStart ? "start" : (isEnd ? "end" : "action"),
|
|
SequenceNumber = sequenceNumber++,
|
|
SegmentIndex = segmentIndex,
|
|
DistanceFromPrevious = distanceFromPrevious,
|
|
});
|
|
|
|
if (isEnd)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var next = userPoints[segmentIndex + 1];
|
|
var nextGeo = new GeoPoint(next.Latitude, next.Longitude);
|
|
var intermediates = GeoUtils.CalculateIntermediatePoints(currentGeo, nextGeo, _maxPointSpacingMeters);
|
|
|
|
foreach (var intermediateGeo in intermediates)
|
|
{
|
|
var prev = allPoints[^1];
|
|
var prevGeo = new GeoPoint(prev.Latitude, prev.Longitude);
|
|
var distFromPrev = GeoUtils.CalculateDistance(prevGeo, intermediateGeo);
|
|
totalDistance += distFromPrev;
|
|
|
|
allPoints.Add(new RoutePointDto
|
|
{
|
|
Latitude = intermediateGeo.Lat,
|
|
Longitude = intermediateGeo.Lon,
|
|
PointType = "intermediate",
|
|
SequenceNumber = sequenceNumber++,
|
|
SegmentIndex = segmentIndex,
|
|
DistanceFromPrevious = distFromPrev,
|
|
});
|
|
}
|
|
}
|
|
|
|
return new RoutePointGraph(allPoints, totalDistance);
|
|
}
|
|
}
|
|
|
|
public record RoutePointGraph(IReadOnlyList<RoutePointDto> Points, double TotalDistanceMeters);
|