aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/geo_gcd.h
blob: acd102070576918815d1f35d356a98306ab7371e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <cstdint>
#include <cmath>

namespace search::common {

/**
 * An immutable struct for a (geo) location point,
 * with methods for computing Great Circle Distance
 * using the haversine formula
 **/
struct GeoGcd
{
    GeoGcd(double lat, double lng);

    // haversine function:
    static constexpr double haversine(double angle) {
        double s = sin(0.5*angle);
        return s*s;
    }

    double km_great_circle_distance(double lat, double lng) const;
private:
    double _latitude_radians;
    double _longitude_radians;
};

} // namespace