DeviceDescriptor: eliminate obsolete NMEAOut kludge
[xcsoar.git] / src / Geo / GeoClip.hpp
blob3101b93aa2958476375fb718d87d374086380a9d
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_GEO_CLIP_HPP
25 #define XCSOAR_GEO_CLIP_HPP
27 #include "Geo/GeoBounds.hpp"
28 #include "Compiler.h"
30 /**
31 * A rectangle on earth's surface with very simple semantics. Similar
32 * to the RECT struct, it is bounded by four orthogonal lines. Its
33 * goal is to perform fast overlap checks, e.g. to determine if an
34 * object is visible on the screen.
36 class GeoClip : protected GeoBounds {
37 Angle width;
39 public:
40 GeoClip() = default;
41 GeoClip(const GeoBounds &other)
42 :GeoBounds(other), width(GetWidth()) {}
44 protected:
45 /**
46 * Imports a longitude value. To avoid wraparound bugs, all
47 * longitudes used internally in this class are relative to the
48 * "west" bound.
50 gcc_pure
51 Angle ImportLongitude(Angle l) const {
52 return (l - GetWest()).AsDelta();
55 gcc_pure
56 GeoPoint ImportPoint(GeoPoint pt) const {
57 return GeoPoint(ImportLongitude(pt.longitude), pt.latitude);
60 gcc_pure
61 GeoPoint ExportPoint(GeoPoint pt) const {
62 return GeoPoint(pt.longitude + GetWest(), pt.latitude);
65 /**
66 * Clips a point to be bounds.
68 * @param pt the point to be clipped (in and out)
69 * @return false if neither origin nor pt are visible
71 bool ClipPoint(const GeoPoint &origin, GeoPoint &pt) const;
73 /**
74 * Clips a vertex.
76 * @param prev the previous vertex
77 * @param pt the vertex to be clipped (in and out)
78 * @param insert an array of up to two vertices to be inserted after pt
79 * @param next the next vertex
80 * @return the new number of vertices between prev and next (e.g. 0
81 * deletes, 1 preserves, 2 or 3 insert new ones)
83 unsigned ClipVertex(const GeoPoint &prev, GeoPoint &pt, GeoPoint *insert,
84 const GeoPoint &next) const;
86 public:
87 /**
88 * Makes sure that the line does not exceed the bounds. This method
89 * is not designed to perform strict clipping, it is just here to
90 * avoid integer overflows in the graphics drivers.
92 * @return false if the line is definitely outside the bounds
93 * rectangle
95 bool ClipLine(GeoPoint &a, GeoPoint &b) const;
97 /**
98 * Makes sure that the polygon does not exceed the bounds. This
99 * method is not designed to perform strict clipping, it is just
100 * here to avoid integer overflows in the graphics drivers.
102 * The implementation is a specialization of the Sutherland-Hodgman
103 * algorithm, with only horizontal and vertical bound lines.
105 * @param dest a GeoPoint array with enough space for three times
106 * src_length
107 * @return the number of vertices written to dest; if less than 3,
108 * then the polygon can not be drawn
110 unsigned ClipPolygon(GeoPoint *dest,
111 const GeoPoint *src, unsigned src_length) const;
114 #endif