2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /* all coord operations MUST BE ABSTRACTED!!! */
28 void vik_coord_convert(VikCoord
*coord
, VikCoordMode dest_mode
)
31 if ( coord
->mode
!= dest_mode
)
33 if ( dest_mode
== VIK_COORD_LATLON
) {
34 a_coords_utm_to_latlon ( (struct UTM
*)coord
, (struct LatLon
*)&tmp
);
35 *((struct LatLon
*)coord
) = *((struct LatLon
*)&tmp
);
37 a_coords_latlon_to_utm ( (struct LatLon
*)coord
, (struct UTM
*)&tmp
);
38 *((struct UTM
*)coord
) = *((struct UTM
*)&tmp
);
40 coord
->mode
= dest_mode
;
44 void vik_coord_copy_convert(const VikCoord
*coord
, VikCoordMode dest_mode
, VikCoord
*dest
)
46 if ( coord
->mode
== dest_mode
) {
49 if ( dest_mode
== VIK_COORD_LATLON
)
50 a_coords_utm_to_latlon ( (struct UTM
*)coord
, (struct LatLon
*)dest
);
52 a_coords_latlon_to_utm ( (struct LatLon
*)coord
, (struct UTM
*)dest
);
53 dest
->mode
= dest_mode
;
57 static gdouble
vik_coord_diff_safe(const VikCoord
*c1
, const VikCoord
*c2
)
59 static struct LatLon a
, b
;
60 vik_coord_to_latlon ( c1
, &a
);
61 vik_coord_to_latlon ( c2
, &b
);
62 return a_coords_latlon_diff ( &a
, &b
);
65 gdouble
vik_coord_diff(const VikCoord
*c1
, const VikCoord
*c2
)
67 if ( c1
->mode
== c2
->mode
)
68 return vik_coord_diff_safe ( c1
, c2
);
69 if ( c1
->mode
== VIK_COORD_UTM
)
70 return a_coords_utm_diff ( (const struct UTM
*) c1
, (const struct UTM
*) c2
);
72 return a_coords_latlon_diff ( (const struct LatLon
*) c1
, (const struct LatLon
*) c2
);
75 void vik_coord_load_from_latlon ( VikCoord
*coord
, VikCoordMode mode
, const struct LatLon
*ll
)
77 if ( mode
== VIK_COORD_LATLON
)
78 *((struct LatLon
*)coord
) = *ll
;
80 a_coords_latlon_to_utm ( ll
, (struct UTM
*) coord
);
84 void vik_coord_load_from_utm ( VikCoord
*coord
, VikCoordMode mode
, const struct UTM
*utm
)
86 if ( mode
== VIK_COORD_UTM
)
87 *((struct UTM
*)coord
) = *utm
;
89 a_coords_utm_to_latlon ( utm
, (struct LatLon
*) coord
);
93 void vik_coord_to_latlon ( const VikCoord
*coord
, struct LatLon
*dest
)
95 if ( coord
->mode
== VIK_COORD_LATLON
)
96 *dest
= *((const struct LatLon
*)coord
);
98 a_coords_utm_to_latlon ( (const struct UTM
*) coord
, dest
);
101 void vik_coord_to_utm ( const VikCoord
*coord
, struct UTM
*dest
)
103 if ( coord
->mode
== VIK_COORD_UTM
)
104 *dest
= *((const struct UTM
*)coord
);
106 a_coords_latlon_to_utm ( (const struct LatLon
*) coord
, dest
);
109 gboolean
vik_coord_equals ( const VikCoord
*coord1
, const VikCoord
*coord2
)
111 if ( coord1
->mode
!= coord2
->mode
)
113 if ( coord1
->mode
== VIK_COORD_LATLON
)
114 return coord1
->north_south
== coord2
->north_south
&& coord1
->east_west
== coord2
->east_west
;
115 else /* VIK_COORD_UTM */
116 return coord1
->utm_zone
== coord2
->utm_zone
&& coord1
->north_south
== coord2
->north_south
&& coord1
->east_west
== coord2
->east_west
;