1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/data/area.h

63 lines
1.3 KiB
C
Raw Normal View History

2019-01-31 01:46:53 +01:00
#ifndef AREA_H
#define AREA_H
#include <QString>
#include <QList>
#include "polygon.h"
class Area
2019-01-31 01:46:53 +01:00
{
public:
2020-12-02 23:58:11 +01:00
Area() {}
Area(const RectC &rect)
{
QVector<Coordinates> v(4);
v[0] = Coordinates(rect.left(), rect.top());
v[1] = Coordinates(rect.right(), rect.top());
v[2] = Coordinates(rect.right(), rect.bottom());
v[3] = Coordinates(rect.left(), rect.bottom());
_polygons.reserve(1);
_polygons.append(v);
_boundingRect = RectC(v.at(0), v.at(2));
}
Area(const Polygon &polygon)
{
_polygons.reserve(1);
_polygons.append(polygon);
_boundingRect = polygon.boundingRect();
2020-12-02 23:58:11 +01:00
}
const QString &name() const {return _name;}
const QString &description() const {return _desc;}
const QList<Polygon> &polygons() const {return _polygons;}
const RectC &boundingRect() const {return _boundingRect;}
2019-01-31 01:46:53 +01:00
bool isValid() const
{
if (_polygons.isEmpty())
2019-01-31 01:46:53 +01:00
return false;
for (int i = 0; i < _polygons.size(); i++)
if (!_polygons.at(i).isValid())
2019-01-31 01:46:53 +01:00
return false;
return true;
}
void append(const Polygon &polygon)
2019-01-31 01:46:53 +01:00
{
_polygons.append(polygon);
_boundingRect |= polygon.boundingRect();
2019-01-31 01:46:53 +01:00
}
void setName(const QString &name) {_name = name;}
void setDescription(const QString &desc) {_desc = desc;}
2019-01-31 01:46:53 +01:00
private:
QList<Polygon> _polygons;
2019-01-31 01:46:53 +01:00
QString _name;
QString _desc;
RectC _boundingRect;
2019-01-31 01:46:53 +01:00
};
#endif // AREA_H