///|
/// A geographic point in degrees and metres.
pub(all) struct GeoPoint {
  lat : Double
  lon : Double
  elevation_m : Double
} derive(Debug, Eq)

///|
/// A scalar geophysical observation attached to a geographic point.
pub(all) struct FieldSample {
  point : GeoPoint
  value : Double
  name : String
} derive(Debug, Eq)

///|
/// Regular latitude/longitude grid in row-major order.
pub(all) struct Grid {
  origin_lat : Double
  origin_lon : Double
  lat_step : Double
  lon_step : Double
  rows : Int
  cols : Int
  values : Array[Double]
} derive(Debug, Eq)

///|
/// Result of sampling a grid along a transect.
pub(all) struct ProfileSample {
  point : GeoPoint
  distance_m : Double
  value : Double
} derive(Debug, Eq)

///|
/// One coefficient pair for a compact spherical-harmonic-style model.
pub(all) struct HarmonicTerm {
  degree : Int
  order : Int
  cosine : Double
  sine : Double
} derive(Debug, Eq)

///|
/// Lightweight spherical harmonic model. The coefficients are dimensionless;
/// callers decide whether the returned scalar represents potential, anomaly,
/// or a normalized field correction.
pub(all) struct SphericalHarmonicModel {
  reference_radius_m : Double
  scale : Double
  terms : Array[HarmonicTerm]
} derive(Debug, Eq)

///|
/// A closed numeric interval used by quality-control and resampling APIs.
pub(all) struct NumericRange {
  minimum : Double
  maximum : Double
} derive(Debug, Eq)

///|
pub enum QualityFlag {
  Good
  Suspect
  Missing
  Invalid
  Outlier
} derive(Debug, Eq)

///|
/// A field sample with a quality flag and optional source label.
pub(all) struct QualitySample {
  sample : FieldSample
  flag : QualityFlag
  uncertainty : Double
  source : String
} derive(Debug, Eq)

///|
pub enum MissingPolicy {
  SkipMissing
  PreserveMissing
  ReplaceWith(value~ : Double)
} derive(Debug, Eq)

///|
pub(all) struct Summary {
  count : Int
  missing : Int
  minimum : Double
  maximum : Double
  mean : Double
  variance : Double
  sum : Double
} derive(Debug, Eq)

///|
pub(all) struct GridExtent {
  min_lat : Double
  max_lat : Double
  min_lon : Double
  max_lon : Double
} derive(Debug, Eq)

///|
pub(all) struct GridCell {
  row : Int
  col : Int
  point : GeoPoint
  value : Double
} derive(Debug, Eq)

///|
pub(all) struct Vector3 {
  x : Double
  y : Double
  z : Double
} derive(Debug, Eq)

///|
pub(all) struct Gradient {
  north_per_degree : Double
  east_per_degree : Double
  magnitude : Double
  azimuth_deg : Double
} derive(Debug, Eq)

///|
pub(all) struct ProfileSummary {
  samples : Int
  distance_m : Double
  minimum : Double
  maximum : Double
  mean : Double
  range : Double
} derive(Debug, Eq)

///|
pub(all) struct ContourSegment {
  start : GeoPoint
  finish : GeoPoint
  level : Double
} derive(Debug, Eq)

///|
/// A scalar observation on a one-dimensional distance or time axis.
pub(all) struct SeriesPoint {
  coordinate : Double
  value : Double
  flag : QualityFlag
} derive(Debug, Eq)

///|
/// A named ordered sequence of field observations.
pub(all) struct FieldSeries {
  name : String
  points : Array[SeriesPoint]
} derive(Debug, Eq)

///|
pub(all) struct Regression {
  slope : Double
  intercept : Double
  r_squared : Double
  residual_rms : Double
  samples : Int
} derive(Debug, Eq)

///|
pub(all) struct HistogramBin {
  lower : Double
  upper : Double
  count : Int
} derive(Debug, Eq)

///|
pub(all) struct OutlierReport {
  indices : Array[Int]
  center : Double
  scale : Double
} derive(Debug, Eq)

///|
pub(all) struct CovarianceSummary {
  covariance : Double
  correlation : Double
  samples : Int
} derive(Debug, Eq)

///|
pub(all) struct RegionSummary {
  label : Int
  cells : Int
  mean : Double
  minimum : Double
  maximum : Double
  area_m2 : Double
} derive(Debug, Eq)

///|
pub(all) struct PointEstimate {
  point : GeoPoint
  value : Double
  neighbours : Int
} derive(Debug, Eq)

///|
pub(all) struct RasterStats {
  valid : Int
  missing : Int
  minimum : Double
  maximum : Double
  mean : Double
  standard_deviation : Double
  area_m2 : Double
} derive(Debug, Eq)

///|
pub(all) struct Kernel3x3 {
  values : Array[Double]
  divisor : Double
} derive(Debug, Eq)

///|
pub(all) struct CoefficientTable {
  reference_radius_m : Double
  scale : Double
  terms : Array[HarmonicTerm]
  source : String
} derive(Debug, Eq)

///|
pub(all) struct DegreeSummary {
  degree : Int
  terms : Int
  cosine_energy : Double
  sine_energy : Double
} derive(Debug, Eq)

///|
pub(all) struct GravityComponents {
  normal_mgal : Double
  free_air_mgal : Double
  bouguer_mgal : Double
  terrain_mgal : Double
} derive(Debug, Eq)

///|
pub(all) struct MagneticField {
  north_nt : Double
  east_nt : Double
  down_nt : Double
  total_nt : Double
  declination_deg : Double
  inclination_deg : Double
} derive(Debug, Eq)

///|
pub(all) struct MagneticPole {
  latitude_deg : Double
  longitude_deg : Double
  strength_nt : Double
} derive(Debug, Eq)

///|
pub(all) struct PolylineFeature {
  name : String
  points : Array[GeoPoint]
} derive(Debug, Eq)

///|
pub(all) struct SpatialSummary {
  neighbours : Int
  mean : Double
  weighted_mean : Double
  minimum_distance_m : Double
  maximum_distance_m : Double
} derive(Debug, Eq)

///|
/// Dense row-major matrix used by small least-squares and transformation tasks.
pub(all) struct Matrix {
  rows : Int
  cols : Int
  values : Array[Double]
} derive(Debug, Eq)

///|
pub(all) struct LeastSquaresResult {
  coefficients : Array[Double]
  residual_sum_squares : Double
  rank : Int
  samples : Int
} derive(Debug, Eq)

///|
pub(all) struct VariogramBin {
  lower_distance_m : Double
  upper_distance_m : Double
  pairs : Int
  mean_distance_m : Double
  semivariance : Double
} derive(Debug, Eq)

///|
pub(all) struct VariogramModel {
  nugget : Double
  sill : Double
  range_m : Double
} derive(Debug, Eq)

///|
pub(all) struct CrossValidationReport {
  samples : Int
  predictions : Array[Double]
  residuals : Array[Double]
  rmse : Double
  mean_absolute_error : Double
} derive(Debug, Eq)

///|
pub(all) struct QualitySummary {
  total : Int
  usable : Int
  missing : Int
  invalid : Int
  suspect : Int
  outlier : Int
} derive(Debug, Eq)

///|
pub(all) struct SampleDesign {
  points : Array[GeoPoint]
  rows : Int
  cols : Int
  spacing_lat_deg : Double
  spacing_lon_deg : Double
} derive(Debug, Eq)