mi_ply.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* This file is part of the GNU libxmi package.
  2. Copyright (C) 1985, 1986, 1987, 1988, 1989, X Consortium. For an
  3. associated permission notice, see the accompanying file README-X.
  4. GNU enhancements Copyright (C) 1998, 1999, 2000, 2005, Free Software
  5. Foundation, Inc.
  6. The GNU libxmi package is free software. You may redistribute it
  7. and/or modify it under the terms of the GNU General Public License as
  8. published by the Free Software foundation; either version 2, or (at your
  9. option) any later version.
  10. The GNU libxmi package is distributed in the hope that it will be
  11. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with the GNU plotutils package; see the file COPYING. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  17. Boston, MA 02110-1301, USA. */
  18. #include "sys-defines.h"
  19. #include "extern.h"
  20. #include "xmi.h"
  21. #include "mi_spans.h"
  22. #include "mi_gc.h"
  23. #include "mi_api.h"
  24. /*
  25. * Written by Brian Kelleher; June 1986
  26. *
  27. * Draw a polygon (supplied as a polyline, i.e. an array of points), via
  28. * one of two scan conversion routines.
  29. */
  30. void
  31. miFillPolygon_internal (miPaintedSet *paintedSet, const miGC *pGC, miPolygonShape shape, miCoordMode mode, int count, const miPoint *pPts)
  32. {
  33. miPoint *ppt = (miPoint *)NULL;
  34. const miPoint *q;
  35. /* ensure we have >=1 points */
  36. if (count <= 0)
  37. return;
  38. if (mode == MI_COORD_MODE_PREVIOUS)
  39. /* convert from relative to absolute coordinates */
  40. {
  41. int i;
  42. ppt = (miPoint *)mi_xmalloc (count * sizeof(miPoint));
  43. ppt[0] = pPts[0];
  44. for (i = 1; i < count; i++)
  45. {
  46. ppt[i].x = ppt[i-1].x + pPts[i].x;
  47. ppt[i].y = ppt[i-1].y + pPts[i].y;
  48. }
  49. q = ppt;
  50. }
  51. else
  52. q = pPts;
  53. switch ((int)shape)
  54. {
  55. case (int)MI_SHAPE_GENERAL:
  56. default:
  57. /* use general scan conversion routine */
  58. miFillGeneralPoly (paintedSet, pGC, count, q);
  59. break;
  60. case (int)MI_SHAPE_CONVEX:
  61. /* use special (faster) routine */
  62. miFillConvexPoly (paintedSet, pGC, count, q);
  63. break;
  64. }
  65. if (mode == MI_COORD_MODE_PREVIOUS)
  66. free (ppt);
  67. }