g_circ.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 circle method, which is a standard part of
  16. libplot. It draws an object: a circle with center x,y and radius r.
  17. Circles are one of the three types of primitive closed path that libplot
  18. supports, along with boxes and ellipses. */
  19. /* Most Plotters obviously require that the map from the user frame to the
  20. device frame be uniform, in order to draw a circle as a primitive (if it
  21. isn't, what results will be an ellipse). The constraints on the user
  22. frame -> device frame map (e.g., it must be uniform) are specified by
  23. the internal `allowed_circle_scaling' parameter, which this code checks. */
  24. #include "sys-defines.h"
  25. #include "extern.h"
  26. int
  27. _API_fcircle (R___(Plotter *_plotter) double x, double y, double r)
  28. {
  29. if (!_plotter->data->open)
  30. {
  31. _plotter->error (R___(_plotter)
  32. "fcircle: invalid operation");
  33. return -1;
  34. }
  35. /* If a simple path is under construction (so that endsubpath() must not
  36. have been invoked), flush out the whole compound path. (It may
  37. include other, previously drawn simple paths.) */
  38. if (_plotter->drawstate->path)
  39. _API_endpath (S___(_plotter));
  40. if (!_plotter->drawstate->points_are_connected)
  41. /* line type is `disconnected', so do nothing (libplot convention) */
  42. {
  43. }
  44. else
  45. /* general case */
  46. {
  47. plPoint pc;
  48. bool clockwise;
  49. /* begin a new path */
  50. _plotter->drawstate->path = _new_plPath ();
  51. /* place circle in path buffer */
  52. pc.x = x;
  53. pc.y = y;
  54. clockwise = _plotter->drawstate->orientation < 0 ? true : false;
  55. if ((_plotter->data->allowed_circle_scaling == AS_ANY)
  56. ||
  57. (_plotter->data->allowed_circle_scaling == AS_UNIFORM
  58. && _plotter->drawstate->transform.uniform))
  59. /* place circle as a primitive, since this Plotter supports
  60. drawing circles as primitives */
  61. _add_circle (_plotter->drawstate->path,
  62. pc, r, clockwise);
  63. else if ((_plotter->data->allowed_ellipse_scaling == AS_ANY)
  64. ||
  65. (_plotter->data->allowed_ellipse_scaling == AS_AXES_PRESERVED
  66. && _plotter->drawstate->transform.axes_preserved))
  67. /* place circle as an ellipse, since this Plotter supports drawing
  68. ellipses as primitives */
  69. _add_ellipse (_plotter->drawstate->path,
  70. pc, r, r, 0.0, clockwise);
  71. else if (_plotter->data->allowed_ellarc_scaling == AS_ANY
  72. || (_plotter->data->allowed_ellarc_scaling == AS_AXES_PRESERVED
  73. && _plotter->drawstate->transform.axes_preserved))
  74. /* draw circle by placing four elliptical arcs into path buffer
  75. (allowed since this Plotter supports elliptical arcs) */
  76. _add_circle_as_ellarcs (_plotter->drawstate->path,
  77. pc, r, clockwise);
  78. else if (_plotter->data->allowed_cubic_scaling == AS_ANY)
  79. /* draw circle by placing four cubic Beziers into path buffer
  80. (allowed since this Plotter supports cubic Beziers) */
  81. _add_circle_as_bezier3s (_plotter->drawstate->path,
  82. pc, r, clockwise);
  83. else
  84. /* draw a polygonal approximation to the circle */
  85. _add_circle_as_lines (_plotter->drawstate->path,
  86. pc, r, clockwise);
  87. if (_plotter->drawstate->path->type == PATH_SEGMENT_LIST)
  88. /* pass all the newly added segments to the Plotter-specific
  89. function maybe_paint_segments(), since some Plotters plot paths
  90. in real time, i.e., prepaint them, rather than waiting until
  91. endpath() is called */
  92. _plotter->maybe_prepaint_segments (R___(_plotter) 0);
  93. }
  94. /* move to center (libplot convention) */
  95. _plotter->drawstate->pos.x = x;
  96. _plotter->drawstate->pos.y = y;
  97. return 0;
  98. }