g_affine.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
  3. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. /* This file contains the translate, rotate and scale methods, which are
  16. GNU extensions to libplot. They affect the affine transformation from
  17. user coordinates to device coordinates, as in Postscript. */
  18. #include "sys-defines.h"
  19. #include "extern.h"
  20. int
  21. _API_ftranslate (R___(Plotter *_plotter) double x, double y)
  22. {
  23. double m0, m1, m2, m3, m4, m5;
  24. if (!_plotter->data->open)
  25. {
  26. _plotter->error (R___(_plotter)
  27. "ftranslate: invalid operation");
  28. return -1;
  29. }
  30. m0 = m3 = 1.0;
  31. m1 = m2 = 0.0;
  32. m4 = x;
  33. m5 = y;
  34. _API_fconcat (R___(_plotter) m0, m1, m2, m3, m4, m5);
  35. return 0;
  36. }
  37. int
  38. _API_frotate (R___(Plotter *_plotter) double theta)
  39. {
  40. double m0, m1, m2, m3, m4, m5;
  41. double radians = M_PI * theta / 180.0;
  42. if (!_plotter->data->open)
  43. {
  44. _plotter->error (R___(_plotter)
  45. "frotate: invalid operation");
  46. return -1;
  47. }
  48. m0 = m3 = cos (radians);
  49. m1 = sin (radians);
  50. m2 = - sin (radians);
  51. m4 = m5 = 0.0;
  52. _API_fconcat (R___(_plotter) m0, m1, m2, m3, m4, m5);
  53. return 0;
  54. }
  55. int
  56. _API_fscale (R___(Plotter *_plotter) double x, double y)
  57. {
  58. double m0, m1, m2, m3, m4, m5;
  59. if (!_plotter->data->open)
  60. {
  61. _plotter->error (R___(_plotter)
  62. "fscale: invalid operation");
  63. return -1;
  64. }
  65. m0 = x;
  66. m3 = y;
  67. m1 = m2 = m4 = m5 = 0.0;
  68. _API_fconcat (R___(_plotter) m0, m1, m2, m3, m4, m5);
  69. return 0;
  70. }