1use strict;
2use warnings;
3use Scalar::Util 'blessed';
4use Test::More qw(no_plan);
5BEGIN { use_ok('Geo::GDAL') };
6
7my $e = Geo::GDAL::Extent->new;
8
9ok(blessed($e), "Can create new extent objects");
10ok(ref $e eq 'Geo::GDAL::Extent', "Can create new extent objects (2)");
11
12ok($e->IsEmpty, "New, without arguments created extent is empty");
13
14my @s = $e->Size;
15
16is_deeply(\@s, [0,0], "The size of and empty extent is (0,0)");
17
18$e = Geo::GDAL::Extent->new([0,0,1,1]);
19
20ok(!$e->IsEmpty, "New, with arguments created extent is not empty");
21
22@s = $e->Size;
23
24is_deeply(\@s, [1,1], "The size of 0,0,1,1 extent is 1,1");
25
26$e = Geo::GDAL::Extent->new(0,0,1,1);
27
28ok(!$e->IsEmpty, "New, with arguments created extent is not empty (2)");
29
30@s = $e->Size;
31
32is_deeply(\@s, [1,1], "The size of 0,0,1,1 extent is 1,1 (2)");
33
34my $f = Geo::GDAL::Extent->new(1,1,2,2);
35ok(!$e->Overlaps($f), "Touching extents do not overlap");
36$f = Geo::GDAL::Extent->new(0.5,0.5,1.5,1.5);
37ok($e->Overlaps($f), "Overlapping extents overlap");
38
39$f = Geo::GDAL::Extent->new(1,-1,2,0);
40ok(!$e->Overlaps($f), "Touching extents do not overlap");
41$f = Geo::GDAL::Extent->new(0.5,-0.5,1.5,0.5);
42ok($e->Overlaps($f), "Overlapping extents overlap");
43
44$f = Geo::GDAL::Extent->new(-1,-1,0,0);
45ok(!$e->Overlaps($f), "Touching extents do not overlap");
46$f = Geo::GDAL::Extent->new(-0.5,-0.5,0.5,0.5);
47ok($e->Overlaps($f), "Overlapping extents overlap");
48
49$f = Geo::GDAL::Extent->new(-1,1,0,2);
50ok(!$e->Overlaps($f), "Touching extents do not overlap");
51$f = Geo::GDAL::Extent->new(-0.5,0.5,0.5,1.5);
52ok($e->Overlaps($f), "Overlapping extents overlap");
53
54$f = Geo::GDAL::Extent->new(0.5,0.5,1.5,1.5);
55my $g = $e->Overlap($f);
56is_deeply($g, [0.5,0.5,1,1], "Overlap is ok");
57
58$f = Geo::GDAL::Extent->new(1,1,2,2);
59$g = $e->Overlap($f);
60ok($g->IsEmpty, "Overlap of not overlapping extents is empty");
61
62$f = Geo::GDAL::Extent->new(1,1,2,2);
63$f->ExpandToInclude($e);
64is_deeply($f, [0,0,2,2], "Expand to NE");
65
66$f = Geo::GDAL::Extent->new(1,-1,2,0);
67$f->ExpandToInclude($e);
68is_deeply($f, [0,-1,2,1], "Expand to SE");
69
70$f = Geo::GDAL::Extent->new(-1,-1,0,0);
71$f->ExpandToInclude($e);
72is_deeply($f, [-1,-1,1,1], "Expand to SW");
73
74$f = Geo::GDAL::Extent->new(-1,1,0,2);
75$f->ExpandToInclude($e);
76is_deeply($f, [-1,0,1,2], "Expand to NW");
77
78$f = Geo::GDAL::Extent->new();
79$e->ExpandToInclude($f);
80is_deeply($e, [0,0,1,1], "Expand with empty");
81
82$f->ExpandToInclude($e);
83is_deeply($f, [0,0,1,1], "Expand empty");
84