An LGPL/GPL-licensed artwork library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.2KB

  1. /* Libart_LGPL - library of basic graphic primitives
  2. * Copyright (C) 1998 Raph Levien
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #include "config.h"
  20. #include "art_rect_svp.h"
  21. #include "art_misc.h"
  22. #include "art_svp.h"
  23. #include "art_rect.h"
  24. #ifndef MAX
  25. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  26. #endif /* MAX */
  27. #ifndef MIN
  28. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  29. #endif /* MIN */
  30. /**
  31. * art_drect_svp: Find the bounding box of a sorted vector path.
  32. * @bbox: Where to store the bounding box.
  33. * @svp: The SVP.
  34. *
  35. * Finds the bounding box of the SVP.
  36. **/
  37. void
  38. art_drect_svp (ArtDRect *bbox, const ArtSVP *svp)
  39. {
  40. int i;
  41. if (svp->n_segs == 0)
  42. {
  43. bbox->x0 = 0;
  44. bbox->y0 = 0;
  45. bbox->x1 = 0;
  46. bbox->y1 = 0;
  47. return;
  48. }
  49. art_drect_copy (bbox, &svp->segs[0].bbox);
  50. for (i = 1; i < svp->n_segs; i++)
  51. {
  52. bbox->x0 = MIN (bbox->x0, svp->segs[i].bbox.x0);
  53. bbox->y0 = MIN (bbox->y0, svp->segs[i].bbox.y0);
  54. bbox->x1 = MAX (bbox->x1, svp->segs[i].bbox.x1);
  55. bbox->y1 = MAX (bbox->y1, svp->segs[i].bbox.y1);
  56. }
  57. }
  58. /**
  59. * art_drect_svp_union: Compute the bounding box of the svp and union it in to the existing bounding box.
  60. * @bbox: Initial boundin box and where to store the bounding box.
  61. * @svp: The SVP.
  62. *
  63. * Finds the bounding box of the SVP, computing its union with an
  64. * existing bbox.
  65. **/
  66. void
  67. art_drect_svp_union (ArtDRect *bbox, const ArtSVP *svp)
  68. {
  69. ArtDRect svp_bbox;
  70. art_drect_svp (&svp_bbox, svp);
  71. art_drect_union (bbox, bbox, &svp_bbox);
  72. }