Coverage Report

Created: 2023-09-25 06:53

/src/h3/src/h3lib/lib/vec3d.c
Line
Count
Source
1
/*
2
 * Copyright 2018, 2020-2021 Uber Technologies, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *         http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
/** @file vec3d.c
17
 * @brief   3D floating point vector functions.
18
 */
19
20
#include "vec3d.h"
21
22
#include <math.h>
23
24
/**
25
 * Square of a number
26
 *
27
 * @param x The input number.
28
 * @return The square of the input number.
29
 */
30
11.6k
double _square(double x) { return x * x; }
31
32
/**
33
 * Calculate the square of the distance between two 3D coordinates.
34
 *
35
 * @param v1 The first 3D coordinate.
36
 * @param v2 The second 3D coordinate.
37
 * @return The square of the distance between the given points.
38
 */
39
3.88k
double _pointSquareDist(const Vec3d *v1, const Vec3d *v2) {
40
3.88k
    return _square(v1->x - v2->x) + _square(v1->y - v2->y) +
41
3.88k
           _square(v1->z - v2->z);
42
3.88k
}
43
44
/**
45
 * Calculate the 3D coordinate on unit sphere from the latitude and longitude.
46
 *
47
 * @param geo The latitude and longitude of the point.
48
 * @param v The 3D coordinate of the point.
49
 */
50
194
void _geoToVec3d(const LatLng *geo, Vec3d *v) {
51
194
    double r = cos(geo->lat);
52
53
194
    v->z = sin(geo->lat);
54
194
    v->x = cos(geo->lng) * r;
55
194
    v->y = sin(geo->lng) * r;
56
194
}