| 1 | #ifndef _Polygon_extensions_h_ |
| 2 | #define _Polygon_extensions_h_ |
| 3 | /* Polygon_extensions.h |
| 4 | * |
| 5 | * Copyright (C) 1993-2019 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | djmw 1996 |
| 23 | djmw 20020813 GPL header |
| 24 | djmw 20120220 Latest modification |
| 25 | */ |
| 26 | |
| 27 | #include "Polygon.h" |
| 28 | #include "Categories.h" |
| 29 | #include "Graphics.h" |
| 30 | #include "Sound.h" |
| 31 | |
| 32 | #define Polygon_INSIDE -1 |
| 33 | #define Polygon_OUTSIDE 0 |
| 34 | #define Polygon_BOUNDARY 1 |
| 35 | #define Polygon_EDGE 3 |
| 36 | #define Polygon_VERTEX 5 |
| 37 | |
| 38 | void Polygon_getExtrema (Polygon me, double *out_xmin, double *out_xmax, double *out_ymin, double *out_ymax); |
| 39 | |
| 40 | autoPolygon Polygon_createSimple (constVECVU const& vertices_asXYPairs); |
| 41 | |
| 42 | autoPolygon Polygon_createFromRandomPoints (integer numberOfVertices, double xmin, double xmax, double ymin, double ymax); |
| 43 | |
| 44 | autoPolygon Polygon_simplify (Polygon me); |
| 45 | |
| 46 | void Polygon_translate (Polygon me, double xt, double yt); |
| 47 | |
| 48 | void Polygon_rotate (Polygon me, double alpha, double xc, double yc); |
| 49 | |
| 50 | void Polygon_scale (Polygon me, double xs, double ys); |
| 51 | |
| 52 | void Polygon_reverseX (Polygon me); |
| 53 | |
| 54 | void Polygon_reverseY (Polygon me); |
| 55 | |
| 56 | autoPolygon Polygon_circularPermutation (Polygon me, integer nshift); |
| 57 | |
| 58 | // Is point (x,y) Inside, Outside, Boundary (Edge or Vertex) ? |
| 59 | int Polygon_getLocationOfPoint (Polygon me, double x0, double y0, double eps); |
| 60 | |
| 61 | void Polygon_Categories_draw (Polygon me, Categories thee, Graphics graphics, double xmin, double xmax, double ymin, double ymax, bool garnish); |
| 62 | /* reverse axis when min > max */ |
| 63 | |
| 64 | void Polygon_drawMarks (Polygon me, Graphics g, double xmin, double xmax, double ymin, double ymax, double size_mm, conststring32 mark); |
| 65 | |
| 66 | autoPolygon Sound_to_Polygon (Sound me, integer channel, double tmin, double tmax, double ymin, double ymax, double level); |
| 67 | /* |
| 68 | Post-conditions: |
| 69 | |
| 70 | If there are ns = i2 - i1 + 1 samples of the sound in the interval (tmin, tmax), the first at index i1 |
| 71 | and the last at index i2, the Polygon will have np = 2 + ns + 2 + 1 points. |
| 72 | i1 = Sampled_xToHighIndex (me, tmin) |
| 73 | i2 = Sampled_xToLowIndex (me, tmax) |
| 74 | thy x [1] = tmin |
| 75 | thy y [1] = clip(level) |
| 76 | thy x [2] = tmin |
| 77 | thy y [2] = interpolated amplitude in 'channel' at tmin (or, averaged over all channels if channel = 0) |
| 78 | thy x [3] = my x1 + (i1 - 1) * my dx |
| 79 | thy y [3] = clip(my z [channel] [i1]) (or, averaged over all channels if channel == 0) |
| 80 | ... |
| 81 | thy x [ns+2] = my x1 +(i2 - 1) * my dx |
| 82 | thy y [ns+2] = clip(my z [channel] [i2]) (or, averaged over all channels if channel == 0) |
| 83 | thy x [ns+3] = tmax |
| 84 | thy y [ns+3] = clip(interpolated amplitude in 'channel' at tmax (or, averaged over all channels if channel == 0)) |
| 85 | thy x [ns+4] = tmax |
| 86 | thy y [ns+4] = clip(level) |
| 87 | thy x [ns+5] = thy x [1] (close the path) |
| 88 | thy y [ns+5] = thy y [1] |
| 89 | where clip(y) = y < ymin ? ymin : y > ymax ? ymax ; y; |
| 90 | */ |
| 91 | |
| 92 | autoPolygon Sounds_to_Polygon_enclosed (Sound me, Sound thee, integer channel, double tmin, double tmax, double ymin, double ymax); |
| 93 | /* Area enclosed by the sounds */ |
| 94 | |
| 95 | autoPolygon Polygons_union (Polygon me, Polygon thee); |
| 96 | |
| 97 | Collection_define (PolygonBag, CollectionOf, Polygon) { |
| 98 | }; |
| 99 | |
| 100 | autoPolygonBag Polygons_clip (Polygon me, Polygon thee); |
| 101 | |
| 102 | autoPolygon Polygon_convexHull (Polygon me); |
| 103 | |
| 104 | double Polygon_getAreaOfConvexHull (Polygon me); |
| 105 | |
| 106 | #endif /* _Polygon_extensions_h_ */ |