| 1 | /* Polygon_extensions.c |
| 2 | * |
| 3 | * Copyright (C) 1993-2020 David Weenink |
| 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. See the GNU |
| 13 | * 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 | /* |
| 20 | djmw 20020813 GPL header |
| 21 | djmw 20080122 float -> double |
| 22 | djmw 20100407 Sound_to_Polygon, Sounds_to_Polygon_encloseds |
| 23 | djmw 20100418 Polygon_rotate. bug: angle was in degrees now in radians |
| 24 | */ |
| 25 | |
| 26 | #include "Matrix.h"cxx . . $ `<file>/fon/Matrix.h`/ |
| 27 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 28 | #include "NUMselect.h"cxx . . $ `<file>/dwsys/NUMselect.h`/ |
| 29 | #include "Polygon_extensions.h"cxx . . $ `<file>/dwtools/Polygon_extensions.h`/ |
| 30 | #include "Vector.h"cxx . . $ `<file>/fon/Vector.h`/ |
| 31 | #include "DoublyLinkedList.h"cxx . . $ `<file>/dwsys/DoublyLinkedList.h`/ |
| 32 | |
| 33 | // not for self-intersecting polygons! |
| 34 | static double Polygon_areacxx . . $ Polygon_area(8e940d5358c1a895). (Polygoncxx . . $ Polygon# me) { |
| 35 | longdoublecxx . . $ longdouble# area = 0.0; |
| 36 | integercxx . . $ integer# j = mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; |
| 37 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 38 | area += (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]) * (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j] - mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]); |
| 39 | j = i; |
| 40 | } |
| 41 | area *= 0.5; |
| 42 | return fabscxx . . $ fabs(fee4f1d22bc8e617). (double (area)); // area may have negative sign in counter-clockwise evaluation of area |
| 43 | } |
| 44 | |
| 45 | void Polygon_getExtremacxx . . $ Polygon_getExtrema(7bc564fe6c79180b). (Polygoncxx . . $ Polygon# me, double *out_xmin, double *out_xmax, double *out_ymin, double *out_ymax) { |
| 46 | const double xmin = numcxx . . $ num/::NUMmin_ecxx . . $ num/NUMmin_e(b008299b69cc71e6). (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 47 | const double xmax = numcxx . . $ num/::NUMmax_ecxx . . $ num/NUMmax_e(b008299b69cc71e6). (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 48 | const double ymin = numcxx . . $ num/::NUMmin_ecxx . . $ num/NUMmin_e(b008299b69cc71e6). (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 49 | const double ymax = numcxx . . $ num/::NUMmax_ecxx . . $ num/NUMmax_e(b008299b69cc71e6). (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 50 | if (out_xmin) |
| 51 | *out_xmin = xmin; |
| 52 | if (out_xmax) |
| 53 | *out_xmax = xmax; |
| 54 | if (out_ymin) |
| 55 | *out_ymin = ymin; |
| 56 | if (out_ymax) |
| 57 | *out_ymax = ymax; |
| 58 | } |
| 59 | |
| 60 | autoPolygoncxx . . $ autoPolygon# Polygon_createSimplecxx . . $ Polygon_createSimple(5ec1d710d38aec9c). (constVECVUcxx . . $ constVECVU# const& vertices_asXYPairs) { |
| 61 | try { |
| 62 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vertices_asXYPairs.size >= 6, |
| 63 | U"There should be at least 3 points (= x,y pairs) in the Polygon"); |
| 64 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vertices_asXYPairs.size % 2 == 0, |
| 65 | U"One value is missing."); |
| 66 | |
| 67 | const integercxx . . $ integer# numberOfPoints = vertices_asXYPairs.sizecxx . . $ constvectorview#size. / 2; |
| 68 | autoPolygoncxx . . $ autoPolygon# me = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (numberOfPoints); |
| 69 | for (integercxx . . $ integer# i = 1; i <= numberOfPoints; i ++) { |
| 70 | mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = vertices_asXYPairs [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).2 * i - 1]; |
| 71 | mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = vertices_asXYPairs [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).2 * i]; |
| 72 | if (i > 1 && mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] == mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1] && mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] == mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1]) |
| 73 | Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Two successive vertices are equal."); |
| 74 | } |
| 75 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 76 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 77 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Polygon not created."); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | autoPolygoncxx . . $ autoPolygon# Polygon_createFromRandomPointscxx . . $ Polygon_createFromRandomPoints(a7feded88c281902). (integercxx . . $ integer# numberOfVertices, double xmin, double xmax, double ymin, double ymax) { |
| 82 | try { |
| 83 | autoPolygoncxx . . $ autoPolygon# me = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (numberOfVertices); |
| 84 | for (integercxx . . $ integer# i = 1; i <= numberOfVertices; i ++) { |
| 85 | mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (xmin, xmax); |
| 86 | mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (ymin, ymax); |
| 87 | } |
| 88 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 89 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 90 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Polygon not created."); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void Polygon_translatecxx . . $ Polygon_translate(5c67dd9106539855). (Polygoncxx . . $ Polygon# me, double xt, double yt) { |
| 95 | mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).() +=cxx . . $ `operator+=`(c555d170d72ff256). xt; |
| 96 | mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).() +=cxx . . $ `operator+=`(c555d170d72ff256). yt; |
| 97 | } |
| 98 | |
| 99 | /* rotate counterclockwise w.r.t. (xc,yc) */ |
| 100 | void Polygon_rotatecxx . . $ Polygon_rotate(47fb2ed3c48fec03). (Polygoncxx . . $ Polygon# me, double alpha, double xc, double yc) { |
| 101 | const double f = alpha * NUMpicxx . . $ NUMpi. / 180, cosa = coscxx . . $ cos(fee4f1d22bc8e617). (f), sina = sincxx . . $ sin(fee4f1d22bc8e617). (f); |
| 102 | |
| 103 | Polygon_translatecxx . . $ Polygon_translate(5c67dd9106539855). (me, -xc, -yc); |
| 104 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 105 | const double x = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 106 | mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = cosa * mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] - sina * mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 107 | mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = sina * x + cosa * mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 108 | } |
| 109 | Polygon_translatecxx . . $ Polygon_translate(5c67dd9106539855). (me, xc, yc); |
| 110 | } |
| 111 | |
| 112 | void Polygon_scalecxx . . $ Polygon_scale(5c67dd9106539855). (Polygoncxx . . $ Polygon# me, double xs, double ys) { |
| 113 | mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).() *=cxx . . $ `operator*=`(c555d170d72ff256). xs; |
| 114 | mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).() *=cxx . . $ `operator*=`(c555d170d72ff256). ys; |
| 115 | } |
| 116 | |
| 117 | void Polygon_reverseXcxx . . $ Polygon_reverseX(91453997b1d2886f). (Polygoncxx . . $ Polygon# me) { |
| 118 | mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).() *=cxx . . $ `operator*=`(c555d170d72ff256). -1.0; |
| 119 | } |
| 120 | |
| 121 | void Polygon_reverseYcxx . . $ Polygon_reverseY(91453997b1d2886f). (Polygoncxx . . $ Polygon# me) { |
| 122 | mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).() *=cxx . . $ `operator*=`(c555d170d72ff256). -1.0; |
| 123 | } |
| 124 | |
| 125 | void Polygon_Categories_drawcxx . . $ Polygon_Categories_draw(d630b9065d4a3419). (Polygoncxx . . $ Polygon# me, Categoriescxx . . $ Categories# thee, Graphicscxx . . $ Graphics# graphics, double xmin, double xmax, double ymin, double ymax, bool garnish) { |
| 126 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. != thycxx . . $ `melder/melder.h:45:9`! sizecxx . . $ CollectionOf#size.) |
| 127 | return; |
| 128 | if (xmax == xmin) { |
| 129 | const MelderRealRangecxx . . $ MelderRealRange# xrange = NUMextrema_ucxx . . $ NUMextrema_u(453fd68922d5429d). (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 130 | if (isundefcxx . . $ isundef(dfa1b40f738f9ef2). (xrange)) |
| 131 | return; |
| 132 | const double tmp = 0.5 * xrange.isEmptycxx . . $ MelderRealRange#isEmpty(50ce9a9e25b4a850).(); |
| 133 | xmin = xrange.mincxx . . $ MelderRealRange#min. - tmp; |
| 134 | xmax = xrange.maxcxx . . $ MelderRealRange#max. + tmp; |
| 135 | } |
| 136 | if (ymax == ymin) { |
| 137 | const MelderRealRangecxx . . $ MelderRealRange# yrange = NUMextrema_ucxx . . $ NUMextrema_u(453fd68922d5429d). (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 138 | if (isundefcxx . . $ isundef(dfa1b40f738f9ef2). (yrange)) |
| 139 | return; |
| 140 | const double tmp = 0.5 * yrange.isEmptycxx . . $ MelderRealRange#isEmpty(50ce9a9e25b4a850).(); |
| 141 | ymin = yrange.mincxx . . $ MelderRealRange#min. - tmp; |
| 142 | ymax = yrange.maxcxx . . $ MelderRealRange#max. + tmp; |
| 143 | } |
| 144 | |
| 145 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (graphics); |
| 146 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (graphics, xmin, xmax, ymin, ymax); |
| 147 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (graphics, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 148 | |
| 149 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 150 | SimpleStringcxx . . $ SimpleString# category = thycxx . . $ `melder/melder.h:45:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 151 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (graphics, mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], category -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 152 | } |
| 153 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (graphics); |
| 154 | if (garnish) { |
| 155 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (graphics); |
| 156 | Graphics_marksLeftcxx . . $ Graphics_marksLeft(c3a11a8a55b243ff). (graphics, 2, true, true, false); |
| 157 | if (ymin * ymax < 0.0) |
| 158 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (graphics, 0.0, true, true, true, nullptr); |
| 159 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (graphics, 2, true, true, false); |
| 160 | if (xmin * xmax < 0.0) |
| 161 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (graphics, 0.0, true, true, true, nullptr); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void Polygon_drawMarkscxx . . $ Polygon_drawMarks(b15a615d680d36a0). (Polygoncxx . . $ Polygon# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double size_mm, conststring32cxx . . $ conststring32# mark) { |
| 166 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 167 | if (xmax <= xmin) { /* Autoscaling along x axis. */ |
| 168 | xmax = NUMmax_ucxx . . $ NUMmax_u(4bb9c3e3a8dd5442). (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 169 | xmin = NUMmin_ucxx . . $ NUMmin_u(4bb9c3e3a8dd5442). (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 170 | if (xmin == xmax) { |
| 171 | xmin -= 1.0; |
| 172 | xmax += 1.0; |
| 173 | } |
| 174 | } |
| 175 | if (ymax <= ymin) { /* Autoscaling along y axis. */ |
| 176 | ymax = NUMmax_ucxx . . $ NUMmax_u(4bb9c3e3a8dd5442). (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 177 | ymin = NUMmin_ucxx . . $ NUMmin_u(4bb9c3e3a8dd5442). (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 178 | if (ymin == ymax) { |
| 179 | ymin -= 1.0; |
| 180 | ymax += 1.0; |
| 181 | } |
| 182 | } |
| 183 | if (isundefcxx . . $ isundef(f8197d536af80c96). (xmin) || isundefcxx . . $ isundef(f8197d536af80c96). (xmax) || isundefcxx . . $ isundef(f8197d536af80c96). (ymin) || isundefcxx . . $ isundef(f8197d536af80c96). (ymax)) |
| 184 | return; |
| 185 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 186 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) |
| 187 | Graphics_markcxx . . $ Graphics_mark(406417efd31feba3). (g, mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], size_mm, mark); |
| 188 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 189 | } |
| 190 | |
| 191 | #define CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`!(y,ymin,ymax) (clip ? ((y) > (ymax) ? (ymax) : (y) < (ymin) ? (ymin) : (y)) : y) |
| 192 | |
| 193 | autoPolygoncxx . . $ autoPolygon# Sound_to_Polygoncxx . . $ Sound_to_Polygon(d49c6384878752b8). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channel, double tmin, double tmax, double ymin, double ymax, double level) { |
| 194 | try { |
| 195 | const bool clip = ymin < ymax; |
| 196 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (channel > 0 && channel <= mycxx . . $ `melder/melder.h:44:9`! ny, |
| 197 | U"Channel does not exist."); |
| 198 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 199 | if (tmin < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 200 | tmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 201 | if (tmax > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 202 | tmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 203 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (tmin < mycxx . . $ `melder/melder.h:44:9`! xmax && tmax > mycxx . . $ `melder/melder.h:44:9`! xmin, |
| 204 | U"Invalid domain."); |
| 205 | |
| 206 | const integercxx . . $ integer# i1 = Sampled_xToHighIndexcxx . . $ Sampled_xToHighIndex(405c2491bc3636e9). (me, tmin); |
| 207 | const integercxx . . $ integer# i2 = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, tmax); |
| 208 | const integercxx . . $ integer# numberOfPoints = i2 - i1 + 1 + 2 + 2; // begin + endpoint + level |
| 209 | autoPolygoncxx . . $ autoPolygon# him = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (numberOfPoints); |
| 210 | |
| 211 | /* |
| 212 | In Vector_getValueAtX the interpolation only returns defined values between the |
| 213 | left and right edges that are calculated as |
| 214 | left = x1 - 0.5 * dx; right = left + my nx * dx. |
| 215 | Given a sound, for example on the domain [0,...], the value of 'left' with the above formula might |
| 216 | not return exactly xmin but instead a very small deviation (due to the imprecise |
| 217 | representation of real numbers in a computer). |
| 218 | Querying for the value at xmin which is outside the interpolation domain then produces an 'undefined'. |
| 219 | We try to avoid this with the following workaround. |
| 220 | */ |
| 221 | const volatile double xmin = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 222 | const volatile double xmax = xmin + mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; // don't change this to e.g. my x1 + (my nx - 0.5) * my dx; see Vector_getValueAtX() |
| 223 | Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (xmin, & tmin); |
| 224 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& tmax, xmax); |
| 225 | // End of workaround |
| 226 | integercxx . . $ integer# k = 1; |
| 227 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmin; |
| 228 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (level, ymin, ymax); |
| 229 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmin; |
| 230 | double y = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (me, tmin, channel, kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR.); |
| 231 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (y, ymin, ymax); |
| 232 | for (integercxx . . $ integer# i = i1; i <= i2; i ++) { |
| 233 | y = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 234 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 235 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (y, ymin, ymax); |
| 236 | } |
| 237 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmax; |
| 238 | y = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (me, tmax, channel, kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR.); |
| 239 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (y, ymin, ymax); |
| 240 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmax; |
| 241 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (level, ymin, ymax); |
| 242 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 243 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 244 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U":no Polygon created."); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /* Area inbetween */ |
| 249 | |
| 250 | autoPolygoncxx . . $ autoPolygon# Sounds_to_Polygon_enclosedcxx . . $ Sounds_to_Polygon_enclosed(e8f555567ffc235c). (Soundcxx . . $ Sound# me, Soundcxx . . $ Sound# thee, integercxx . . $ integer# channel, double tmin, double tmax, double ymin, double ymax) { |
| 251 | try { |
| 252 | const bool clip = ymin < ymax; |
| 253 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (channel > 0 && channel <= mycxx . . $ `melder/melder.h:44:9`! ny && channel <= thycxx . . $ `melder/melder.h:45:9`! ny, |
| 254 | U"Invalid channel."); |
| 255 | |
| 256 | // find overlap in the domains with xmin workaround as in Sound_to_Polygon |
| 257 | const double xmin1 = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., xmin2 = thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. - 0.5 * thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.; |
| 258 | const double xmin = ( mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. > thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. ? xmin1 : xmin2 ); |
| 259 | const double xmax = ( mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. < thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. ? xmin1 + mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. : xmin2 + thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx. * thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx. ); |
| 260 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (xmax > xmin, |
| 261 | U"Domains should overlap."); |
| 262 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (xmin < xmax, |
| 263 | U"Domains should overlap."); |
| 264 | if (tmin >= tmax) { |
| 265 | tmin = xmin; |
| 266 | tmax = xmax; |
| 267 | } |
| 268 | if (tmin < xmin) |
| 269 | tmin = xmin; |
| 270 | if (tmax > xmax) |
| 271 | tmax = xmax; |
| 272 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (tmin < xmax && tmax > xmin, |
| 273 | U"Invalid domain."); |
| 274 | |
| 275 | const integercxx . . $ integer# ib1 = Sampled_xToHighIndexcxx . . $ Sampled_xToHighIndex(405c2491bc3636e9). (me, tmin); |
| 276 | const integercxx . . $ integer# ie1 = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, tmax); |
| 277 | const integercxx . . $ integer# n1 = ie1 - ib1 + 1; |
| 278 | const integercxx . . $ integer# ib2 = Sampled_xToHighIndexcxx . . $ Sampled_xToHighIndex(405c2491bc3636e9). (thee, tmin); |
| 279 | const integercxx . . $ integer# ie2 = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (thee, tmax); |
| 280 | const integercxx . . $ integer# n2 = ie2 - ib2 + 1; |
| 281 | const integercxx . . $ integer# numberOfPoints = n1 + n2 + 4; // me + thee + begin + endpoint + closing |
| 282 | |
| 283 | autoPolygoncxx . . $ autoPolygon# him = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (numberOfPoints); |
| 284 | /* |
| 285 | my starting point at tmin |
| 286 | */ |
| 287 | double y = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (me, tmin, ( mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel ), kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR.); |
| 288 | integercxx . . $ integer# k = 1; |
| 289 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmin; |
| 290 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (y, ymin, ymax); |
| 291 | |
| 292 | // my samples |
| 293 | |
| 294 | for (integercxx . . $ integer# i = ib1; i <= ie1; i ++) { |
| 295 | double t = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 296 | y = ( mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] ); |
| 297 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = t; |
| 298 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (y, ymin, ymax); |
| 299 | } |
| 300 | |
| 301 | // my end point at tmax |
| 302 | |
| 303 | y = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (me, tmax, ( mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel ), kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR.); |
| 304 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmax; |
| 305 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = y; |
| 306 | |
| 307 | // thy starting point at tmax |
| 308 | |
| 309 | y = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (thee, tmax, ( thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel ), kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR.); |
| 310 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmax; |
| 311 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = y; |
| 312 | |
| 313 | // thy samples |
| 314 | |
| 315 | for (integercxx . . $ integer# i = ie2; i >= ib2; i--) { |
| 316 | double t = thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. + (i - 1) * thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.; |
| 317 | y = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).( thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel )] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 318 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = t; |
| 319 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k ++] = CLIP_Ycxx . . $ `dwtools/Polygon_extensions.cpp:191:9`! (y, ymin, ymax); |
| 320 | } |
| 321 | |
| 322 | // thy end point at tmin |
| 323 | |
| 324 | y = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (thee, tmin, ( thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel ), kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR.); |
| 325 | hiscxx . . $ `melder/melder.h:47:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = tmin; |
| 326 | hiscxx . . $ `melder/melder.h:47:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).k] = y; |
| 327 | |
| 328 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (k == numberOfPoints); |
| 329 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 330 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 331 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no enclosed Polygon created."); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | #define INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`! 0 |
| 336 | #define INTERSECTION_PROPERcxx . . $ `dwtools/Polygon_extensions.cpp:336:9`! 1 |
| 337 | #define INTERSECTION_AT_EDGEcxx . . $ `dwtools/Polygon_extensions.cpp:337:9`! 2 |
| 338 | #define INTERSECTION_AT_VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:338:9`! 3 |
| 339 | #define INTERSECTION_COPLANARcxx . . $ `dwtools/Polygon_extensions.cpp:339:9`! 4 |
| 340 | #define INTERSECTION_COPLANAR_AT_EDGEcxx . . $ `dwtools/Polygon_extensions.cpp:340:9`! 6 |
| 341 | #define INTERSECTION_COPLANAR_AT_VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:341:9`! 7 |
| 342 | |
| 343 | // 12 is from subject 34 from clipping |
| 344 | static int get_collinearIntersectionPointcxx . . $ get_collinearIntersectionPoint(6fa3ed935acd336a). (double x1, double x2, double x3, double x4, double *xs) { |
| 345 | bool p3inb12 = (x1 < x3 and x3 <= x2) or (x1 > x3 and x3 >= x2); |
| 346 | bool p4inb12 = (x1 < x4 and x4 <= x2) or (x1 > x4 and x4 >= x2); |
| 347 | int intersection = INTERSECTION_AT_VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:338:9`!; |
| 348 | if (x1 < x2) { |
| 349 | if (x3 < x4) { |
| 350 | if (x2 < x3 || x4 < x1) { |
| 351 | intersection = INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 352 | } else if (p3inb12) { |
| 353 | // 4 can be inside or outside |
| 354 | *xs = ( p4inb12 ? x4 : x2 ); |
| 355 | } else if (p4inb12) { |
| 356 | // 3 is outside |
| 357 | *xs = x4; |
| 358 | } else { |
| 359 | // 3 and 4 outside 12 segment |
| 360 | *xs = x2; |
| 361 | intersection = INTERSECTION_AT_EDGEcxx . . $ `dwtools/Polygon_extensions.cpp:337:9`!; |
| 362 | } |
| 363 | } else { |
| 364 | // x4 < x3 |
| 365 | if (x2 < x4 || x3 < x1) { |
| 366 | intersection = INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 367 | } else if (p3inb12) { |
| 368 | // 4 can be inside or outside |
| 369 | *xs = x4; |
| 370 | } else if (p4inb12) { |
| 371 | // 3 outside |
| 372 | *xs = x4; |
| 373 | } else { |
| 374 | *xs = x2; |
| 375 | intersection = INTERSECTION_AT_EDGEcxx . . $ `dwtools/Polygon_extensions.cpp:337:9`!; |
| 376 | } |
| 377 | } |
| 378 | } else { |
| 379 | // x2 < x1 |
| 380 | if (x3 < x4) { |
| 381 | if (x1 < x3 || x4 < x2) { |
| 382 | intersection = INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 383 | } else if (p3inb12) { |
| 384 | *xs = ( p4inb12 ? x4 : x3 ); |
| 385 | } else if (p4inb12) { |
| 386 | // 3 outside |
| 387 | *xs = x4; |
| 388 | } else { |
| 389 | *xs = x2; |
| 390 | intersection = INTERSECTION_AT_EDGEcxx . . $ `dwtools/Polygon_extensions.cpp:337:9`!; |
| 391 | } |
| 392 | } else { |
| 393 | // x4 < x3 |
| 394 | if (x1 < x4 || x3 < x2) { |
| 395 | intersection = INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 396 | } else if (p3inb12) { |
| 397 | *xs = x3; |
| 398 | } else if (p4inb12) { |
| 399 | *xs = x4; |
| 400 | } else { |
| 401 | *xs = x3; |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | return intersection; |
| 406 | } |
| 407 | |
| 408 | // Line from a to b : |
| 409 | // (1) ab = (1-s)*a+s*b = a + s*(b-a) = a + s * b' |
| 410 | // (2) cd = c+t*(d-c) = c + t * d' |
| 411 | // where b' = b - a and d' = d - c. |
| 412 | // at intersection: |
| 413 | // (3) a + s * b' = c + t * d' |
| 414 | // Cross (3) with d'; |
| 415 | // cross (a, d') + s * cross (b', d') = cross (c, d') |
| 416 | // s = cross (c - a, d') / cross (b', d') |
| 417 | // Cross (3) with b' |
| 418 | // cross (a, b') = cross (c, b') + t * cross (d', b') |
| 419 | // t = cross (c - a, b') / cross (b', d') |
| 420 | // if cross (b', b') then b' and d' are parallel |
| 421 | // After Paul Rourke |
| 422 | // Area of triangle a,b,c = ((bx-ax)(cy-ay) - (cx-ax)(by-ay)) / 2 |
| 423 | #define POScxx . . $ `dwtools/Polygon_extensions.cpp:423:9`!(ax,ay,bx,by,cx,cy) (bx - ax) * (cy - ay) - (cx - ax) * (by-ay); |
| 424 | // if POS(a,b,c) (> 0 ; <0, 0) then c is on (the left of; the right of; collinear with) the line segment (a,b) |
| 425 | |
| 426 | // Register the crossing of line a(1)b(2) with c(3)d(4), if the crossing is degenerate only register the tip. |
| 427 | static int LineSegments_getIntersectioncxx . . $ LineSegments_getIntersection(40ed0125601b3f11). (double x1, double y1, double x2, double y2, double x3, double y3, |
| 428 | double x4, double y4, double *mua, double *mub, double eps) { |
| 429 | // bounding box pre-selection |
| 430 | double min12 = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (x1, x2); |
| 431 | double max12 = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (x1, x2); |
| 432 | double min34 = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (x3, x4); |
| 433 | double max34 = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (x3, x4); |
| 434 | if (max12 - min34 < -eps or max34 - min12 < -eps) { |
| 435 | return INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; // eps? |
| 436 | } |
| 437 | min12 = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (y1, y2); |
| 438 | max12 = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (y1, y2); |
| 439 | min34 = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (y3, y4); |
| 440 | max34 = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (y3, y4); |
| 441 | if (max12 - min34 < -eps or max34 - min12 < -eps) { |
| 442 | return INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 443 | } |
| 444 | |
| 445 | double cad = (x3 - x1) * (y4 - y3) - (y3 - y1) * (x4 - x3); // cross (c - a, d') |
| 446 | double cab = (x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1); // cross (c - a, b') |
| 447 | double bd = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3); // cross (b', d') |
| 448 | |
| 449 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (bd) > eps) { |
| 450 | *mua = cad / bd; |
| 451 | *mub = cab / bd; |
| 452 | if (*mua <= eps || *mua > 1.0 + eps || *mub < eps || *mub > 1.0 + eps) |
| 453 | return INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 454 | if (*mua > eps && *mua <= 1.0 - eps && *mub >= eps && *mub < 1.0 - eps) { |
| 455 | // This occurs most of the cases (hopefully) |
| 456 | return INTERSECTION_PROPERcxx . . $ `dwtools/Polygon_extensions.cpp:336:9`!; |
| 457 | } |
| 458 | // Now eps < mua,mub <= 1+eps |
| 459 | // and at least one of the mu's is near 1, |
| 460 | // the other is in [eps,1] |
| 461 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (*mua - 1.0) < eps) |
| 462 | *mua = 1.0; |
| 463 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (*mub - 1.0) < eps) |
| 464 | *mub = 1.0; |
| 465 | // is the intersection at an edge or at vertex |
| 466 | if (*mua == 1.0) // end of ab touches cd |
| 467 | return ( *mub == 1.0 ? INTERSECTION_AT_VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:338:9`! : INTERSECTION_AT_EDGEcxx . . $ `dwtools/Polygon_extensions.cpp:337:9`! ); |
| 468 | else // ab crosses a vertex |
| 469 | return INTERSECTION_AT_VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:338:9`!; |
| 470 | } else { // ab and cd are parallel or coplanar |
| 471 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (cad) > eps and fabscxx . . $ fabs(fee4f1d22bc8e617). (cab) > eps) |
| 472 | return INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!; |
| 473 | if (x1 == x2) { |
| 474 | x1 = y1; |
| 475 | x2 = y2; |
| 476 | x3 = y3; |
| 477 | x4 = y4; |
| 478 | } |
| 479 | double xs; |
| 480 | int intersection = get_collinearIntersectionPointcxx . . $ get_collinearIntersectionPoint(6fa3ed935acd336a). (x1, x2, x3, x4, &xs); |
| 481 | if (intersection != INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!) { |
| 482 | *mua = fabscxx . . $ fabs(fee4f1d22bc8e617). ((xs - x1) / (x2 - x1)); |
| 483 | *mub = fabscxx . . $ fabs(fee4f1d22bc8e617). ((xs - x3) / (x4 - x3)); |
| 484 | intersection += INTERSECTION_COPLANARcxx . . $ `dwtools/Polygon_extensions.cpp:339:9`!; |
| 485 | } |
| 486 | return intersection; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | // Vertices: |
| 491 | // first node has prev = 0, last node has next = 0; |
| 492 | // entry marks the entrance of the OTHER polygon |
| 493 | |
| 494 | Thing_definecxx . . $ `sys/Thing.h:60:9`! (Vertex, Daata) { |
| 495 | double xcxx . . $ structVertex#x., ycxx . . $ structVertex#y., alphacxx . . $ structVertex#alpha.; |
| 496 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# neighbourcxx . . $ structVertex#neighbour.; |
| 497 | integercxx . . $ integer# poly_npointscxx . . $ structVertex#poly_npoints., idcxx . . $ structVertex#id.; |
| 498 | int intersectcxx . . $ structVertex#intersect., entrycxx . . $ structVertex#entry.; |
| 499 | bool processedcxx . . $ structVertex#processed.; |
| 500 | |
| 501 | void v1_copycxx . . $ structVertex#v1_copy(42659c2335f2eda7). (Daatacxx . . $ Daata# data_to) const |
| 502 | override; |
| 503 | }; |
| 504 | |
| 505 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Vertex, Daata, 0); |
| 506 | |
| 507 | void structVertexcxx . . $ structVertex# :: v1_copycxx . . $ structVertex#v1_copy(42659c2335f2eda7). (Daatacxx . . $ Daata# thee_Daata) const { |
| 508 | Vertexcxx . . $ Vertex# thee = static_cast <Vertexcxx . . $ Vertex#> (thee_Daata); |
| 509 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structVertex#x. = ourcxx . . $ `melder/melder.h:42:9`! xcxx . . $ structVertex#x.; |
| 510 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structVertex#y. = ourcxx . . $ `melder/melder.h:42:9`! ycxx . . $ structVertex#y.; |
| 511 | thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structVertex#alpha. = ourcxx . . $ `melder/melder.h:42:9`! alphacxx . . $ structVertex#alpha.; |
| 512 | thycxx . . $ `melder/melder.h:45:9`! neighbourcxx . . $ structVertex#neighbour. = ourcxx . . $ `melder/melder.h:42:9`! neighbourcxx . . $ structVertex#neighbour.; |
| 513 | thycxx . . $ `melder/melder.h:45:9`! poly_npointscxx . . $ structVertex#poly_npoints. = ourcxx . . $ `melder/melder.h:42:9`! poly_npointscxx . . $ structVertex#poly_npoints.; |
| 514 | thycxx . . $ `melder/melder.h:45:9`! idcxx . . $ structVertex#id. = ourcxx . . $ `melder/melder.h:42:9`! idcxx . . $ structVertex#id.; |
| 515 | thycxx . . $ `melder/melder.h:45:9`! intersectcxx . . $ structVertex#intersect. = ourcxx . . $ `melder/melder.h:42:9`! intersectcxx . . $ structVertex#intersect.; |
| 516 | thycxx . . $ `melder/melder.h:45:9`! entrycxx . . $ structVertex#entry. = ourcxx . . $ `melder/melder.h:42:9`! entrycxx . . $ structVertex#entry.; |
| 517 | thycxx . . $ `melder/melder.h:45:9`! processedcxx . . $ structVertex#processed. = ourcxx . . $ `melder/melder.h:42:9`! processedcxx . . $ structVertex#processed.; |
| 518 | } |
| 519 | |
| 520 | static autoVertexcxx . . $ autoVertex# Vertex_createcxx . . $ Vertex_create(7aeb32f69b730a98). () { |
| 521 | return Thing_newcxx . . $ `sys/Thing.h:514:9`! (Vertex); |
| 522 | } |
| 523 | |
| 524 | Thing_definecxx . . $ `sys/Thing.h:60:9`! (Vertices, DoublyLinkedList) { |
| 525 | static int s_compareHookcxx . . $ structVertices#s_compareHook(10e1f21cd55c34dc). (DoublyLinkedNodecxx . . $ DoublyLinkedNode# me, DoublyLinkedNodecxx . . $ DoublyLinkedNode# thee) noexcept; |
| 526 | Data_CompareHookcxx . . $ Data_CompareHook# v_getCompareHookcxx . . $ structVertices#v_getCompareHook(595dba4c91681740). () |
| 527 | override { return s_compareHookcxx . . $ MelderCompareHook#MelderCompareHook(51152207c55e0314).; } |
| 528 | }; |
| 529 | |
| 530 | inline static autoVerticescxx . . $ autoVertices# Vertices_createcxx . . $ Vertices_create(f6d1e97d1c59e963). () { |
| 531 | return Thing_newcxx . . $ `sys/Thing.h:514:9`! (Vertices); |
| 532 | } |
| 533 | |
| 534 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Vertices, DoublyLinkedList, 0); |
| 535 | |
| 536 | #define VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`!(n) ((Vertex) ((n) -> data.get())) |
| 537 | |
| 538 | int structVerticescxx . . $ structVertices# :: s_compareHookcxx . . $ structVertices#s_compareHook(10e1f21cd55c34dc). (DoublyLinkedNodecxx . . $ DoublyLinkedNode# me, DoublyLinkedNodecxx . . $ DoublyLinkedNode# thee) noexcept { |
| 539 | return ( VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (me) -> alphacxx . . $ structVertex#alpha. < VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (thee) -> alphacxx . . $ structVertex#alpha. ? -1 : ( VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (me) -> alphacxx . . $ structVertex#alpha. > VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (thee) -> alphacxx . . $ structVertex#alpha. ? 1 : 0 ) ); |
| 540 | } |
| 541 | |
| 542 | static void Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (Verticescxx . . $ Vertices# me, DoublyLinkedNodecxx . . $ DoublyLinkedNode# n) { |
| 543 | try { |
| 544 | autoDoublyLinkedNodecxx . . $ autoDoublyLinkedNode# nc = Data_copycxx . . $ Data_copy(97a542a26794c80e). (n); |
| 545 | DoublyLinkedList_addBackcxx . . $ DoublyLinkedList_addBack(a2c897d9bfcc8e6a). (me, nc.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).()); |
| 546 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 547 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no copy added."); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static bool pointsInsideIntervalcxx . . $ pointsInsideInterval(1a12eba28d1263a1). (double *x, integercxx . . $ integer# n, integercxx . . $ integer# istart, integercxx . . $ integer# iend, integercxx . . $ integer# *jstart, integercxx . . $ integer# *jend) { |
| 552 | double xmax = x [istart], xmin = x [istart]; |
| 553 | integercxx . . $ integer# imax = istart, imin = istart; |
| 554 | integercxx . . $ integer# iendmod = ( iend > istart ? iend : iend + n ); // circular |
| 555 | for (integercxx . . $ integer# i = istart + 1; i <= iendmod; i ++) { |
| 556 | integercxx . . $ integer# index = (i - 1) % n + 1; // make it circular |
| 557 | if (x [index] > xmax) { |
| 558 | xmax = x [index]; |
| 559 | imax = index; |
| 560 | } else if (x [index] < xmin) { |
| 561 | xmin = x [index]; |
| 562 | imin = index; |
| 563 | } |
| 564 | } |
| 565 | *jstart = imin; |
| 566 | *jend = imax; |
| 567 | if (x [istart] > x [iend]) { |
| 568 | *jstart = imax; |
| 569 | *jend = imin; |
| 570 | } |
| 571 | if (x [istart] == x [*jstart] and x [iend] == x [*jend]) { // if there are duplicates of the extrema |
| 572 | *jstart = istart; |
| 573 | *jend = iend; |
| 574 | } |
| 575 | return *jstart == istart and * jend == iend; |
| 576 | } |
| 577 | |
| 578 | autoPolygoncxx . . $ autoPolygon# Polygon_circularPermutationcxx . . $ Polygon_circularPermutation(5f594b76660cfd5). (Polygoncxx . . $ Polygon# me, integercxx . . $ integer# nshift) { |
| 579 | try { |
| 580 | autoPolygoncxx . . $ autoPolygon# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 581 | if (nshift != 0) { |
| 582 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 583 | integercxx . . $ integer# inew = (i + nshift - 1) % mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. + 1; |
| 584 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inew] = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 585 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inew] = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 586 | } |
| 587 | } |
| 588 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 589 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 590 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not circularly permuted."); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | static void _Polygons_copyNonCollinearitiescxx . . $ _Polygons_copyNonCollinearities(c7083c13408f9024). (Polygoncxx . . $ Polygon# me, Polygoncxx . . $ Polygon# thee, integercxx . . $ integer# collstart, integercxx . . $ integer# collend) { |
| 595 | // Determine if all collinear point are within the interval [colstart,colend] |
| 596 | integercxx . . $ integer# jstart, jend; |
| 597 | bool allPointsInside = ( mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).collstart] != mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).collend] ? |
| 598 | pointsInsideIntervalcxx . . $ pointsInsideInterval(1a12eba28d1263a1). (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x..asArgumentToFunctionThatExpectsOneBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsOneBasedArray(5a2a78a048fb49a8).(), |
| 599 | mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints., collstart, collend, &jstart, &jend) : |
| 600 | pointsInsideIntervalcxx . . $ pointsInsideInterval(1a12eba28d1263a1). (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y..asArgumentToFunctionThatExpectsOneBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsOneBasedArray(5a2a78a048fb49a8).(), |
| 601 | mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints., collstart, collend, &jstart, &jend) ); |
| 602 | if (not allPointsInside) { |
| 603 | if (collstart != jstart) { // also include the extreme point at start |
| 604 | thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. ++; |
| 605 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.] = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jstart]; |
| 606 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.] = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jstart]; |
| 607 | } |
| 608 | if (collend != jend) { // also include the extreme point at end |
| 609 | thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. ++; |
| 610 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.] = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jend]; |
| 611 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.] = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jend]; |
| 612 | } |
| 613 | } |
| 614 | thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. ++; |
| 615 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.] = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).collend]; thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.] = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).collend]; |
| 616 | } |
| 617 | |
| 618 | #define AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`!(x1,y1,x2,y2,x3,y3) (x1*(y2 - y3)+x2*(y3-y1)+x3*(y1-y2)) |
| 619 | autoPolygoncxx . . $ autoPolygon# Polygon_simplifycxx . . $ Polygon_simplify(18f02ed335786f5e). (Polygoncxx . . $ Polygon# me) { |
| 620 | try { |
| 621 | autoPolygoncxx . . $ autoPolygon# p1 = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 622 | |
| 623 | // pass 1: remove doublets |
| 624 | integercxx . . $ integer# np = 1; |
| 625 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 626 | if (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] != p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).np] || mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] != p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).np]) { |
| 627 | p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1). ++ np] = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 628 | p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).np] = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 629 | } |
| 630 | } |
| 631 | // last and first points! |
| 632 | if (p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).np] == p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] && p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).np] == p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]) { |
| 633 | np --; |
| 634 | } |
| 635 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (np > 2, U"Not enough points left after doublet removal."); |
| 636 | |
| 637 | p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints. = np; |
| 638 | |
| 639 | // pass 2: remove collinearities |
| 640 | |
| 641 | autoPolygoncxx . . $ autoPolygon# p = Data_copycxx . . $ Data_copy(97a542a26794c80e). (p1.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 642 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints. = 0; |
| 643 | // is there collinearity between the first and the last points of p1? |
| 644 | double eps = 1e-15; |
| 645 | double area = AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`! (p1 -> x [np], p1 -> y [np], p1 -> x [1], p1 -> y [1], p1 -> x [2], p1 -> y [2]); |
| 646 | integercxx . . $ integer# collend = 2; |
| 647 | while (fabscxx . . $ fabs(fee4f1d22bc8e617). (area) < eps && collend < np) { |
| 648 | collend ++; |
| 649 | area = AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`! (p1 -> x [collend - 2], p1 -> y [collend - 2], p1 -> x [collend - 1], p1 -> y [collend - 1], p1 -> x [collend], p1 -> y [collend]); |
| 650 | } |
| 651 | collend--; |
| 652 | area = AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`! (p1 -> x [np - 1], p1 -> y [np - 1], p1 -> x [np], p1 -> y [np], p1 -> x [1], p1 -> y [1]); |
| 653 | integercxx . . $ integer# collstart = np - 1; |
| 654 | while (fabscxx . . $ fabs(fee4f1d22bc8e617). (area) < eps && collstart > collend) { |
| 655 | collstart --; |
| 656 | area = AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`! (p1 -> x [collstart], p1 -> y [collstart], p1 -> x [collstart + 1], p1 -> y [collstart + 1], p1 -> x [collstart + 2], p1 -> y [collstart + 2]); |
| 657 | } |
| 658 | collstart ++; |
| 659 | if (collend - collstart + p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints. > 1) { |
| 660 | _Polygons_copyNonCollinearitiescxx . . $ _Polygons_copyNonCollinearities(c7083c13408f9024). (p1.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), p.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), collstart, collend); |
| 661 | } else { |
| 662 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints. = 1; |
| 663 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 664 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 665 | } |
| 666 | bool collinearity = false; |
| 667 | integercxx . . $ integer# endpos = collstart - 1; |
| 668 | for (integercxx . . $ integer# i = collend + 1; i <= endpos; i ++) { // start was < numberOfPoints |
| 669 | // if i-1, i, i+1 are coplanar, remove i |
| 670 | // area = x1*(y2 - y3)+x2*(y3-y1)+x3*(y1-y2) |
| 671 | area = AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`! (p1 -> x [i - 1], p1 -> y [i - 1], p1 -> x [i], p1 -> y [i], p1 -> x [i + 1], p1 -> y [i + 1]); |
| 672 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (area) < eps) { |
| 673 | if (collinearity) { |
| 674 | collend = i + 1; |
| 675 | } else { // start of possibly new series |
| 676 | collinearity = true; |
| 677 | collstart = i - 1; collend = i + 1; |
| 678 | } |
| 679 | if (i != endpos) { |
| 680 | continue; |
| 681 | } |
| 682 | } |
| 683 | if (! collinearity) { |
| 684 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints. ++; |
| 685 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints.] = p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 686 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints.] = p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 687 | } else { // end of series of collinearities detected |
| 688 | _Polygons_copyNonCollinearitiescxx . . $ _Polygons_copyNonCollinearities(c7083c13408f9024). (p1.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), p.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), collstart, collend); |
| 689 | collinearity = false; |
| 690 | } |
| 691 | } |
| 692 | if (not collinearity and collend != endpos + 1) { // only if previous series was not collinear |
| 693 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints. ++; |
| 694 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints.] = p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).endpos + 1]; |
| 695 | p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).p ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfPointscxx . . $ structPolygon#numberOfPoints.] = p1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).endpos + 1]; |
| 696 | } |
| 697 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (p -> numberOfPoints > 2, U"Not enough points left after collinear points removal."); |
| 698 | |
| 699 | autoPolygoncxx . . $ autoPolygon# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (p.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); // |
| 700 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 701 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 702 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not simplified."); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | #undef AREAcxx . . $ `dwtools/Polygon_extensions.cpp:618:9`! |
| 707 | |
| 708 | static autoVerticescxx . . $ autoVertices# Polygon_to_Verticescxx . . $ Polygon_to_Vertices(b23f1ad3a531eda). (Polygoncxx . . $ Polygon# me, bool close) { |
| 709 | try { |
| 710 | autoVerticescxx . . $ autoVertices# thee = Vertices_createcxx . . $ Vertices_create(f6d1e97d1c59e963). (); |
| 711 | for (integercxx . . $ integer# i = 1 ; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 712 | autoVertexcxx . . $ autoVertex# v = Vertex_createcxx . . $ Vertex_create(7aeb32f69b730a98). (); |
| 713 | v ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structVertex#x. = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; v ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structVertex#y. = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 714 | autoDoublyLinkedNodecxx . . $ autoDoublyLinkedNode# n = DoublyLinkedNode_createcxx . . $ DoublyLinkedNode_create(d0f338d5367a7b54). (vcxx . . $ autoSomeThing#autoSomeThing(327dc2ad7b4df21)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 715 | DoublyLinkedList_addBackcxx . . $ DoublyLinkedList_addBack(a2c897d9bfcc8e6a). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), n.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).()); |
| 716 | } |
| 717 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (thycxx . . $ `melder/melder.h:45:9`! numberOfNodes == mycxx . . $ `melder/melder.h:44:9`! numberOfPoints); |
| 718 | if (close) { |
| 719 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), thycxx . . $ `melder/melder.h:45:9`! frontcxx . . $ structDoublyLinkedList#front.); |
| 720 | } |
| 721 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 722 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 723 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Vertices created."); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | #define SKIP_INTERSECTION_NODEScxx . . $ `dwtools/Polygon_extensions.cpp:727:9`!(n) while(VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`!(n) -> intersect != 0) n = n -> next; |
| 728 | |
| 729 | |
| 730 | static void Vertices_printcxx . . $ Vertices_print(ca2dea659c0d3720). (Verticescxx . . $ Vertices# me, Verticescxx . . $ Vertices# thee) { |
| 731 | integercxx . . $ integer# ns = 0, nc = 0, nt, nt2; |
| 732 | // MelderInfo_open(); |
| 733 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# n = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; |
| 734 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 735 | while (n != 0) { |
| 736 | double x = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> xcxx . . $ structVertex#x., y = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> ycxx . . $ structVertex#y., alpha = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> alphacxx . . $ structVertex#alpha.; |
| 737 | conststring32cxx . . $ conststring32# type, itype; |
| 738 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 739 | type = U"S"; |
| 740 | ns ++; |
| 741 | nt = ns; |
| 742 | itype = U"-"; |
| 743 | nt2 = 0; |
| 744 | } else { |
| 745 | type = U"I"; |
| 746 | nt = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> idcxx . . $ structVertex#id.; |
| 747 | nt2 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> neighbour) -> idcxx . . $ structVertex#id.; |
| 748 | itype = Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> intersectcxx . . $ structVertex#intersect.); |
| 749 | } |
| 750 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (type, nt, U" I", itype, U", (", x, U", ", y, U"), "); |
| 751 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (alpha, U", E", VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> entrycxx . . $ structVertex#entry., U"(", nt2, U")\n"); |
| 752 | n = n -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 753 | } |
| 754 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 755 | n = thycxx . . $ `melder/melder.h:45:9`! frontcxx . . $ structDoublyLinkedList#front.; |
| 756 | while (n != 0) { |
| 757 | double x = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> xcxx . . $ structVertex#x., y = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> ycxx . . $ structVertex#y., alpha = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> alphacxx . . $ structVertex#alpha.; |
| 758 | conststring32cxx . . $ conststring32# type, itype; |
| 759 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 760 | type = U"C"; |
| 761 | nc ++; |
| 762 | nt = nc; |
| 763 | itype = U"-"; |
| 764 | nt2 = 0; |
| 765 | } else { |
| 766 | type = U"I"; |
| 767 | nt = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> idcxx . . $ structVertex#id.; |
| 768 | nt2 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> neighbour) -> idcxx . . $ structVertex#id.; |
| 769 | itype = Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> intersectcxx . . $ structVertex#intersect.); |
| 770 | } |
| 771 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (type, nt, U" I", itype, U", (", x, U", ", y, U"), "); |
| 772 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (alpha, U", E", VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> entrycxx . . $ structVertex#entry., U"(", nt2, U")\n"); |
| 773 | n = n -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 774 | } |
| 775 | // MelderInfo_close(); |
| 776 | } |
| 777 | |
| 778 | static void Vertices_sortIntersectionscxx . . $ Vertices_sortIntersections(82474cb899208149). (Verticescxx . . $ Vertices# me) { |
| 779 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# ni = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front., first; |
| 780 | bool intersections = false; |
| 781 | while (ni != mycxx . . $ `melder/melder.h:44:9`! backcxx . . $ structDoublyLinkedList#back.) { |
| 782 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 783 | if (intersections) { // the previous was the last of a series of intersections |
| 784 | DoublyLinkedList_sortPartcxx . . $ DoublyLinkedList_sortPart(df52792679f85443). ( (DoublyLinkedListcxx . . $ DoublyLinkedList#) me, first, ni -> prevcxx . . $ structDoublyLinkedNode#prev.); |
| 785 | // restore myNode pointers |
| 786 | intersections = false; |
| 787 | } |
| 788 | } else { |
| 789 | if (not intersections) { |
| 790 | first = ni; |
| 791 | intersections = true; |
| 792 | } |
| 793 | } |
| 794 | ni = ni -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 795 | } |
| 796 | // we might have missed the last series of intersections |
| 797 | if (intersections) { |
| 798 | DoublyLinkedList_sortPartcxx . . $ DoublyLinkedList_sortPart(df52792679f85443). ( (DoublyLinkedListcxx . . $ DoublyLinkedList#) me, first, ni -> prevcxx . . $ structDoublyLinkedNode#prev.); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | static void Vertices_addIntersectionscxx . . $ Vertices_addIntersections(ca2dea659c0d3720). (Verticescxx . . $ Vertices# me, Verticescxx . . $ Vertices# thee) { |
| 803 | try { |
| 804 | double eps = 1e-15; |
| 805 | integercxx . . $ integer# id = 0; |
| 806 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfNodescxx . . $ structDoublyLinkedList#numberOfNodes. < 4 || thycxx . . $ `melder/melder.h:45:9`! numberOfNodescxx . . $ structDoublyLinkedList#numberOfNodes. < 4) { |
| 807 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"We need at least three vertices."); |
| 808 | } |
| 809 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# ni = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; // the node index in me (s) |
| 810 | while (ni != mycxx . . $ `melder/melder.h:44:9`! backcxx . . $ structDoublyLinkedList#back.) { // until penultimate |
| 811 | double x1 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> xcxx . . $ structVertex#x., y1 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> ycxx . . $ structVertex#y.; |
| 812 | double x2 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni -> next) -> xcxx . . $ structVertex#x., y2 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni -> next) -> ycxx . . $ structVertex#y.; |
| 813 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# nj = thycxx . . $ `melder/melder.h:45:9`! frontcxx . . $ structDoublyLinkedList#front.; // the current node index in thee (c) |
| 814 | while (nj != thycxx . . $ `melder/melder.h:45:9`! backcxx . . $ structDoublyLinkedList#back. && VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (nj) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 815 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# njn = nj -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 816 | SKIP_INTERSECTION_NODEScxx . . $ `dwtools/Polygon_extensions.cpp:727:9`! (njn) |
| 817 | double x3 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (nj) -> xcxx . . $ structVertex#x., y3 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (nj) -> ycxx . . $ structVertex#y.; |
| 818 | double x4 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (njn) -> xcxx . . $ structVertex#x., y4 = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (njn) -> ycxx . . $ structVertex#y., mua, mub; |
| 819 | int intersection = LineSegments_getIntersectioncxx . . $ LineSegments_getIntersection(40ed0125601b3f11). (x1, y1, x2, y2, x3, y3, x4, y4, &mua, &mub, eps); |
| 820 | if (intersection != INTERSECTION_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.cpp:335:9`!) { |
| 821 | id ++; |
| 822 | // 1. create the vertices |
| 823 | autoVertexcxx . . $ autoVertex# ins = Vertex_createcxx . . $ Vertex_create(7aeb32f69b730a98). (); |
| 824 | ins ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xcxx . . $ structVertex#x. = x1 + mua * (x2 - x1); |
| 825 | ins ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structVertex#y. = y1 + mua * (y2 - y1); |
| 826 | ins ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). alphacxx . . $ structVertex#alpha. = mua; |
| 827 | ins ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). intersectcxx . . $ structVertex#intersect. = intersection; |
| 828 | ins ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). idcxx . . $ structVertex#id. = id; |
| 829 | autoVertexcxx . . $ autoVertex# inc = Data_copycxx . . $ Data_copy(97a542a26794c80e). (ins.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 830 | inc ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). alphacxx . . $ structVertex#alpha. = mub; |
| 831 | // 2. create the nodes |
| 832 | autoDoublyLinkedNodecxx . . $ autoDoublyLinkedNode# ns = DoublyLinkedNode_createcxx . . $ DoublyLinkedNode_create(d0f338d5367a7b54). (autoDaatacxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).()); |
| 833 | autoDoublyLinkedNodecxx . . $ autoDoublyLinkedNode# nc = DoublyLinkedNode_createcxx . . $ DoublyLinkedNode_create(d0f338d5367a7b54). (autoDaatacxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).()); |
| 834 | // 3. link the neighbours + copy the links |
| 835 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# njc = ins ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). neighbourcxx . . $ structVertex#neighbour. = nc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); |
| 836 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# nic = inc ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). neighbourcxx . . $ structVertex#neighbour. = ns.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); |
| 837 | // 4. transfer the vertices to the nodes |
| 838 | ns ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDoublyLinkedNode#data. =cxx . . $ autoSomeThing#`operator=`(ed6a1a4da6aedae3). ins.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); |
| 839 | nc ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDoublyLinkedNode#data. =cxx . . $ autoSomeThing#`operator=`(ed6a1a4da6aedae3). inc.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); |
| 840 | // 5. add the nodes to the list |
| 841 | DoublyLinkedList_addAftercxx . . $ DoublyLinkedList_addAfter(df52792679f85443). (me, ni, ns.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).()); |
| 842 | DoublyLinkedList_addAftercxx . . $ DoublyLinkedList_addAfter(df52792679f85443). (thee, nj, nc.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).()); |
| 843 | // 6. set node pointer to inserted nodes |
| 844 | ni = nic; nj = njc; |
| 845 | } |
| 846 | nj = nj -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 847 | SKIP_INTERSECTION_NODEScxx . . $ `dwtools/Polygon_extensions.cpp:727:9`! (nj) |
| 848 | } |
| 849 | ni = ni -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 850 | } |
| 851 | if (Melder_debugcxx . . $ Melder_debug. == -1) { |
| 852 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8).(); |
| 853 | Vertices_printcxx . . $ Vertices_print(ca2dea659c0d3720). (me, thee); |
| 854 | } |
| 855 | Vertices_sortIntersectionscxx . . $ Vertices_sortIntersections(82474cb899208149). (me); |
| 856 | Vertices_sortIntersectionscxx . . $ Vertices_sortIntersections(82474cb899208149). (thee); |
| 857 | if (Melder_debugcxx . . $ Melder_debug. == -1) { |
| 858 | Vertices_printcxx . . $ Vertices_print(ca2dea659c0d3720). (me, thee); |
| 859 | } |
| 860 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 861 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Intersections not calculated."); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | #define Polygon_ENcxx . . $ `dwtools/Polygon_extensions.cpp:865:9`! 1 |
| 866 | #define Polygon_EXcxx . . $ `dwtools/Polygon_extensions.cpp:866:9`! 2 |
| 867 | #define Polygon_ENEXcxx . . $ `dwtools/Polygon_extensions.cpp:867:9`! 3 |
| 868 | #define Polygon_EXENcxx . . $ `dwtools/Polygon_extensions.cpp:868:9`! 4 |
| 869 | |
| 870 | static void Vertices_markEntryPointscxx . . $ Vertices_markEntryPoints(ca7ebdd765aabe84). (Verticescxx . . $ Vertices# me, int firstLocation) { |
| 871 | int entry = ( firstLocation == Polygon_INSIDEcxx . . $ `dwtools/Polygon_extensions.h:32:9`! ? Polygon_EXcxx . . $ `dwtools/Polygon_extensions.cpp:866:9`! : ( firstLocation == Polygon_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.h:33:9`! ? Polygon_ENcxx . . $ `dwtools/Polygon_extensions.cpp:865:9`! : Polygon_ENEXcxx . . $ `dwtools/Polygon_extensions.cpp:867:9`! ) ); // problematic when on boundary |
| 872 | // my back/front can never be an intersection node |
| 873 | for (DoublyLinkedNodecxx . . $ DoublyLinkedNode# ni = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front. -> nextcxx . . $ structDoublyLinkedNode#next.; ni != mycxx . . $ `melder/melder.h:44:9`! backcxx . . $ structDoublyLinkedList#back.; ni = ni -> nextcxx . . $ structDoublyLinkedNode#next.) { |
| 874 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 875 | continue; |
| 876 | } |
| 877 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> entrycxx . . $ structVertex#entry. = entry; |
| 878 | entry = ( entry == Polygon_ENcxx . . $ `dwtools/Polygon_extensions.cpp:865:9`! ? Polygon_EXcxx . . $ `dwtools/Polygon_extensions.cpp:866:9`! : ( entry == Polygon_EXcxx . . $ `dwtools/Polygon_extensions.cpp:866:9`! ? Polygon_ENcxx . . $ `dwtools/Polygon_extensions.cpp:865:9`! : Polygon_ENEXcxx . . $ `dwtools/Polygon_extensions.cpp:867:9`! ) ); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | static autoVerticescxx . . $ autoVertices# Verticeses_connectClippingPathsUnioncxx . . $ Verticeses_connectClippingPathsUnion(a40e66a0c73c758d). (Verticescxx . . $ Vertices# me, Verticescxx . . $ Vertices# thee) { |
| 883 | try { |
| 884 | // find my first vertex outside thee, by searching the first intersection entry |
| 885 | |
| 886 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# firstOutside = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; |
| 887 | bool firstOutsideSet = true; |
| 888 | for (DoublyLinkedNodecxx . . $ DoublyLinkedNode# ni = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; ni != 0; ni = ni -> nextcxx . . $ structDoublyLinkedNode#next.) { |
| 889 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> intersectcxx . . $ structVertex#intersect. == 0) { // |
| 890 | if (firstOutsideSet) { |
| 891 | continue; |
| 892 | } |
| 893 | firstOutside = ni; break; |
| 894 | } else if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> entrycxx . . $ structVertex#entry. == Polygon_ENcxx . . $ `dwtools/Polygon_extensions.cpp:865:9`!) { |
| 895 | break; |
| 896 | } |
| 897 | // We were inside |
| 898 | else { |
| 899 | firstOutsideSet = false; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | autoVerticescxx . . $ autoVertices# him = Vertices_createcxx . . $ Vertices_create(f6d1e97d1c59e963). (); |
| 904 | integercxx . . $ integer# poly_npoints = 0; |
| 905 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# current = firstOutside; |
| 906 | bool inside = false, forward = true; |
| 907 | do { |
| 908 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 909 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; |
| 910 | } else { // intersection point |
| 911 | // store and jump to other polygon |
| 912 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; |
| 913 | current = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> neighbourcxx . . $ structVertex#neighbour.; inside = not inside; |
| 914 | forward = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> entrycxx . . $ structVertex#entry. == Polygon_EXcxx . . $ `dwtools/Polygon_extensions.cpp:866:9`!; |
| 915 | } |
| 916 | if (forward) { |
| 917 | current = current -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 918 | if (current == 0) { |
| 919 | current = inside ? thycxx . . $ `melder/melder.h:45:9`! frontcxx . . $ structDoublyLinkedList#front. : mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; |
| 920 | } |
| 921 | } else { |
| 922 | current = current -> prevcxx . . $ structDoublyLinkedNode#prev.; |
| 923 | if (current == 0) { |
| 924 | current = ( inside ? thycxx . . $ `melder/melder.h:45:9`! backcxx . . $ structDoublyLinkedList#back. : mycxx . . $ `melder/melder.h:44:9`! backcxx . . $ structDoublyLinkedList#back. ); |
| 925 | } |
| 926 | } |
| 927 | } while (current != firstOutside and current != 0 and poly_npoints < mycxx . . $ `melder/melder.h:44:9`! numberOfNodescxx . . $ structDoublyLinkedList#numberOfNodes.); |
| 928 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (hiscxx . . $ `melder/melder.h:47:9`! front) -> poly_npointscxx . . $ structVertex#poly_npoints. = poly_npoints; |
| 929 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 930 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 931 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no clipping path."); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | //Vertices Verticeses_connectClippingPaths (Vertices me, bool use_myinterior, Vertices thee, bool use_thyinterior); |
| 936 | static autoVerticescxx . . $ autoVertices# Verticeses_connectClippingPathscxx . . $ Verticeses_connectClippingPaths(b0c7493c9219ab15). (Verticescxx . . $ Vertices# me, bool /* use_myinterior */, Verticescxx . . $ Vertices# thee, bool /* use_thyinterior */) { |
| 937 | try { |
| 938 | autoVerticescxx . . $ autoVertices# him = Vertices_createcxx . . $ Vertices_create(f6d1e97d1c59e963). (); |
| 939 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# prevPoly = nullptr; |
| 940 | integercxx . . $ integer# poly_npoints = 0; |
| 941 | for (DoublyLinkedNodecxx . . $ DoublyLinkedNode# ni = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; ni != 0; ni = ni -> nextcxx . . $ structDoublyLinkedNode#next.) { |
| 942 | if ( (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> intersectcxx . . $ structVertex#intersect. == 0) || VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (ni) -> processedcxx . . $ structVertex#processed.) { |
| 943 | continue; |
| 944 | } |
| 945 | // Intersection found: start new polygon |
| 946 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# currentPoly = hiscxx . . $ `melder/melder.h:47:9`! backcxx . . $ structDoublyLinkedList#back.; |
| 947 | if (currentPoly == hiscxx . . $ `melder/melder.h:47:9`! frontcxx . . $ structDoublyLinkedList#front.) { |
| 948 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ni); poly_npoints ++; |
| 949 | prevPoly = hiscxx . . $ `melder/melder.h:47:9`! frontcxx . . $ structDoublyLinkedList#front.; |
| 950 | } else { |
| 951 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ni); poly_npoints ++; |
| 952 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (prevPoly) -> poly_npointscxx . . $ structVertex#poly_npoints. = poly_npoints; |
| 953 | poly_npoints = 0; |
| 954 | prevPoly = currentPoly; |
| 955 | } |
| 956 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# current = ni; |
| 957 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> processedcxx . . $ structVertex#processed. = true; |
| 958 | integercxx . . $ integer# jumps = 0; |
| 959 | do { |
| 960 | if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> entrycxx . . $ structVertex#entry. == Polygon_ENcxx . . $ `dwtools/Polygon_extensions.cpp:865:9`!) { |
| 961 | while ( (current = current -> nextcxx . . $ structDoublyLinkedNode#next.) != 0 and VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 962 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; |
| 963 | } |
| 964 | if (current == 0) { // back of list? Goto front |
| 965 | current = ( jumps % 2 == 0 ? mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front. : thycxx . . $ `melder/melder.h:45:9`! frontcxx . . $ structDoublyLinkedList#front. ); |
| 966 | while ( (current = current -> nextcxx . . $ structDoublyLinkedNode#next.) != 0 and VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 967 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; |
| 968 | } |
| 969 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; // intersection point |
| 970 | } else if (current == ni) { |
| 971 | break; // done |
| 972 | } else { |
| 973 | current = current -> prevcxx . . $ structDoublyLinkedNode#prev.; |
| 974 | } |
| 975 | } else if (VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> entrycxx . . $ structVertex#entry. == Polygon_EXcxx . . $ `dwtools/Polygon_extensions.cpp:866:9`!) { |
| 976 | while ( (current = current -> prevcxx . . $ structDoublyLinkedNode#prev.) != 0 and VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 977 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; |
| 978 | } |
| 979 | if (current == 0) { // start of list? Goto end |
| 980 | current = ( jumps % 2 == 0 ? mycxx . . $ `melder/melder.h:44:9`! backcxx . . $ structDoublyLinkedList#back. : thycxx . . $ `melder/melder.h:45:9`! backcxx . . $ structDoublyLinkedList#back. ); |
| 981 | while ( (current = current -> prevcxx . . $ structDoublyLinkedNode#prev.) != 0 and VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> intersectcxx . . $ structVertex#intersect. == 0) { |
| 982 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; |
| 983 | } |
| 984 | Vertices_addCopyBackcxx . . $ Vertices_addCopyBack(25762edbcca978e3). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), current); poly_npoints ++; // intersection point |
| 985 | } else if (current == ni) { |
| 986 | break; // done |
| 987 | } else { |
| 988 | current = current -> nextcxx . . $ structDoublyLinkedNode#next.; |
| 989 | } |
| 990 | } else { |
| 991 | } |
| 992 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> processedcxx . . $ structVertex#processed. = true; |
| 993 | current = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> neighbourcxx . . $ structVertex#neighbour.; jumps ++; |
| 994 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (current) -> processedcxx . . $ structVertex#processed. = true; |
| 995 | } while (current != ni); // polygon closed |
| 996 | } |
| 997 | // last polygon: |
| 998 | VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (prevPoly) -> poly_npointscxx . . $ structVertex#poly_npoints. = poly_npoints; |
| 999 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1000 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1001 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no clipping vertices created."); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | // |
| 1006 | static autoPolygoncxx . . $ autoPolygon# Vertices_to_Polygoncxx . . $ Vertices_to_Polygon(568bdc83f069b2ed). (Verticescxx . . $ Vertices# /* me */, DoublyLinkedNodecxx . . $ DoublyLinkedNode# *ni) { |
| 1007 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# n = *ni; |
| 1008 | try { |
| 1009 | integercxx . . $ integer# i = 1, nPoints = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> poly_npointscxx . . $ structVertex#poly_npoints.; |
| 1010 | if (nPoints == 0) { |
| 1011 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No number info."); |
| 1012 | } |
| 1013 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (nPoints); |
| 1014 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> xcxx . . $ structVertex#x.; thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> ycxx . . $ structVertex#y.; |
| 1015 | while ((n = n -> nextcxx . . $ structDoublyLinkedNode#next.) != 0 && VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> poly_npointscxx . . $ structVertex#poly_npoints. == 0 && i <= nPoints) { |
| 1016 | i ++; |
| 1017 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> xcxx . . $ structVertex#x.; |
| 1018 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = VERTEXcxx . . $ `dwtools/Polygon_extensions.cpp:536:9`! (n) -> ycxx . . $ structVertex#y.; |
| 1019 | } |
| 1020 | *ni = n; |
| 1021 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1022 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1023 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Polygon not created."); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (PolygonBag, Collection, 0); |
| 1028 | |
| 1029 | static autoPolygonBagcxx . . $ autoPolygonBag# Vertices_to_Polygonscxx . . $ Vertices_to_Polygons(18747d90b2335ae4). (Verticescxx . . $ Vertices# me) { |
| 1030 | try { |
| 1031 | autoPolygonBagcxx . . $ autoPolygonBag# thee = PolygonBag_createcxx . . $ PolygonBag_create(1eb977bb17a9e031). (); |
| 1032 | DoublyLinkedNodecxx . . $ DoublyLinkedNode# node = mycxx . . $ `melder/melder.h:44:9`! frontcxx . . $ structDoublyLinkedList#front.; |
| 1033 | do { |
| 1034 | autoPolygoncxx . . $ autoPolygon# polygon = Vertices_to_Polygoncxx . . $ Vertices_to_Polygon(568bdc83f069b2ed). (me, & node); |
| 1035 | thycxx . . $ `melder/melder.h:45:9`! addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (polygoncxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 1036 | } while (node); |
| 1037 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1038 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1039 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no polygon collection created."); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | static autoPolygonBagcxx . . $ autoPolygonBag# Polygons_findClippingscxx . . $ Polygons_findClippings(2b3b3498a7178385). (Polygoncxx . . $ Polygon# me, bool use_myinterior, Polygoncxx . . $ Polygon# thee, bool use_thyinterior) { |
| 1044 | try { |
| 1045 | autoVerticescxx . . $ autoVertices# subject = Polygon_to_Verticescxx . . $ Polygon_to_Vertices(b23f1ad3a531eda). (me, true); |
| 1046 | integercxx . . $ integer# ns = subject ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfNodescxx . . $ structDoublyLinkedList#numberOfNodes.; |
| 1047 | autoVerticescxx . . $ autoVertices# clip = Polygon_to_Verticescxx . . $ Polygon_to_Vertices(b23f1ad3a531eda). (thee, true); |
| 1048 | // integer nc = clip -> numberOfNodes; |
| 1049 | double eps = 1e-15; |
| 1050 | |
| 1051 | // phase 1: Get all intersections and add them to both lists |
| 1052 | |
| 1053 | Vertices_addIntersectionscxx . . $ Vertices_addIntersections(ca2dea659c0d3720). (subject.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), clip.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1054 | integercxx . . $ integer# nnewnodes = subject ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfNodescxx . . $ structDoublyLinkedList#numberOfNodes. - ns; |
| 1055 | int firstLocation = Polygon_getLocationOfPointcxx . . $ Polygon_getLocationOfPoint(7c887ac351245d3b). (thee, mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], eps); |
| 1056 | if (nnewnodes == 0) { // no crossings, either one completely inside the other or separate |
| 1057 | autoPolygonBagcxx . . $ autoPolygonBag# polygonscxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 1058 | if (! use_myinterior && ! use_thyinterior && firstLocation == Polygon_INSIDEcxx . . $ `dwtools/Polygon_extensions.h:32:9`!) { |
| 1059 | autoPolygoncxx . . $ autoPolygon# copy = Data_copycxx . . $ Data_copy(97a542a26794c80e). (thee); |
| 1060 | polygons ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (copycxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 1061 | } else { |
| 1062 | autoPolygoncxx . . $ autoPolygon# copy = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 1063 | polygons ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (copycxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 1064 | } |
| 1065 | return polygonscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1066 | } |
| 1067 | |
| 1068 | // phase 2: Determine intersections as entry / exit points |
| 1069 | |
| 1070 | Vertices_markEntryPointscxx . . $ Vertices_markEntryPoints(ca7ebdd765aabe84). (subject.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), firstLocation); |
| 1071 | |
| 1072 | firstLocation = Polygon_getLocationOfPointcxx . . $ Polygon_getLocationOfPoint(7c887ac351245d3b). (me, thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], eps); |
| 1073 | Vertices_markEntryPointscxx . . $ Vertices_markEntryPoints(ca7ebdd765aabe84). (subject.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), firstLocation); |
| 1074 | if (Melder_debugcxx . . $ Melder_debug. == -1) { |
| 1075 | Vertices_printcxx . . $ Vertices_print(ca2dea659c0d3720). (subject.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), clip.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1076 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8).(); |
| 1077 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Bail out of Polygons_findClippings."); |
| 1078 | } |
| 1079 | |
| 1080 | // phase 3: Determine the clipping paths |
| 1081 | // use_myinterior use_thyinterior result |
| 1082 | // true false diff me - thee |
| 1083 | // false false union |
| 1084 | // true true clip |
| 1085 | // false true diff thee - me |
| 1086 | autoVerticescxx . . $ autoVertices# pgscxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 1087 | if (! use_myinterior && ! use_thyinterior) { |
| 1088 | pgs =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Verticeses_connectClippingPathsUnioncxx . . $ Verticeses_connectClippingPathsUnion(a40e66a0c73c758d). (subject.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), clip.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1089 | } else { |
| 1090 | pgs =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Verticeses_connectClippingPathscxx . . $ Verticeses_connectClippingPaths(b0c7493c9219ab15). (subject.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), use_myinterior, clip.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), use_thyinterior); |
| 1091 | } |
| 1092 | // phase 4: to Polygons |
| 1093 | |
| 1094 | autoPolygonBagcxx . . $ autoPolygonBag# polygons = Vertices_to_Polygonscxx . . $ Vertices_to_Polygons(18747d90b2335ae4). (pgs.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1095 | return polygonscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1096 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1097 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no union Polygon created."); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | autoPolygonBagcxx . . $ autoPolygonBag# Polygons_clipcxx . . $ Polygons_clip(4fbb2164e8b4b37c). (Polygoncxx . . $ Polygon# subject, Polygoncxx . . $ Polygon# clipper) { |
| 1102 | try { |
| 1103 | autoPolygonBagcxx . . $ autoPolygonBag# him = Polygons_findClippingscxx . . $ Polygons_findClippings(2b3b3498a7178385). (subject, true, clipper, true); |
| 1104 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1105 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1106 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (subject, U": no union created."); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | autoPolygoncxx . . $ autoPolygon# Polygons_unioncxx . . $ Polygons_union(bc0089f2395c09bf). (Polygoncxx . . $ Polygon# me, Polygoncxx . . $ Polygon# thee) { |
| 1111 | try { |
| 1112 | autoPolygonBagcxx . . $ autoPolygonBag# him = Polygons_findClippingscxx . . $ Polygons_findClippings(2b3b3498a7178385). (me, false, thee, false); |
| 1113 | //Melder_assert (his size == 1); |
| 1114 | autoPolygoncxx . . $ autoPolygon# p = hiscxx . . $ `melder/melder.h:47:9`! subtractItem_movecxx . . $ CollectionOf#subtractItem_move(8363591d77234f91). (1); |
| 1115 | return pcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1116 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1117 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no union created."); |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | #define CROSSINGcxx . . $ `dwtools/Polygon_extensions.cpp:1121:9`! (mycxx . . $ `melder/melder.h:44:9`! y [i] < y0) != (mycxx . . $ `melder/melder.h:44:9`! y [ip1] < y0) |
| 1122 | #define AREAcxx . . $ `dwtools/Polygon_extensions.cpp:1122:9`! { a = (mycxx . . $ `melder/melder.h:44:9`! x [i]-x0)*(mycxx . . $ `melder/melder.h:44:9`! y [ip1]-y0) - (mycxx . . $ `melder/melder.h:44:9`! x [ip1]-x0)*(mycxx . . $ `melder/melder.h:44:9`! y [i]-y0); if (fabs (a) <= eps) return Polygon_EDGEcxx . . $ `dwtools/Polygon_extensions.h:35:9`!; } |
| 1123 | #define RIGHT_CROSSINGcxx . . $ `dwtools/Polygon_extensions.cpp:1123:9`! (a > 0) == (mycxx . . $ `melder/melder.h:44:9`! y [ip1] > mycxx . . $ `melder/melder.h:44:9`! y [i]) |
| 1124 | #define MODIFY_CROSSING_NUMBERcxx . . $ `dwtools/Polygon_extensions.cpp:1124:9`! { if (mycxx . . $ `melder/melder.h:44:9`! y [ip1] > mycxx . . $ `melder/melder.h:44:9`! y [i]) nup ++; else nup--; } |
| 1125 | |
| 1126 | int Polygon_getLocationOfPointcxx . . $ Polygon_getLocationOfPoint(7c887ac351245d3b). (Polygoncxx . . $ Polygon# me, double x0, double y0, double eps) { |
| 1127 | if (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] == y0 and mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] == x0) { |
| 1128 | return Polygon_VERTEXcxx . . $ `dwtools/Polygon_extensions.h:36:9`!; |
| 1129 | } |
| 1130 | |
| 1131 | integercxx . . $ integer# nup = 0; |
| 1132 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 1133 | double a; |
| 1134 | integercxx . . $ integer# ip1 = ( i < mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. ? i + 1 : 1 ); |
| 1135 | if (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ip1] == y0) { |
| 1136 | if (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ip1] == x0) { |
| 1137 | return Polygon_VERTEXcxx . . $ `dwtools/Polygon_extensions.h:36:9`!; |
| 1138 | } else if (mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] == y0 && ( mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ip1] > x0 ) == ( mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] < x0 )) { |
| 1139 | return Polygon_EDGEcxx . . $ `dwtools/Polygon_extensions.h:35:9`!; |
| 1140 | } |
| 1141 | } |
| 1142 | if (CROSSINGcxx . . $ `dwtools/Polygon_extensions.cpp:1121:9`!) { |
| 1143 | if (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] >= x0) { |
| 1144 | if (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ip1] > x0) MODIFY_CROSSING_NUMBERcxx . . $ `dwtools/Polygon_extensions.cpp:1124:9`! |
| 1145 | else { |
| 1146 | AREAcxx . . $ `dwtools/Polygon_extensions.cpp:1122:9`! |
| 1147 | if (RIGHT_CROSSINGcxx . . $ `dwtools/Polygon_extensions.cpp:1123:9`!) MODIFY_CROSSING_NUMBERcxx . . $ `dwtools/Polygon_extensions.cpp:1124:9`! |
| 1148 | } |
| 1149 | } else { |
| 1150 | if (mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ip1] > x0) { |
| 1151 | AREAcxx . . $ `dwtools/Polygon_extensions.cpp:1122:9`! |
| 1152 | if (RIGHT_CROSSINGcxx . . $ `dwtools/Polygon_extensions.cpp:1123:9`!) MODIFY_CROSSING_NUMBERcxx . . $ `dwtools/Polygon_extensions.cpp:1124:9`! |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | return ( nup % 2 == 0 ? Polygon_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.h:33:9`! : Polygon_INSIDEcxx . . $ `dwtools/Polygon_extensions.h:32:9`! ); |
| 1158 | } |
| 1159 | |
| 1160 | static inline double crosscxx . . $ cross(7ba2c0e50130b3d8). (double x1, double y1, double x2, double y2, double x3, double y3) { |
| 1161 | return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1); |
| 1162 | } |
| 1163 | |
| 1164 | // Code adapted from http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain#C |
| 1165 | autoPolygoncxx . . $ autoPolygon# Polygon_convexHullcxx . . $ Polygon_convexHull(18f02ed335786f5e). (Polygoncxx . . $ Polygon# me) { |
| 1166 | try { |
| 1167 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. <= 3) return Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 1168 | |
| 1169 | autoVECcxx . . $ autoVEC# x = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.), y = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.); |
| 1170 | autoINTVECcxx . . $ autoINTVEC# hull = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. + 2); |
| 1171 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 1172 | x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = mycxx . . $ `melder/melder.h:44:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 1173 | y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = mycxx . . $ `melder/melder.h:44:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 1174 | } |
| 1175 | NUMsortTogethercxx . . $ NUMsortTogether(13c11f7bd0e7e3d2). (x.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), y.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 1176 | // lower hull |
| 1177 | integercxx . . $ integer# n = 1; |
| 1178 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints.; i ++) { |
| 1179 | while (n > 2 && crosscxx . . $ cross(7ba2c0e50130b3d8). (x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 2]], y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 2]], x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 1]], y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 1]], x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]) <= 0) |
| 1180 | --n; // counter clockwise turn |
| 1181 | hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n ++] = i; |
| 1182 | } |
| 1183 | // upper hull |
| 1184 | integercxx . . $ integer# t = n + 1; |
| 1185 | for (integercxx . . $ integer# i = mycxx . . $ `melder/melder.h:44:9`! numberOfPointscxx . . $ structPolygon#numberOfPoints. - 1; i >= 1; i--) { |
| 1186 | while (n >= t && crosscxx . . $ cross(7ba2c0e50130b3d8). (x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 2]], y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 2]], x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 1]], y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n - 1]], x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]) <= 0) |
| 1187 | --n; |
| 1188 | hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).n ++] = i; |
| 1189 | } |
| 1190 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (n - 1); |
| 1191 | for (integercxx . . $ integer# i = 1; i <= n - 1; i ++) { |
| 1192 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]]; |
| 1193 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).hull [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]]; |
| 1194 | } |
| 1195 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1196 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1197 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no convex hull polygon created."); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | double Polygon_getAreaOfConvexHullcxx . . $ Polygon_getAreaOfConvexHull(8e940d5358c1a895). (Polygoncxx . . $ Polygon# me) { |
| 1202 | try { |
| 1203 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_convexHullcxx . . $ Polygon_convexHull(18f02ed335786f5e). (me); |
| 1204 | return Polygon_areacxx . . $ Polygon_area(8e940d5358c1a895). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1205 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1206 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 1207 | return undefinedcxx . . $ undefined.; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | /* End of file Polygon_extensions.cpp */ |