| 1 |
/* Matrix_and_Polygon.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2005,2011,2012,2015-2018,2020 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "Matrix_and_Polygon.h" |
| 20 |
|
| 21 |
autoPolygon Matrix_to_Polygon (Matrix me) { |
| 22 |
try { |
| 23 |
Melder_require (my nx == 2 || my ny == 2, |
| 24 |
U"The Matrix should have exactly 2 rows or columns."); |
| 25 |
autoPolygon thee; |
| 26 |
if (my ny == 2) { |
| 27 |
/* |
| 28 |
The matrix has two rows. |
| 29 |
The first row will be interpreted as x values, the second as y values. |
| 30 |
*/ |
| 31 |
thee = Polygon_create (my nx); |
| 32 |
thy x.all() <<= my z.row (1); |
| 33 |
thy y.all() <<= my z.row (2); |
| 34 |
} else { |
| 35 |
/* |
| 36 |
The matrix has two columns. |
| 37 |
The first column will be interpreted as x values, the second as y values. |
| 38 |
*/ |
| 39 |
thee = Polygon_create (my ny); |
| 40 |
thy x.all() <<= my z.column (1); |
| 41 |
thy y.all() <<= my z.column (2); |
| 42 |
} |
| 43 |
return thee; |
| 44 |
} catch (MelderError) { |
| 45 |
Melder_throw (me, U": not converted to Polygon."); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
autoMatrix Polygon_to_Matrix (Polygon me) { |
| 50 |
try { |
| 51 |
/* |
| 52 |
The matrix will have two rows: |
| 53 |
the first column will represent x, the second will represent y. |
| 54 |
*/ |
| 55 |
autoMatrix thee = Matrix_create (1.0, my numberOfPoints, my numberOfPoints, 1.0, 1.0, 1.0, 2.0, 2, 1.0, 1.0); |
| 56 |
thy z.row (1) <<= my x.get(); |
| 57 |
thy z.row (2) <<= my y.get(); |
| 58 |
return thee; |
| 59 |
} catch (MelderError) { |
| 60 |
Melder_throw (me, U": not converted to Matrix."); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/* End of file Matrix_and_Polygon.cpp */ |