mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 17:01:14 +00:00
f7ad7aa5ab
Extract RouteValidator (aggregating validator), RoutePointGraphBuilder (point interpolation + sequence numbering), GeofenceGridCalculator (NW/SE region centers), and RouteResponseMapper (entity -> DTO; also used by GetRouteAsync, eliminating duplicate DTO assembly). CreateRouteAsync shrinks 184 -> 52 LOC of orchestration. RouteService.cs shrinks 295 -> 138 LOC overall. Validation aggregates all failures into a single ArgumentException (AC-2); single-violation messages preserved verbatim so existing RouteServiceTests pass unchanged. 28 new unit tests for the four helpers (112/112 unit tests, smoke green). Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Common.Utils;
|
|
|
|
namespace SatelliteProvider.Services.RouteManagement;
|
|
|
|
public class GeofenceGridCalculator
|
|
{
|
|
public IReadOnlyList<GeoPoint> GenerateRegions(GeoPoint northWest, GeoPoint southEast, double regionSizeMeters)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(northWest);
|
|
ArgumentNullException.ThrowIfNull(southEast);
|
|
if (regionSizeMeters <= 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(regionSizeMeters), "Region size must be positive");
|
|
}
|
|
|
|
var midLon = (northWest.Lon + southEast.Lon) / 2;
|
|
var midLat = (northWest.Lat + southEast.Lat) / 2;
|
|
|
|
var heightMeters = GeoUtils.CalculateDistance(
|
|
new GeoPoint(northWest.Lat, midLon),
|
|
new GeoPoint(southEast.Lat, midLon));
|
|
var widthMeters = GeoUtils.CalculateDistance(
|
|
new GeoPoint(midLat, northWest.Lon),
|
|
new GeoPoint(midLat, southEast.Lon));
|
|
|
|
var numLatSteps = Math.Max(1, (int)Math.Ceiling(heightMeters / regionSizeMeters));
|
|
var numLonSteps = Math.Max(1, (int)Math.Ceiling(widthMeters / regionSizeMeters));
|
|
|
|
var latStep = (northWest.Lat - southEast.Lat) / numLatSteps;
|
|
var lonStep = (southEast.Lon - northWest.Lon) / numLonSteps;
|
|
|
|
var regions = new List<GeoPoint>(numLatSteps * numLonSteps);
|
|
for (int latIdx = 0; latIdx < numLatSteps; latIdx++)
|
|
{
|
|
for (int lonIdx = 0; lonIdx < numLonSteps; lonIdx++)
|
|
{
|
|
var lat = northWest.Lat - (latIdx + 0.5) * latStep;
|
|
var lon = northWest.Lon + (lonIdx + 0.5) * lonStep;
|
|
regions.Add(new GeoPoint(lat, lon));
|
|
}
|
|
}
|
|
|
|
return regions;
|
|
}
|
|
}
|