QGCGeoBoundingCube.h 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/


#pragma once

#include <QObject>
#include <QGeoCoordinate>

// A bounding "cube" for small surface areas (doesn't take in consideration earth's curvature)
// Coordinate system makes NW Up Left Bottom (0,0,0) and SE Bottom Right Top (y,x,z)
class QGCGeoBoundingCube : public QObject {
    Q_OBJECT
public:
    QGCGeoBoundingCube(const QGCGeoBoundingCube& other)
22
        : QObject()
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    {
        pointNW = other.pointNW;
        pointSE = other.pointSE;
    }

    QGCGeoBoundingCube()
        : pointNW(QGeoCoordinate(MaxSouth, MaxEast, MaxAlt))
        , pointSE(QGeoCoordinate(MaxNorth, MaxWest, MinAlt))
    {
    }

    QGCGeoBoundingCube(QGeoCoordinate p1, QGeoCoordinate p2)
        : pointNW(p1)
        , pointSE(p2)
    {
    }

    Q_PROPERTY(QGeoCoordinate pointNW MEMBER pointNW CONSTANT)
    Q_PROPERTY(QGeoCoordinate pointSE MEMBER pointNW CONSTANT)

43 44 45
    Q_INVOKABLE void            reset   ();
    Q_INVOKABLE bool            isValid () const;
    Q_INVOKABLE QGeoCoordinate  center  () const;
46 47 48 49 50 51

    inline bool operator ==(const QGCGeoBoundingCube& other)
    {
        return pointNW == other.pointNW && pointSE == other.pointSE;
    }

52 53
    bool operator ==(const QList<QGeoCoordinate>& coords) const;

54 55 56 57 58 59 60 61 62 63 64 65 66
    inline bool operator !=(const QGCGeoBoundingCube& other)
    {
        return !(*this == other);
    }

    inline const QGCGeoBoundingCube& operator =(const QGCGeoBoundingCube& other)
    {
        pointNW = other.pointNW;
        pointSE = other.pointSE;
        return *this;
    }

    //-- 2D
67
    QList<QGeoCoordinate> polygon2D(double clipTo = 0.0) const;
68 69 70 71 72

    Q_INVOKABLE double width    () const;
    Q_INVOKABLE double height   () const;
    Q_INVOKABLE double area     () const;
    Q_INVOKABLE double radius   () const;
73 74 75 76 77 78 79 80 81 82

    QGeoCoordinate  pointNW;
    QGeoCoordinate  pointSE;
    static double MaxAlt;
    static double MinAlt;
    static double MaxNorth;
    static double MaxSouth;
    static double MaxWest;
    static double MaxEast;
};