# Geospatial Metrics

> NumKong for Swift

The Swift geospatial helpers operate on four coordinate arrays, two per point set.
They score every point of the first set against every point of the second.
Inputs are in radians.
Outputs are in meters, row-major with one row per point of the first set.

```swift
import NumKong

// Statue of Liberty (40.6892°N, 74.0445°W) → Big Ben (51.5007°N, 0.1246°W)
let libertyLatitudes: [Float64] = [0.7101605100]
let libertyLongitudes: [Float64] = [-1.2923203180]
let bigBenLatitudes: [Float64] = [0.8988567821]
let bigBenLongitudes: [Float64] = [-0.0021746802]

let ellipsoidal = vincentys(
    aLatitudes: libertyLatitudes, aLongitudes: libertyLongitudes,
    bLatitudes: bigBenLatitudes, bLongitudes: bigBenLongitudes) // ≈ [5,589,857] m
let spherical = haversines(
    aLatitudes: libertyLatitudes, aLongitudes: libertyLongitudes,
    bLatitudes: bigBenLatitudes, bLongitudes: bigBenLongitudes) // ≈ [5,574,848] m
```

The low-level `UnsafeBufferPointer` static methods on `Float64` remain available for zero-copy use cases.

`import NumKong`

## NumKongGeospatial

Convenience alias for types supporting both Haversine and Vincenty geospatial distances.

```swift
typealias NumKongGeospatial = NumKongHaversines & NumKongVincentys
```

## NumKongHaversines

A type that can compute SIMD-accelerated great-circle Haversine distances from every point of one set to every point of another, row-major with one row per `a` point.

```swift
protocol NumKongHaversines : BinaryFloatingPoint
```

Conforms to: `BinaryFloatingPoint`, `ExpressibleByFloatLiteral`, `FloatingPoint`, `Hashable`, `Equatable`, `Strideable`, `Comparable`, `SignedNumeric`, `Numeric`, `ExpressibleByIntegerLiteral`, `AdditiveArithmetic`

Conforming types: [`Double`](https://www.unum.cloud/docs/numkong/swift/scalar-types.md#Double)

## haversines

Writes Haversine distances from every `a` point to every `b` point into `results`.

```swift
static func haversines(
    aLatitudes: UnsafeBufferPointer<Self>,
    aLongitudes: UnsafeBufferPointer<Self>,
    bLatitudes: UnsafeBufferPointer<Self>,
    bLongitudes: UnsafeBufferPointer<Self>,
    results: UnsafeMutableBufferPointer<Self>
) -> Bool
```

```swift
static func haversines<A, B, C, D>(
    aLatitudes: A,
    aLongitudes: B,
    bLatitudes: C,
    bLongitudes: D
) -> [Self]? where Self == A.Element, A : Sequence, B : Sequence, C : Sequence, D : Sequence, A.Element == B.Element, B.Element == C.Element, C.Element == D.Element
```

Computes Haversine distances from every `a` point to every `b` point.

Coordinates are in radians, with as many longitudes as latitudes in each set.
`results` receives meters, row-major with one row per `a` point.

## NumKongVincentys

A type that can compute SIMD-accelerated Vincenty ellipsoidal geodesic distances from every point of one set to every point of another, row-major with one row per `a` point.

```swift
protocol NumKongVincentys : BinaryFloatingPoint
```

Conforms to: `BinaryFloatingPoint`, `ExpressibleByFloatLiteral`, `FloatingPoint`, `Hashable`, `Equatable`, `Strideable`, `Comparable`, `SignedNumeric`, `Numeric`, `ExpressibleByIntegerLiteral`, `AdditiveArithmetic`

Conforming types: [`Double`](https://www.unum.cloud/docs/numkong/swift/scalar-types.md#Double)

## vincentys

Writes Vincenty geodesic distances from every `a` point to every `b` point into `results`.

```swift
static func vincentys(
    aLatitudes: UnsafeBufferPointer<Self>,
    aLongitudes: UnsafeBufferPointer<Self>,
    bLatitudes: UnsafeBufferPointer<Self>,
    bLongitudes: UnsafeBufferPointer<Self>,
    results: UnsafeMutableBufferPointer<Self>
) -> Bool
```

```swift
static func vincentys<A, B, C, D>(
    aLatitudes: A,
    aLongitudes: B,
    bLatitudes: C,
    bLongitudes: D
) -> [Self]? where Self == A.Element, A : Sequence, B : Sequence, C : Sequence, D : Sequence, A.Element == B.Element, B.Element == C.Element, C.Element == D.Element
```

Computes Vincenty geodesic distances from every `a` point to every `b` point.

Coordinates are in radians, with as many longitudes as latitudes in each set.
`results` receives meters, row-major with one row per `a` point.

## *

```swift
func haversines<A>(
    aLatitudes: A,
    aLongitudes: A,
    bLatitudes: A,
    bLongitudes: A
) -> [Float64]? where A : Sequence, A.Element == Double
```

- `haversines`
- `vincentys`

