Debian Codegraph @

sys/Graphics_altitude.cpp

raw symbols SCIP
1 /* Graphics_altitude.cpp
2 *
3 * Copyright (C) 1992-2005,2008,2011,2015-2020 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/
20
21 static int emptycxx . . $ empty(b62d2ee55d458130). (constMATVUcxx . . $ constMATVU# const& data, constBOOLMATcxx . . $ constBOOLMAT# const& right, constBOOLMATcxx . . $ constBOOLMAT# const& below, integercxx . . $ integer# row1, integercxx . . $ integer# col1, double height, integercxx . . $ integer# row, integercxx . . $ integer# col, integercxx . . $ integer# ori) {
22 if (ori == 3) {
23 row ++;
24 ori = 1;
25 } else if (ori == 2) {
26 col ++;
27 ori = 4;
28 }
29 if (ori == 1)
30 return (data [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col] < height) != (data [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col + 1] < height) &&
31 ! right [cxx . . $ constmatrix#`operator[]`(aae4ad074ae650ba).row - row1 + 1] [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).col - col1 + 1];
32 else /* ori == 4 */
33 return (data [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col] < height) != (data [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row + 1] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col] < height) &&
34 ! below [cxx . . $ constmatrix#`operator[]`(aae4ad074ae650ba).row - row1 + 1] [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).col - col1 + 1];
35 }
36
37 #define MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! 50
38 #define MAXALTPATHcxx . . $ `sys/Graphics_altitude.cpp:38:9`! (2 * MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! * (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1) + 2)
39
40 static integercxx . . $ integer# numberOfPointscxx . . $ numberOfPoints.;
41 static integercxx . . $ integer# row1cxx . . $ row1., row2cxx . . $ row2., col1cxx . . $ col1., col2cxx . . $ col2.;
42 static autoBOOLMATcxx . . $ autoBOOLMAT# rightcxx . . $ right., belowcxx . . $ below.;
43 static autoVECcxx . . $ autoVEC# xcxx . . $ x., ycxx . . $ y.;
44 static bool closedcxx . . $ closed.;
45 static double dxcxx . . $ dx., dycxx . . $ dy., xoffcxx . . $ xoff., yoffcxx . . $ yoff.;
46
47 static int notecxx . . $ note(22bbacca1d27327b). (constMATVUcxx . . $ constMATVU# const& z, double height, integercxx . . $ integer# row, integercxx . . $ integer# col, int ori, bool pleaseForget) {
48 ++ numberOfPointscxx . . $ numberOfPoints.;
49 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (numberOfPoints <= MAXALTPATHcxx . . $ `sys/Graphics_altitude.cpp:38:9`!);
50 if (ori == 3) {
51 row ++;
52 ori = 1;
53 } else if (ori == 2) {
54 col ++;
55 ori = 4;
56 }
57 if (ori == 1) {
58 if (pleaseForget)
59 rightcxx . . $ right. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).row - row1cxx . . $ row1. + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).col - col1cxx . . $ col1. + 1] = true;
60 xcxx . . $ x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPointscxx . . $ numberOfPoints.] = xoffcxx . . $ xoff. +
61 (col + (height - z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col]) / (z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col + 1] - z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col])) * dxcxx . . $ dx.;
62 ycxx . . $ y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPointscxx . . $ numberOfPoints.] = yoffcxx . . $ yoff. + row * dycxx . . $ dy.;
63 } else { /* ori == 4 */
64 if (pleaseForget)
65 belowcxx . . $ below. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).row - row1cxx . . $ row1. + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).col - col1cxx . . $ col1. + 1] = true;
66 xcxx . . $ x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPointscxx . . $ numberOfPoints.] = xoffcxx . . $ xoff. + col * dxcxx . . $ dx.;
67 ycxx . . $ y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPointscxx . . $ numberOfPoints.] = yoffcxx . . $ yoff. +
68 (row + (height - z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col]) / (z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row + 1] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col] - z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).row] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).col])) * dycxx . . $ dy.;
69 }
70 return 1;
71 }
72
73 static void makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (Graphicscxx . . $ Graphics# graphics, constMATVUcxx . . $ constMATVU# const& z, double height, integercxx . . $ integer# row0, integercxx . . $ integer# col0, int ori0) {
74 integercxx . . $ integer# row = row0, col = col0;
75 bool edge = false;
76 int ori = ori0;
77 numberOfPointscxx . . $ numberOfPoints. = 0;
78 notecxx . . $ note(22bbacca1d27327b). (z, height, row0, col0, ori0, false);
79 do {
80 bool const clockwise = ! (ori & 1);
81 do { /* Preference for contours perpendicular to x == y. */
82 ori = ( clockwise ? ori : ori + 2 ) % 4 + 1;
83 } while (! emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row, col, ori));
84 if (! closedcxx . . $ closed.) switch (ori) {
85 case 1: edge = row == row1cxx . . $ row1.; break;
86 case 2: edge = col == col2cxx . . $ col2. - 1; break;
87 case 3: edge = row == row2cxx . . $ row2. - 1; break;
88 case 4: edge = col == col1cxx . . $ col1.; break;
89 }
90 if (! edge) {
91 switch (ori) {
92 case 1: row --; break;
93 case 2: col ++; break;
94 case 3: row ++; break;
95 case 4: col --; break;
96 }
97 ori = (ori + 1) % 4 + 1;
98 }
99 if (! notecxx . . $ note(22bbacca1d27327b). (z, height, row, col, ori, 1))
100 return;
101 }
102 while (edge == 0 && (row != row0 || col != col0 || ori != ori0))
103 ;
104 if (closedcxx . . $ closed.)
105 notecxx . . $ note(22bbacca1d27327b). (z, height, row0, col0, ori0, true); // close the contour
106 Graphics_polylinecxx . . $ Graphics_polyline(23a712ce109b96e0). (graphics, numberOfPointscxx . . $ numberOfPoints., & xcxx . . $ x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], & ycxx . . $ y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]);
107 }
108
109 static void smallAltcxx . . $ smallAlt(af7691ee81fad5ca). (Graphicscxx . . $ Graphics# graphics, constMATVUcxx . . $ constMATVU# const& z, double height) {
110 for (integercxx . . $ integer# row = 1; row <= MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!; row ++)
111 for (integercxx . . $ integer# col = 1; col <= MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!; col ++)
112 rightcxx . . $ right. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).row] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).col] = belowcxx . . $ below. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).row] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).col] = false;
113
114 /* Find all the edge contours of this border value. */
115
116 closedcxx . . $ closed. = false;
117 for (integercxx . . $ integer# col = col1cxx . . $ col1.; col < col2cxx . . $ col2.; col ++)
118 if (emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row1cxx . . $ row1., col, 1))
119 makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (graphics, z, height, row1cxx . . $ row1., col, 1);
120 for (integercxx . . $ integer# row = row1cxx . . $ row1.; row < row2cxx . . $ row2.; row ++)
121 if (emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row, col2cxx . . $ col2. - 1, 2))
122 makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (graphics, z, height, row, col2cxx . . $ col2. - 1, 2);
123 for (integercxx . . $ integer# col = col2cxx . . $ col2. - 1; col >= col1cxx . . $ col1.; col --)
124 if (emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row2cxx . . $ row2. - 1, col, 3))
125 makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (graphics, z, height, row2cxx . . $ row2. - 1, col, 3);
126 for (integercxx . . $ integer# row = row2cxx . . $ row2. - 1; row >= row1cxx . . $ row1.; row --)
127 if (emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row, col1cxx . . $ col1., 4))
128 makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (graphics, z, height, row, col1cxx . . $ col1., 4);
129
130 /* Find all the closed contours of this border value. */
131
132 closedcxx . . $ closed. = true;
133 for (integercxx . . $ integer# row = row1cxx . . $ row1. + 1; row < row2cxx . . $ row2.; row ++)
134 for (integercxx . . $ integer# col = col1cxx . . $ col1.; col < col2cxx . . $ col2.; col ++)
135 if (emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row, col, 1))
136 makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (graphics, z, height, row, col, 1);
137 for (integercxx . . $ integer# col = col1cxx . . $ col1. + 1; col < col2cxx . . $ col2.; col ++)
138 for (integercxx . . $ integer# row = row1cxx . . $ row1.; row < row2cxx . . $ row2.; row ++)
139 if (emptycxx . . $ empty(b62d2ee55d458130). (z, rightcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), belowcxx . . $ constmatrix#constmatrix(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), row1cxx . . $ row1., col1cxx . . $ col1., height, row, col, 4))
140 makeContourcxx . . $ makeContour(eafa4b4a01376ff2). (graphics, z, height, row, col, 4);
141 }
142
143 void Graphics_contourcxx . . $ Graphics_contour(da66b3099e9f7711). (Graphicscxx . . $ Graphics# me, constMATVUcxx . . $ constMATVU# const& z,
144 double x1WC, double x2WC, double y1WC, double y2WC,
145 double height)
146 {
147 if (z.nrowcxx . . $ constmatrixview#nrow. <= 1 || z.ncolcxx . . $ constmatrixview#ncol. <= 1)
148 return;
149 dxcxx . . $ dx. = (x2WC - x1WC) / (z.ncolcxx . . $ constmatrixview#ncol. - 1);
150 dycxx . . $ dy. = (y2WC - y1WC) / (z.nrowcxx . . $ constmatrixview#nrow. - 1);
151 xoffcxx . . $ xoff. = x1WC - dxcxx . . $ dx.;
152 yoffcxx . . $ yoff. = y1WC - dycxx . . $ dy.;
153 if (NUMisEmptycxx . . $ NUMisEmpty(43b61114f729c675). (rightcxx . . $ right..getcxx . . $ automatrix#get(b2b81450b5bdda66).())) { // static!
154 rightcxx . . $ right. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_BOOLMATcxx . . $ zero_BOOLMAT(e9a8779cbc949ca0). (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!, MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!);
155 belowcxx . . $ below. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_BOOLMATcxx . . $ zero_BOOLMAT(e9a8779cbc949ca0). (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!, MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!);
156 xcxx . . $ x. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (MAXALTPATHcxx . . $ `sys/Graphics_altitude.cpp:38:9`!);
157 ycxx . . $ y. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (MAXALTPATHcxx . . $ `sys/Graphics_altitude.cpp:38:9`!);
158 }
159 for (row1cxx . . $ row1. = 1; row1cxx . . $ row1. < z.nrowcxx . . $ constmatrixview#nrow.; row1cxx . . $ row1. += MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1) {
160 for (col1cxx . . $ col1. = 1; col1cxx . . $ col1. < z.ncolcxx . . $ constmatrixview#ncol.; col1cxx . . $ col1. += MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1) {
161 if ((row2cxx . . $ row2. = row1cxx . . $ row1. + (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1)) > z.nrowcxx . . $ constmatrixview#nrow.)
162 row2cxx . . $ row2. = z.nrowcxx . . $ constmatrixview#nrow.;
163 if ((col2cxx . . $ col2. = col1cxx . . $ col1. + (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1)) > z.ncolcxx . . $ constmatrixview#ncol.)
164 col2cxx . . $ col2. = z.ncolcxx . . $ constmatrixview#ncol.;
165 smallAltcxx . . $ smallAlt(af7691ee81fad5ca). (me, z, height);
166 }
167 }
168 }
169
170 void Graphics_altitudecxx . . $ Graphics_altitude(42c98de22ed1cdd8). (Graphicscxx . . $ Graphics# me, constMATVUcxx . . $ constMATVU# const& z,
171 double x1WC, double x2WC, double y1WC, double y2WC,
172 int numberOfBorders, double borders [])
173 {
174 if (z.nrowcxx . . $ constmatrixview#nrow. <= 1 || z.ncolcxx . . $ constmatrixview#ncol. <= 1)
175 return;
176 dxcxx . . $ dx. = (x2WC - x1WC) / (z.ncolcxx . . $ constmatrixview#ncol. - 1);
177 dycxx . . $ dy. = (y2WC - y1WC) / (z.nrowcxx . . $ constmatrixview#nrow. - 1);
178 xoffcxx . . $ xoff. = x1WC - dxcxx . . $ dx.;
179 yoffcxx . . $ yoff. = y1WC - dycxx . . $ dy.;
180 if (NUMisEmptycxx . . $ NUMisEmpty(43b61114f729c675). (rightcxx . . $ right..getcxx . . $ automatrix#get(b2b81450b5bdda66).())) { // static!
181 rightcxx . . $ right. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_BOOLMATcxx . . $ zero_BOOLMAT(e9a8779cbc949ca0). (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!, MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!);
182 belowcxx . . $ below. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_BOOLMATcxx . . $ zero_BOOLMAT(e9a8779cbc949ca0). (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!, MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`!);
183 xcxx . . $ x. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (MAXALTPATHcxx . . $ `sys/Graphics_altitude.cpp:38:9`!);
184 ycxx . . $ y. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (MAXALTPATHcxx . . $ `sys/Graphics_altitude.cpp:38:9`!);
185 }
186 for (row1cxx . . $ row1. = 1; row1cxx . . $ row1. < z.nrowcxx . . $ constmatrixview#nrow.; row1cxx . . $ row1. += MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1) {
187 for (col1cxx . . $ col1. = 1; col1cxx . . $ col1. < z.ncolcxx . . $ constmatrixview#ncol.; col1cxx . . $ col1. += MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1) {
188 if ((row2cxx . . $ row2. = row1cxx . . $ row1. + (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1)) > z.nrowcxx . . $ constmatrixview#nrow.)
189 row2cxx . . $ row2. = z.nrowcxx . . $ constmatrixview#nrow.;
190 if ((col2cxx . . $ col2. = col1cxx . . $ col1. + (MAXALTSIDEcxx . . $ `sys/Graphics_altitude.cpp:37:9`! - 1)) > z.ncolcxx . . $ constmatrixview#ncol.)
191 col2cxx . . $ col2. = z.ncolcxx . . $ constmatrixview#ncol.;
192 for (int iborder = 1; iborder <= numberOfBorders; iborder ++)
193 smallAltcxx . . $ smallAlt(af7691ee81fad5ca). (me, z, borders [iborder]);
194 }
195 }
196 }
197
198 /* End of file Graphics_altitude.cpp */