short_way.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*!
  2. * \file lib/gis/short_way.c
  3. *
  4. * \brief GIS Library - Shortest path functions.
  5. *
  6. * (C) 2001-2009 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author Original author CERL
  12. */
  13. #include <grass/gis.h>
  14. /*!
  15. * \brief Shortest way between two eastings.
  16. *
  17. * For lat-lon projection (<tt>PROJECTION_LL</tt>), <i>east1</i>,
  18. * <i>east2</i> are changed so that they are no more than 180 degrees
  19. * apart. Their true locations are not changed. For all other
  20. * projections, this function does nothing.
  21. *
  22. * \param[in,out] east1 east (x) coordinate of first point
  23. * \param[in,out] east2 east (x) coordinate of second point
  24. */
  25. void G_shortest_way(double *east1, double *east2)
  26. {
  27. if (G_projection() == PROJECTION_LL) {
  28. if (*east1 > *east2)
  29. while ((*east1 - *east2) > 180)
  30. *east2 += 360;
  31. else if (*east2 > *east1)
  32. while ((*east2 - *east1) > 180)
  33. *east1 += 360;
  34. }
  35. }