SampledXY.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SampledXY.cpp
  2. *
  3. * Copyright (C) 1992-2012,2013,2014,2017 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. #include "SampledXY.h"
  19. #include "oo_DESTROY.h"
  20. #include "SampledXY_def.h"
  21. #include "oo_COPY.h"
  22. #include "SampledXY_def.h"
  23. #include "oo_EQUAL.h"
  24. #include "SampledXY_def.h"
  25. #include "oo_CAN_WRITE_AS_ENCODING.h"
  26. #include "SampledXY_def.h"
  27. #include "oo_WRITE_TEXT.h"
  28. #include "SampledXY_def.h"
  29. #include "oo_READ_TEXT.h"
  30. #include "SampledXY_def.h"
  31. #include "oo_WRITE_BINARY.h"
  32. #include "SampledXY_def.h"
  33. #include "oo_READ_BINARY.h"
  34. #include "SampledXY_def.h"
  35. #include "oo_DESCRIPTION.h"
  36. #include "SampledXY_def.h"
  37. Thing_implement (SampledXY, Sampled, 0);
  38. /*
  39. * CHECK
  40. if (xmin > xmax || ymin > ymax) {
  41. Melder_throw (U"xmax should be greater than xmax and ymax should be greater than ymin.");
  42. }
  43. if (nx < 1 || ny < 1) {
  44. Melder_throw (U"nx and ny should be at least 1.");
  45. }
  46. if (dx <= 0 || dy <= 0) {
  47. Melder_throw (U"dx and dy should be positive.");
  48. }
  49. }
  50. */
  51. void SampledXY_init (SampledXY me,
  52. double xmin, double xmax, integer nx, double dx, double x1,
  53. double ymin, double ymax, integer ny, double dy, double y1)
  54. {
  55. Sampled_init (me, xmin, xmax, nx, dx, x1);
  56. my ymin = ymin;
  57. my ymax = ymax;
  58. my ny = ny;
  59. my dy = dy;
  60. my y1 = y1;
  61. }
  62. integer SampledXY_getWindowSamplesY (SampledXY me, double fromY, double toY, integer *iymin, integer *iymax) {
  63. double riymin = 1.0 + Melder_roundUp ((fromY - my y1) / my dy);
  64. double riymax = 1.0 + Melder_roundDown ((toY - my y1) / my dy); // could be above 32-bit LONG_MAX
  65. *iymin = riymin < 1.0 ? 1 : (integer) riymin;
  66. *iymax = riymax > (double) my ny ? my ny : (integer) riymax;
  67. if (*iymin > *iymax) return 0;
  68. return *iymax - *iymin + 1;
  69. }
  70. /* End of file SampledXY.cpp */