[grits] Add string parser to GritsPoly
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] Add string parser to GritsPoly
- Date: Tue, 3 Jan 2012 01:18:43 +0000 (UTC)
commit b92e1aaaa39845e6ae25c0901c419f26c00541ee
Author: Andy Spencer <andy753421 gmail com>
Date: Wed Oct 12 08:30:35 2011 +0000
Add string parser to GritsPoly
src/objects/grits-poly.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/objects/grits-poly.h | 3 +++
2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/src/objects/grits-poly.c b/src/objects/grits-poly.c
index 1fe2266..da78fba 100644
--- a/src/objects/grits-poly.c
+++ b/src/objects/grits-poly.c
@@ -117,6 +117,47 @@ GritsPoly *grits_poly_new(gdouble (**points)[3])
return poly;
}
+GritsPoly *grits_poly_parse(gchar *str,
+ gchar *poly_sep, gchar *point_sep, gchar *coord_sep)
+{
+ /* Split and count polygons */
+ gchar **spolys = g_strsplit(str, poly_sep, -1);
+ int npolys = g_strv_length(spolys);
+
+ GritsPoint center = {0,0,0};
+ gdouble (**polys)[3] = (gpointer)g_new0(double*, npolys+1);
+ for (int pi = 0; pi < npolys; pi++) {
+ /* Split and count coordinates */
+ gchar **scoords = g_strsplit(spolys[pi], point_sep, -1);
+ int ncoords = g_strv_length(scoords);
+
+ /* Create binary coords */
+ gdouble (*coords)[3] = (gpointer)g_new0(gdouble, 3*(ncoords+1));
+ for (int ci = 0; ci < ncoords; ci++) {
+ gdouble lat, lon;
+ sscanf(scoords[ci], "%lf,%lf", &lat, &lon);
+ if (ci == 0) {
+ center.lat = lat;
+ center.lon = lon;
+ center.elev = 0;
+ }
+ lle2xyz(lat, lon, 0,
+ &coords[ci][0],
+ &coords[ci][1],
+ &coords[ci][2]);
+ }
+
+ /* Insert coords into poly array */
+ polys[pi] = coords;
+ g_strfreev(scoords);
+ }
+
+ /* Create GritsPoly */
+ GritsPoly *poly = grits_poly_new(polys);
+ GRITS_OBJECT(poly)->center = center;
+ return poly;
+}
+
/* GObject code */
G_DEFINE_TYPE(GritsPoly, grits_poly, GRITS_TYPE_OBJECT);
static void grits_poly_init(GritsPoly *poly)
diff --git a/src/objects/grits-poly.h b/src/objects/grits-poly.h
index df70b67..2629353 100644
--- a/src/objects/grits-poly.h
+++ b/src/objects/grits-poly.h
@@ -51,4 +51,7 @@ GType grits_poly_get_type(void);
GritsPoly *grits_poly_new(gdouble (**points)[3]);
+GritsPoly *grits_poly_parse(gchar *str,
+ gchar *poly_sep, gchar *point_sep, gchar *coord_sep);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]