flip.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*!
  2. \file lib/vector/vedit/flip.c
  3. \brief Vedit library - flip lines
  4. (C) 2007-2008 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Martin Landa <landa.martin gmail.com>
  8. */
  9. #include <grass/vedit.h>
  10. /*!
  11. \brief Flip direction of selected lines
  12. \param Map pointer to Map_info
  13. \param List list of selected lines
  14. \return number of modified lines
  15. \return -1 on error
  16. */
  17. int Vedit_flip_lines(struct Map_info *Map, struct ilist *List)
  18. {
  19. struct line_cats *Cats;
  20. struct line_pnts *Points;
  21. int i, line, type;
  22. int nlines_flipped;
  23. nlines_flipped = 0;
  24. Points = Vect_new_line_struct();
  25. Cats = Vect_new_cats_struct();
  26. for (i = 0; i < List->n_values; i++) {
  27. line = List->value[i];
  28. if (!Vect_line_alive(Map, line))
  29. continue;
  30. type = Vect_read_line(Map, Points, Cats, line);
  31. if (!(type & GV_LINES))
  32. continue;
  33. Vect_line_reverse(Points);
  34. if (Vect_rewrite_line(Map, line, type, Points, Cats) < 0) {
  35. return -1;
  36. }
  37. G_debug(3, "Vedit_flip_lines(): line=%d", line);
  38. nlines_flipped++;
  39. }
  40. /* destroy structures */
  41. Vect_destroy_line_struct(Points);
  42. Vect_destroy_cats_struct(Cats);
  43. return nlines_flipped;
  44. }