]> err.no Git - libchamplain/commitdiff
Bindings for ChamplainPoint
authorEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Sun, 14 Jun 2009 14:46:02 +0000 (16:46 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 14 Jun 2009 17:19:59 +0000 (13:19 -0400)
bindings/perl/Champlain/MANIFEST
bindings/perl/Champlain/maps
bindings/perl/Champlain/t/ChamplainPoint.t [new file with mode: 0644]
bindings/perl/Champlain/xs/ChamplainPoint.xs [new file with mode: 0644]

index 024f42e99cc47538f9d35fefa852737af44039c2..6f8196725923bcff4169016f01e1449f28f4650f 100644 (file)
@@ -16,6 +16,7 @@ xs/ChamplainMapSourceDesc.xs
 xs/ChamplainMapSourceFactory.xs
 xs/ChamplainMarker.xs
 xs/ChamplainNetworkMapSource.xs
+xs/ChamplainPoint.xs
 xs/ChamplainTile.xs
 xs/ChamplainView.xs
 xs/ChamplainZoomLevel.xs
@@ -28,6 +29,7 @@ t/ChamplainMapSourceDesc.t
 t/ChamplainMapSourceFactory.t
 t/ChamplainMarker.t
 t/ChamplainNetworkMapSource.t
+t/ChamplainPoint.t
 t/ChamplainTile.t
 t/ChamplainView.t
 t/ChamplainZoomLevel.t
index aaf00ccd66cf194b907931cac45dea9a5e9fff7b..12be7ba008d2bc5552b39b6a72ff3a66c091b460 100644 (file)
@@ -12,3 +12,4 @@ CHAMPLAIN_TYPE_STATE               ChamplainState             GEnum    Champlain
 CHAMPLAIN_TYPE_MAP_SOURCE_FACTORY  ChamplainMapSourceFactory  GObject  Champlain::MapSourceFactory
 CHAMPLAIN_TYPE_CACHE               ChamplainCache             GObject  Champlain::Cache
 CHAMPLAIN_TYPE_MAP_SOURCE_DESC     ChamplainMapSourceDesc     GBoxed   Champlain::MapSourceDesc
+CHAMPLAIN_TYPE_POINT               ChamplainPoint             GBoxed   Champlain::Point
diff --git a/bindings/perl/Champlain/t/ChamplainPoint.t b/bindings/perl/Champlain/t/ChamplainPoint.t
new file mode 100644 (file)
index 0000000..e791efb
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Clutter::TestHelper tests => 10;
+use Test::Exception;
+
+use Champlain ':maps';
+
+exit tests();
+
+sub tests {
+       test_generic();
+       return 0;
+}
+
+
+sub test_generic {
+       my $point = Champlain::Point->new(10.2, 34.5);
+       isa_ok($point, 'Champlain::Point');
+
+       is($point->lat, 10.2, "point->lat()");
+       is($point->lon, 34.5, "point->lon()");
+
+
+       # Copy the point
+       my $copy = $point->copy;
+       isa_ok($copy, 'Champlain::Point');
+       is($copy->lat, $point->lat, "lat of copy is identical to the original");
+       is($copy->lon, $point->lon, "lon of copy is identical to the original");
+
+
+       # Modify the copy
+       $copy->lat(-45.03);
+       is($copy->lat, -45.03, "point->lat(x)");
+       is($point->lat, 10.2, "point->lat()");
+
+       $copy->lon(74.364);
+       is($copy->lon, 74.364, "point->lon(y)");
+       is($point->lon, 34.5, "point->lon()");
+}
diff --git a/bindings/perl/Champlain/xs/ChamplainPoint.xs b/bindings/perl/Champlain/xs/ChamplainPoint.xs
new file mode 100644 (file)
index 0000000..12c04b5
--- /dev/null
@@ -0,0 +1,47 @@
+#include "champlain-perl.h"
+
+
+MODULE = Champlain::Point  PACKAGE = Champlain::Point  PREFIX = champlain_point_
+
+
+ChamplainPoint*
+champlain_point_new (class, gdouble lat, gdouble lon)
+       C_ARGS: lat, lon
+
+
+ChamplainPoint*
+champlain_point_copy (const ChamplainPoint* point)
+
+
+void
+champlain_point_free (ChamplainPoint* point)
+
+
+#
+# Provide nice accessors to the data members of the struct.
+#
+gdouble
+lat (ChamplainPoint *point, gdouble newval = 0)
+       ALIAS:
+               lon = 1
+
+       CODE:
+               switch (ix) {
+                       case 0:
+                               RETVAL = point->lat;
+                               if (items > 1) point->lat = newval;
+                       break;
+
+                       case 1:
+                               RETVAL = point->lon;
+                               if (items > 1) point->lon = newval;
+                       break;
+
+                       default:
+                               RETVAL = 0.0;
+                               g_assert_not_reached();
+                       break;
+               }
+
+       OUTPUT:
+               RETVAL