SphereCalculus.h 2.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#ifndef SphereCalculus_H
#define SphereCalculus_H

#include <QObject>
#include <QGeoCoordinate>
#include <QPointF>
#include <QLineF>

#include "QGCGeo.h"

// Abstract class providing methods to do calculations on objects located on a sphere (e.g. earth)
class SphereCalculus : public QObject
{
    Q_OBJECT
public:
    SphereCalculus(QObject *parent = nullptr);
    SphereCalculus(const SphereCalculus &other, QObject *parent = nullptr);
    SphereCalculus &operator=(const SphereCalculus &other);

    typedef QPair<QGeoCoordinate, QGeoCoordinate> Line;


    enum JoinPolygonError { NotSimplePolygon1, PolygonJoined, NotSimplePolygon2, Disjoint, PathSizeLow};
    enum IntersectionType { NoIntersection, EdgeIntersection, InteriorIntersection, Error};
    enum DijkstraError    { NoPathFound, PathFound, NotSimplePolygon};

    // Property setters
    void setEpsilonMeter(double epsilon);

    // Property getters
    double epsilonMeter() const;

    // Member Methodes
    int                     closestVertexIndex  (const QList<QGeoCoordinate> &path, const QGeoCoordinate &coordinate);
    QGeoCoordinate          closestVertex       (const QList<QGeoCoordinate> &path, const QGeoCoordinate &coordinate);
    int                     nextPolygonIndex    (int pathsize, int index);
    int                     previousPolygonIndex(int pathsize, int index);
    JoinPolygonError        joinPolygon         (QList<QGeoCoordinate> polygon1, QList<QGeoCoordinate> polygon2,
                                                    QList<QGeoCoordinate> &joinedPolygon);
    IntersectionType        intersects          (const Line &line1, const Line &line2,
                                                    QGeoCoordinate &intersectionPt);
    QList<IntersectionType> intersects          (const QList<QGeoCoordinate> &polygon, const Line &line,
                                                    QList<QGeoCoordinate> &intersectionList,  QList<QPair<int, int>> &neighbourList);
    bool                    intersects          (const QList<QGeoCoordinate> &polygon, const Line &line);
    DijkstraError           dijkstraPath        (const QList<QGeoCoordinate> &polygon, const QGeoCoordinate& start,
                                                    const QGeoCoordinate& end, QList<QGeoCoordinate>& dijkstraPath);
    bool                    isSimplePolygon     (const QList<QGeoCoordinate> &polygon);
    bool                    hasClockwiseWinding (const QList<QGeoCoordinate> &path);
    void                    reversePath         (QList<QGeoCoordinate> &path);
    bool                    offsetPolygon       (QList<QGeoCoordinate> &polygon, double offset);



signals:

public slots:

private:
    double distanceInsidePolygon (const QGeoCoordinate& c1, const QGeoCoordinate& c2, QList<QGeoCoordinate> polygon);

    double _epsilonMeter; // The accuracy used for distance calculations (unit: m).

};

#endif // SphereCalculus_H