]> err.no Git - libchamplain/commitdiff
Refine the Polygon point API
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 10 Jun 2009 02:04:32 +0000 (22:04 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 10 Jun 2009 02:04:32 +0000 (22:04 -0400)
champlain/champlain-polygon.c
champlain/champlain-polygon.h
demos/polygons.c

index f5695923e8ae47a7d1ec8c200408325bb75edfd6..110541119404702aa667399471b6907c13d1ac9d 100644 (file)
@@ -269,20 +269,70 @@ champlain_polygon_new ()
   return g_object_new (CHAMPLAIN_TYPE_POLYGON, NULL);
 }
 
-void
-champlain_polygon_add_point (ChamplainPolygon *self,
+/**
+ * champlain_polygon_append_point:
+ * @polygon: The polygon
+ * @lat: the latitude
+ * @lon: the longitude
+ *
+ * Adds point at the end of the list of points in the polygon
+ *
+ * Returns the added point, should not be freed.
+ *
+ * Since: 0.4
+ */
+ChamplainPoint *
+champlain_polygon_append_point (ChamplainPolygon *self,
     gdouble lat,
     gdouble lon)
 {
-  g_return_if_fail (CHAMPLAIN_IS_POLYGON (self));
+  g_return_val_if_fail (CHAMPLAIN_IS_POLYGON (self), NULL);
 
   ChamplainPoint *point = g_new0 (ChamplainPoint, 1);
   point->lat = lat;
   point->lon = lon;
 
   self->priv->points = g_list_append (self->priv->points, point);
+  return point;
 }
 
+/**
+ * champlain_polygon_insert_point:
+ * @polygon: The polygon
+ * @lat: the latitude
+ * @lon: the longitude
+ * @pos: where to insert the point
+ *
+ * Adds point at the given position in the list of points in the polygon
+ *
+ * Returns the added point, should not be freed.
+ *
+ * Since: 0.4
+ */
+ChamplainPoint *
+champlain_polygon_insert_point (ChamplainPolygon *self,
+    gdouble lat,
+    gdouble lon,
+    gint pos)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_POLYGON (self), NULL);
+
+  ChamplainPoint *point = g_new0 (ChamplainPoint, 1);
+  point->lat = lat;
+  point->lon = lon;
+
+  self->priv->points = g_list_insert (self->priv->points, point, pos);
+  return point;
+}
+
+/**
+ * champlain_polygon_clear_points:
+ * @polygon: The polygon
+ *
+ * Remove all points from the polygon
+ *
+ * Since: 0.4
+ */
 void
 champlain_polygon_clear_points (ChamplainPolygon *self)
 {
@@ -297,6 +347,22 @@ champlain_polygon_clear_points (ChamplainPolygon *self)
   g_list_free (self->priv->points);
 }
 
+/**
+ * champlain_polygon_get_points:
+ * @polygon: The polygon
+ *
+ * Returns a list of all points from the polygon, it shouldn't be freed.
+ *
+ * Since: 0.4
+ */
+GList *
+champlain_polygon_get_points (ChamplainPolygon *self)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_POLYGON (self), NULL);
+
+  return self->priv->points;
+}
+
 /**
  * champlain_polygon_set_fill_color:
  * @polygon: The polygon
index 8f995d41d57f40bdecd63200bd46838433ff143e..d5ab20561e7a3b661a57dfda77081ae1edbcecf3 100644 (file)
@@ -60,13 +60,18 @@ typedef struct {
 
 GType champlain_polygon_get_type (void);
 
-ChamplainPolygon* champlain_polygon_new (void);
+ChamplainPolygon * champlain_polygon_new (void);
 
-void champlain_polygon_add_point (ChamplainPolygon *polygon,
+ChamplainPoint * champlain_polygon_append_point (ChamplainPolygon *polygon,
     gdouble lat,
     gdouble lon);
-
+ChamplainPoint * champlain_polygon_insert_point (ChamplainPolygon *polygon,
+    gdouble lat,
+    gdouble lon,
+    gint pos);
 void champlain_polygon_clear_points (ChamplainPolygon *polygon);
+GList *champlain_polygon_get_points (ChamplainPolygon *polygon);
+
 void champlain_polygon_set_fill_color (ChamplainPolygon *polygon,
     const ClutterColor *color);
 void champlain_polygon_set_stroke_color (ChamplainPolygon *polygon,
index 7c23745cb7bc9f1d9ac2a6e508d9808ff4e43f97..7ea3ce2e8e7c89b8e544a544246be115b4e984d3 100644 (file)
@@ -110,25 +110,25 @@ main (int argc,
   /* draw a line */
   polygon = champlain_polygon_new ();
   /* Cheap approx of Highway 10 */
-  champlain_polygon_add_point (polygon, 45.4095, -73.3197);
-  champlain_polygon_add_point (polygon, 45.4104, -73.2846);
-  champlain_polygon_add_point (polygon, 45.4178, -73.2239);
-  champlain_polygon_add_point (polygon, 45.4176, -73.2181);
-  champlain_polygon_add_point (polygon, 45.4151, -73.2126);
-  champlain_polygon_add_point (polygon, 45.4016, -73.1926);
-  champlain_polygon_add_point (polygon, 45.3994, -73.1877);
-  champlain_polygon_add_point (polygon, 45.4000, -73.1815);
-  champlain_polygon_add_point (polygon, 45.4151, -73.1218);
+  champlain_polygon_append_point (polygon, 45.4095, -73.3197);
+  champlain_polygon_append_point (polygon, 45.4104, -73.2846);
+  champlain_polygon_append_point (polygon, 45.4178, -73.2239);
+  champlain_polygon_append_point (polygon, 45.4176, -73.2181);
+  champlain_polygon_append_point (polygon, 45.4151, -73.2126);
+  champlain_polygon_append_point (polygon, 45.4016, -73.1926);
+  champlain_polygon_append_point (polygon, 45.3994, -73.1877);
+  champlain_polygon_append_point (polygon, 45.4000, -73.1815);
+  champlain_polygon_append_point (polygon, 45.4151, -73.1218);
   champlain_polygon_set_stroke_width (polygon, 5.0);
   champlain_view_add_polygon (CHAMPLAIN_VIEW (actor), polygon);
 
   /* draw a polygon */
   polygon = champlain_polygon_new ();
-  champlain_polygon_add_point (polygon, 45.1386, -73.9196);
-  champlain_polygon_add_point (polygon, 45.1229, -73.8991);
-  champlain_polygon_add_point (polygon, 45.0946, -73.9531);
-  champlain_polygon_add_point (polygon, 45.1085, -73.9714);
-  champlain_polygon_add_point (polygon, 45.1104, -73.9761);
+  champlain_polygon_append_point (polygon, 45.1386, -73.9196);
+  champlain_polygon_append_point (polygon, 45.1229, -73.8991);
+  champlain_polygon_append_point (polygon, 45.0946, -73.9531);
+  champlain_polygon_append_point (polygon, 45.1085, -73.9714);
+  champlain_polygon_append_point (polygon, 45.1104, -73.9761);
   champlain_view_add_polygon (CHAMPLAIN_VIEW (actor), polygon);
   g_object_set (polygon, "closed-path", TRUE, NULL);
   g_object_set (polygon, "fill", TRUE, NULL);