1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // Copyright 2014	   Gábor Péterffy <peterffy95@gmail.com>
3 //
4 
5 #ifndef MARBLE_AZIMUTHALPROJECTIONPRIVATE_H
6 #define MARBLE_AZIMUTHALPROJECTIONPRIVATE_H
7 
8 #include "AbstractProjection_p.h"
9 
10 
11 namespace Marble
12 {
13 
14 // Maximum amount of nodes that are created automatically between actual nodes.
15 static const int maxTessellationNodes = 200;
16 
17 
18 class AzimuthalProjection;
19 
20 class AzimuthalProjectionPrivate : public AbstractProjectionPrivate
21 {
22 public:
AzimuthalProjectionPrivate(AzimuthalProjection * parent)23     explicit AzimuthalProjectionPrivate( AzimuthalProjection * parent )
24         : AbstractProjectionPrivate( parent ),
25           q_ptr( parent )
26     {
27 
28     }
29 
~AzimuthalProjectionPrivate()30     ~AzimuthalProjectionPrivate() override {};
31 
32     // This method tessellates a line segment in a way that the line segment
33     // follows great circles. The count parameter specifies the
34     // number of nodes generated for the polygon. If the
35     // clampToGround flag is added the polygon contains count + 2
36     // nodes as the clamped down start and end node get added.
37 
38     // In order to ensure proper performance the current algorithm
39     // determines whether the linestring disappears
40     // behind the horizon by evaluating the actual node coordinates of the
41     // linestring.
42     // However in some cases only a tessellated portion of the linestring
43     // disappears behind the globe. In this case non-closed linestrings
44     // can still be cut into separate polygons without problems.
45     // But for linearrings the horizon detection at this stage happens too
46     // late already to be taken into account for rendering.
47     // The allowLatePolygonCut parameter allows to split at least
48     // non-closed linestrings properly at this point.
49 
50     void tessellateLineSegment(  const GeoDataCoordinates &aCoords,
51                                 qreal ax, qreal ay,
52                                 const GeoDataCoordinates &bCoords,
53                                 qreal bx, qreal by,
54                                 QVector<QPolygonF*> &polygons,
55                                 const ViewportParams *viewport,
56                                 TessellationFlags f = nullptr,
57                                 bool allowLatePolygonCut = false ) const;
58 
59     void processTessellation(   const GeoDataCoordinates &previousCoords,
60                                const GeoDataCoordinates &currentCoords,
61                                int count,
62                                QVector<QPolygonF*> &polygons,
63                                const ViewportParams *viewport,
64                                TessellationFlags f = nullptr,
65                                bool allowLatePolygonCut = false ) const;
66 
67     void crossHorizon( const GeoDataCoordinates & bCoord,
68                        QVector<QPolygonF*> &polygons,
69                        const ViewportParams *viewport,
70                        bool allowLatePolygonCut = false
71                      ) const;
72 
73     virtual bool lineStringToPolygon( const GeoDataLineString &lineString,
74                               const ViewportParams *viewport,
75                               QVector<QPolygonF*> &polygons ) const;
76 
77     void horizonToPolygon( const ViewportParams *viewport,
78                            const GeoDataCoordinates & disappearCoords,
79                            const GeoDataCoordinates & reappearCoords,
80                            QPolygonF* ) const;
81 
82     GeoDataCoordinates findHorizon( const GeoDataCoordinates & previousCoords,
83                                     const GeoDataCoordinates & currentCoords,
84                                     const ViewportParams *viewport,
85                                     TessellationFlags f = nullptr) const;
86 
87     GeoDataCoordinates doFindHorizon(const GeoDataCoordinates & previousCoords,
88                                      const GeoDataCoordinates & currentCoords,
89                                      const ViewportParams *viewport,
90                                      TessellationFlags f,
91                                      bool currentHide,
92                                      int recursionCounter) const;
93 
94     bool globeHidesPoint( const GeoDataCoordinates &coordinates,
95                           const ViewportParams *viewport ) const;
96 
97     AzimuthalProjection * const q_ptr;
98 
99     Q_DECLARE_PUBLIC( AzimuthalProjection )
100 };
101 
102 } // namespace Marble
103 
104 #endif
105