| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Itinero.Routing.Isochrones; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// How finely to resolve an isochrone, and how far past it to search. |
| | | 7 | | /// </summary> |
| | | 8 | | public class IsochroneSettings |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Grid resolution in metres, or null to scale it to the area reached. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <remarks> |
| | | 14 | | /// A fixed size is too coarse for a short walk and too fine for an hour's drive. Coarsened |
| | | 15 | | /// further if <see cref="MaxCells"/> would be exceeded. |
| | | 16 | | /// </remarks> |
| | 48 | 17 | | public double? CellSizeMeters { get; set; } |
| | | 18 | | |
| | | 19 | | /// <summary>Cells across the reached area when <see cref="CellSizeMeters"/> is null.</summary> |
| | 37 | 20 | | public int TargetCellsAcross { get; set; } = 400; |
| | | 21 | | |
| | | 22 | | /// <summary>Floor on the scaled cell size, in metres.</summary> |
| | 37 | 23 | | public double MinCellSizeMeters { get; set; } = 20.0; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Ceiling on grid cells, so a large bound coarsens rather than allocating without limit. |
| | | 27 | | /// </summary> |
| | 52 | 28 | | public long MaxCells { get; set; } = 8_000_000; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// How far past the outermost band to keep searching, as a share of that band. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <remarks> |
| | | 34 | | /// The boundary is interpolated between a point inside it and one outside, so stopping at |
| | | 35 | | /// the band leaves nothing to interpolate against and the contour pulls inward. |
| | | 36 | | /// </remarks> |
| | 50 | 37 | | public double Margin { get; set; } = 0.15; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Drop any ring enclosing less than this share of the band's largest ring. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <remarks> |
| | | 43 | | /// Single cells get picked up where a road clips the corner of one. 0 keeps everything. |
| | | 44 | | /// </remarks> |
| | 55 | 45 | | public double Denoise { get; set; } = 0.01; |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// How far off a road still counts as reached, in metres. 0 marks only the roads. |
| | | 49 | | /// </summary> |
| | | 50 | | /// <remarks> |
| | | 51 | | /// Without this a band is a set of ribbons as wide as one grid cell, which only reads as an |
| | | 52 | | /// area where roads are closer together than that. Valhalla gets the same effect from cells |
| | | 53 | | /// of 110-550 m, where the ribbon is a cell wide; separating the two keeps the boundary as |
| | | 54 | | /// accurate as the grid while the fill is wide enough to join. |
| | | 55 | | /// </remarks> |
| | 70 | 56 | | public double ReachRadiusMeters { get; set; } = 150.0; |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Fill unreached pockets smaller than this, in square metres. 0 keeps every pocket. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <remarks> |
| | | 62 | | /// The surface only knows costs along roads, so without this every city block comes back as |
| | | 63 | | /// a hole and the band describes a street network rather than an area. The default fills a |
| | | 64 | | /// block of roughly 220 m a side and leaves genuinely unreachable ground — water, a closed |
| | | 65 | | /// estate — as the hole it is. |
| | | 66 | | /// </remarks> |
| | 58 | 67 | | public double FillHolesBelowSquareMeters { get; set; } = 50_000.0; |
| | | 68 | | |
| | | 69 | | internal void Validate() |
| | 17 | 70 | | { |
| | 17 | 71 | | if (this.CellSizeMeters is <= 0) |
| | 0 | 72 | | throw new ArgumentOutOfRangeException(nameof(this.CellSizeMeters)); |
| | 17 | 73 | | if (this.TargetCellsAcross < 2) |
| | 0 | 74 | | throw new ArgumentOutOfRangeException(nameof(this.TargetCellsAcross)); |
| | 17 | 75 | | if (this.MinCellSizeMeters <= 0) |
| | 0 | 76 | | throw new ArgumentOutOfRangeException(nameof(this.MinCellSizeMeters)); |
| | 17 | 77 | | if (this.MaxCells < 4) throw new ArgumentOutOfRangeException(nameof(this.MaxCells)); |
| | 17 | 78 | | if (this.Margin < 0) throw new ArgumentOutOfRangeException(nameof(this.Margin)); |
| | 17 | 79 | | if (this.Denoise is < 0 or > 1) throw new ArgumentOutOfRangeException(nameof(this.Denoise)); |
| | 17 | 80 | | if (this.FillHolesBelowSquareMeters < 0) |
| | 0 | 81 | | throw new ArgumentOutOfRangeException(nameof(this.FillHolesBelowSquareMeters)); |
| | 17 | 82 | | if (this.ReachRadiusMeters < 0) |
| | 0 | 83 | | throw new ArgumentOutOfRangeException(nameof(this.ReachRadiusMeters)); |
| | 17 | 84 | | } |
| | | 85 | | } |