1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 19:52:09 +01:00

Some more micro-optimizations & code cleanup

This commit is contained in:
Martin Tůma 2023-05-16 23:03:07 +02:00
parent 04c203625f
commit cf81a90865
5 changed files with 16 additions and 19 deletions

View File

@ -3,6 +3,7 @@
#include <cmath>
#include <QDebug>
#include "hash.h"
#define deg2rad(d) (((d)*M_PI)/180.0)
#define rad2deg(d) (((d)*180.0)/M_PI)
@ -48,6 +49,11 @@ inline bool operator<(const Coordinates &c1, const Coordinates &c2)
return (c1.lat() < c2.lat());
}
inline HASH_T qHash(const Coordinates &c)
{
return qHash(QPair<double, double>(c.lon(), c.lat()));
}
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const Coordinates &c);
#endif // QT_NO_DEBUG

View File

@ -584,8 +584,10 @@ bool MapData::readPaths(const VectorTile *tile, int zoom, QList<Path> *list)
if (!subfile.seek(subfile.pos() + val))
return false;
paths.reserve(paths[zoom - info.min]);
for (unsigned i = 0; i < paths[zoom - info.min]; i++) {
Path p(subfile.offset() + subfile.pos());
Path p;
qint32 lon = 0, lat = 0;
if (!(subfile.readVUInt32(unused) && subfile.readUInt16(bitmap)
@ -665,6 +667,8 @@ bool MapData::readPoints(const VectorTile *tile, int zoom, QList<Point> *list)
if (!subfile.readVUInt32(unused))
return false;
list->reserve(points[zoom - info.min]);
for (unsigned i = 0; i < points[zoom - info.min]; i++) {
qint32 lat, lon;

View File

@ -36,10 +36,7 @@ public:
};
struct Point {
Point(const Coordinates &c) : coordinates(c)
{
id = (quint64)qHash(QPair<double, double>(c.lon(), c.lat()));
}
Point(const Coordinates &c) : id(qHash(c)), coordinates(c) {}
quint64 id;
Coordinates coordinates;
@ -48,9 +45,6 @@ public:
};
struct Path {
Path(quint64 id) : id(id) {}
quint64 id;
Polygon poly;
QVector<Tag> tags;
Coordinates labelPos;
@ -59,8 +53,6 @@ public:
bool operator<(const Path &other) const
{return layer < other.layer;}
bool operator==(const Path &other) const
{return (id == other.id);}
};
RectC bounds() const;
@ -190,11 +182,6 @@ inline HASH_T qHash(const MapData::Tag &tag)
return ::qHash(tag.key) ^ ::qHash(tag.value);
}
inline HASH_T qHash(const MapData::Path &path)
{
return ::qHash(path.id);
}
}
#ifndef QT_NO_DEBUG

View File

@ -224,9 +224,10 @@ QPainterPath RasterTile::painterPath(const Polygon &polygon, bool curve) const
}
path.quadTo(p2, p3);
} else {
path.moveTo(ll2xy(subpath.first()));
for (int j = 1; j < subpath.size(); j++)
path.lineTo(ll2xy(subpath.at(j)));
QVector<QPointF> p(subpath.size());
for (int j = 0; j < subpath.size(); j++)
p[j] = ll2xy(subpath.at(j));
path.addPolygon(p);
}
}

View File

@ -14,7 +14,6 @@ public:
: _file(file), _offset(offset), _size(size), _pos(-1),
_blockNum(-1), _blockPos(-1) {}
quint64 offset() const {return _offset;}
quint64 pos() const {return _pos;}
bool seek(quint64 pos);