X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fgis-util.c;h=c25b57c4ed0116902b7a06457d60a76011ab401c;hb=aa0783b3ce8ab7dd72560b7327600c2b36a8b391;hp=3bd5246002e134843c7c8c2a13726dbc8e05c653;hpb=a2a902d978b6050289f7a92794fb1dc0aa2b5e26;p=grits diff --git a/src/gis-util.c b/src/gis-util.c index 3bd5246..c25b57c 100644 --- a/src/gis-util.c +++ b/src/gis-util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Andy Spencer + * Copyright (C) 2009-2010 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,3 +65,16 @@ gdouble distd(gdouble *a, gdouble *b) (a[1]-b[1])*(a[1]-b[1]) + (a[2]-b[2])*(a[2]-b[2])); } + +gdouble lon_avg(gdouble a, gdouble b) +{ + gdouble diff = ABS(a-b); + gdouble avg = (a+b)/2; + if (diff > 180) { + if (avg >= 0) + avg -= 180; + else + avg += 180; + } + return avg; +}