From: Pierre-Luc Beaudoin Date: Wed, 10 Jun 2009 02:04:32 +0000 (-0400) Subject: Refine the Polygon point API X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0356d04496a5d3ae4bd70d7469adbb3e866a21e;p=libchamplain Refine the Polygon point API --- diff --git a/champlain/champlain-polygon.c b/champlain/champlain-polygon.c index f569592..1105411 100644 --- a/champlain/champlain-polygon.c +++ b/champlain/champlain-polygon.c @@ -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 diff --git a/champlain/champlain-polygon.h b/champlain/champlain-polygon.h index 8f995d4..d5ab205 100644 --- a/champlain/champlain-polygon.h +++ b/champlain/champlain-polygon.h @@ -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, diff --git a/demos/polygons.c b/demos/polygons.c index 7c23745..7ea3ce2 100644 --- a/demos/polygons.c +++ b/demos/polygons.c @@ -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);