Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / TestGeoBounds.cpp
blob3984e7c49b4dba37a1361b6695bdba5cbd8dc231
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Geo/GeoBounds.hpp"
24 #include "TestUtil.hpp"
26 #include <stdio.h>
28 static GeoBounds
29 MakeGeoBounds(int west, int north, int east, int south)
31 return GeoBounds(GeoPoint(Angle::Degrees(west), Angle::Degrees(north)),
32 GeoPoint(Angle::Degrees(east), Angle::Degrees(south)));
35 int main(int argc, char **argv)
37 plan_tests(38);
39 GeoPoint g(Angle::Degrees(2), Angle::Degrees(4));
41 GeoBounds b(g);
43 ok1(equals(b.GetEast(), 2));
44 ok1(equals(b.GetWest(), 2));
45 ok1(equals(b.GetNorth(), 4));
46 ok1(equals(b.GetSouth(), 4));
48 ok1(b.IsEmpty());
50 g.latitude = Angle::Degrees(6);
51 g.longitude = Angle::Degrees(8);
52 b.Extend(g);
54 ok1(equals(b.GetEast(), 8));
55 ok1(equals(b.GetWest(), 2));
56 ok1(equals(b.GetNorth(), 6));
57 ok1(equals(b.GetSouth(), 4));
59 ok1(!b.IsEmpty());
61 g = b.GetCenter();
62 ok1(equals(g.latitude, 5));
63 ok1(equals(g.longitude, 5));
65 ok1(b.IsInside(Angle::Degrees(7), Angle::Degrees(4.5)));
66 ok1(!b.IsInside(Angle::Degrees(9), Angle::Degrees(4.5)));
67 ok1(!b.IsInside(Angle::Degrees(7), Angle::Degrees(1)));
68 ok1(!b.IsInside(Angle::Degrees(9), Angle::Degrees(1)));
70 b = b.Scale(fixed(2));
72 ok1(equals(b.GetEast(), 11));
73 ok1(equals(b.GetWest(), -1));
74 ok1(equals(b.GetNorth(), 7));
75 ok1(equals(b.GetSouth(), 3));
77 b = b.Scale(fixed(0.5));
79 ok1(equals(b.GetEast(), 8));
80 ok1(equals(b.GetWest(), 2));
81 ok1(equals(b.GetNorth(), 6));
82 ok1(equals(b.GetSouth(), 4));
84 GeoBounds c = MakeGeoBounds(2, 6, 8, 4);
85 ok1(c.Overlaps(b));
86 ok1(c.IntersectWith(b));
87 ok1(equals(c.GetWest(), 2));
88 ok1(equals(c.GetNorth(), 6));
89 ok1(equals(c.GetEast(), 8));
90 ok1(equals(c.GetSouth(), 4));
92 GeoBounds d = MakeGeoBounds(2, 6, 7, 5);
93 ok1(c.Overlaps(d));
94 ok1(c.IntersectWith(d));
95 ok1(equals(c.GetWest(), 2));
96 ok1(equals(c.GetNorth(), 6));
97 ok1(equals(c.GetEast(), 7));
98 ok1(equals(c.GetSouth(), 5));
100 d = MakeGeoBounds(8, 6, 1, 5);
101 ok1(!c.Overlaps(d));
102 ok1(!c.IntersectWith(d));
104 return exit_status();