Debian Codegraph @

unittest/gunit/gis_test_geom.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_TEST_GEOM_H_INCLUDED
25 #define UNITTEST_GUNIT_GIS_TEST_GEOM_H_INCLUDED
26
27 #include <cmath> // M_PI, M_PI_2
28
29 #include "sql/gis/geometries_cs.h" // gis::{Cartesian,Geographic}*
30
31 // Header-only definitions of sample geometries useful for testing
32 // Note that the internal point representation for geographic coordinates is
33 // (eastwards (-pi, pi], northwards [pi/2, pi/2]) in radians.
34
35 namespace {
36 namespace test_geom {
37
38 using Cpt = gis::Cartesian_point;
39 using Cls = gis::Cartesian_linestring;
40 using Cgc = gis::Cartesian_geometrycollection;
41 using Gpt = gis::Geographic_point;
42 using Gls = gis::Geographic_linestring;
43 using Ggc = gis::Geographic_geometrycollection;
44
45 inline Cpt point_origin() { return {0.0, 0.0}; }
46
47 inline Cls linestring_line() {
48 // Slanted line
49 Cls ls;
50 ls.push_back(Cpt{-1, -1});
51 ls.push_back(Cpt{+1, +1});
52 return ls;
53 }
54
55 inline Cls linestring_right_angle() {
56 // _|-shape
57 Cls ls;
58 ls.push_back(Cpt{-1, -1});
59 ls.push_back(Cpt{+1, -1});
60 ls.push_back(Cpt{+1, +1});
61 return ls;
62 }
63
64 inline Cls linestring_triangle() {
65 // Closed _|-shape
66 Cls ls;
67 ls.push_back(Cpt{-1, -1});
68 ls.push_back(Cpt{+1, -1});
69 ls.push_back(Cpt{+1, +1});
70 ls.push_back(Cpt{-1, -1});
71 return ls;
72 }
73
74 inline Cls linestring_selfintersecting() {
75 // Open bow / fish-shape, like: ><|
76 Cls ls;
77 ls.push_back(Cpt{-1, +1});
78 ls.push_back(Cpt{+1, -1});
79 ls.push_back(Cpt{+1, +1});
80 ls.push_back(Cpt{-1, -1});
81 return ls;
82 }
83
84 inline Cls linestring_selfintersecting_closed() {
85 // Bow-shape, like |><|
86 Cls ls;
87 ls.push_back(Cpt{-1, +1});
88 ls.push_back(Cpt{+1, -1});
89 ls.push_back(Cpt{+1, +1});
90 ls.push_back(Cpt{-1, -1});
91 ls.push_back(Cpt{-1, +1});
92 return ls;
93 }
94
95 inline Cls linestring_selftangential() {
96 Cls ls;
97 ls.push_back(Cpt{-1.0, -0.75});
98 ls.push_back(Cpt{+1.0, -0.75});
99 ls.push_back(Cpt{+0.0, +0.00}); // Tangent point
100 ls.push_back(Cpt{+0.5, -0.50});
101 ls.push_back(Cpt{-0.5, -0.50}); // Tangent line
102 ls.push_back(Cpt{+0.5, +0.50}); // Touch at midpoint
103 ls.push_back(Cpt{-1.0, -0.75});
104 return ls;
105 }
106
107 inline Gls linestring_pole_alias() {
108 // Line between two coordinates both mapping to the north-pole
109 Gls ls;
110 ls.push_back(Gpt{0, M_PI_2});
111 ls.push_back(Gpt{1, M_PI_2});
112 return ls;
113 }
114
115 inline Cgc geometrycollection_empty() { return {}; }
116
117 inline Cgc geometrycollection_crossintersecting() {
118 Cgc gc;
119 {
120 Cls ls;
121 ls.push_back(Cpt{-1, -1});
122 ls.push_back(Cpt{+1, +1});
123 gc.push_back(ls);
124 }
125 {
126 Cls ls;
127 ls.push_back(Cpt{-1, +1});
128 ls.push_back(Cpt{+1, -1});
129 gc.push_back(ls);
130 }
131 return gc;
132 }
133
134 inline Cgc geometrycollection_subintersecting() {
135 Cgc gc;
136 gc.push_back(linestring_selfintersecting());
137 return gc;
138 }
139
140 inline Ggc bug26495068() {
141 // Regression test for Bug#26495068
142 // Certain geometries crossing the anti-meridian give incorrect results.
143 auto deg = [](double x) { return x * M_PI / 180; };
144 Ggc gc;
145 {
146 Gls ls;
147 ls.push_back(Gpt{deg(135), deg(0)});
148 ls.push_back(Gpt{deg(-150), deg(36)});
149 gc.push_back(ls);
150 }
151 {
152 Gls ls;
153 ls.push_back(Gpt{deg(-101), deg(0)});
154 ls.push_back(Gpt{deg(-178), deg(30)});
155 gc.push_back(ls);
156 }
157 return gc;
158 }
159
160 } // namespace test_geom
161 } // namespace
162
163 #endif // include guard