vect.c 807 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Functions: adjust_line
  2. *
  3. * Author: Radim Blazek Feb 2000
  4. *
  5. */
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <grass/vector.h>
  9. #include <grass/gis.h>
  10. #include "vector.h"
  11. #define LENGTH(DX, DY) ( sqrt( (DX*DX)+(DY*DY) ) )
  12. /* nearest returns nearest longitude coordinate, copy from src/libes */
  13. static double nearest_longitude(double e0, double e1)
  14. {
  15. while (e0 - e1 > 180)
  16. e1 += 360.0;
  17. while (e1 - e0 > 180)
  18. e1 -= 360.0;
  19. return e1;
  20. }
  21. /* if projection is PROJECTION_LL adjust_line will change
  22. * longitudes to nearest form previous point
  23. */
  24. void adjust_line(struct line_pnts *Points)
  25. {
  26. int i, np;
  27. if (G_projection() == PROJECTION_LL) {
  28. np = Points->n_points;
  29. for (i = 1; i < np; i++) {
  30. Points->x[i] = nearest_longitude(Points->x[i - 1], Points->x[i]);
  31. }
  32. }
  33. }