Debian Codegraph @

unittest/gunit/gis_project_on_pole.h

raw symbols SCIP
1 /* Copyright (c) 2017, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #ifndef UNITTEST_GUNIT_GIS_PROJECT_ON_POLE_H_INCLUDED
25 #define UNITTEST_GUNIT_GIS_PROJECT_ON_POLE_H_INCLUDED
26
27 #include <cmath> // M_PI_2
28
29 #include "sql/gis/geometries_cs.h" // gis::{Cartesian_*,Geographic_*}
30
31 namespace {
32
33 /**
34 * Convert to polar coordinates (-y as polar axis), interpret as sphere north
35 * pole azimuthal equidistant coordinates, then unproject to latiude /
36 * longtitude. This transformation does not preserve any properties, and in
37 * particular, straight lines do not become geodesics unless going through
38 * cartesian point (0,0), mapped to the north pole. Intersections should happen
39 * at cartesian (0,0) to be guaranteed preseved.
40 *
41 * A better projection would be something like polar gnomonic but for an
42 * ellipsoid surface. Such a projection would ensure straight lines get mapped
43 * to geodesics. However, such a projection seems impossible.
44 */
45 gis::Geographic_point gis_project_on_pole(const gis::Cartesian_point &cart) {
46 using std::atan2;
47 using std::hypot;
48
49 auto x = cart.x();
50 auto y = cart.y();
51 // Input point should be inside radius pi/2 of origin. Otherwise
52 // clockwisedness of rings would not be preserved.
53 assert(hypot(x, y) <= M_PI_2);
54 // Rotate 45deg and project, so that -y points along the prime meridian and
55 // origin is on north pole, convert to polar, and translate origin to
56 // equator.
57 return {atan2(-y, x), (M_PI_2 - hypot(-y, x))};
58 }
59
60 inline gis::Geographic_linestring gis_project_on_pole(
61 const gis::Cartesian_linestring &cart) {
62 gis::Geographic_linestring geom;
63 for (size_t i = 0; i < cart.size(); i++) {
64 geom.push_back(gis_project_on_pole(cart[i]));
65 }
66 return geom;
67 }
68
69 } // namespace
70
71 #endif // include guard