summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-09-03 16:08:07 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-09-03 16:08:07 (GMT)
commitdf015efc2e70b80d23bcad683d7f819904009af4 (patch)
treeb0011b148df5e0432e367425af9c221ea4ef593c
parent61e174ee6913582f4584a664e8e00abead867a6c (diff)
Avoid static_casts and redundant code
-rw-r--r--tools/osm-simplify/NodeReducer.cpp50
-rw-r--r--tools/osm-simplify/NodeReducer.h33
2 files changed, 35 insertions, 48 deletions
diff --git a/tools/osm-simplify/NodeReducer.cpp b/tools/osm-simplify/NodeReducer.cpp
index 54909d2..5ae074b 100644
--- a/tools/osm-simplify/NodeReducer.cpp
+++ b/tools/osm-simplify/NodeReducer.cpp
@@ -39,7 +39,7 @@ void NodeReducer::process()
else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
GeoDataLinearRing* prevRing = static_cast<GeoDataLinearRing*>(placemark->geometry());
- GeoDataLinearRing* reducedRing = static_cast<GeoDataLinearRing*>(reduce(prevRing));
+ GeoDataLinearRing* reducedRing = reduce(prevRing);
placemark->setGeometry(reducedRing);
}
@@ -47,12 +47,12 @@ void NodeReducer::process()
GeoDataPolygon* reducedPolygon = new GeoDataPolygon;
GeoDataPolygon* prevPolygon = static_cast<GeoDataPolygon*>(placemark->geometry());
GeoDataLinearRing* prevRing = &(prevPolygon->outerBoundary());
- GeoDataLinearRing* reducedRing = static_cast<GeoDataLinearRing*>(reduce(prevRing));
+ GeoDataLinearRing* reducedRing = reduce(prevRing);
reducedPolygon->setOuterBoundary(*reducedRing);
QVector<GeoDataLinearRing>& innerBoundaries = prevPolygon->innerBoundaries();
for(int i = 0; i < innerBoundaries.size(); i++) {
prevRing = &innerBoundaries[i];
- reducedRing = static_cast<GeoDataLinearRing*>(reduce(prevRing));
+ reducedRing = reduce(prevRing);
reducedPolygon->appendInnerBoundary(*reducedRing);
}
placemark->setGeometry(reducedPolygon);
@@ -61,50 +61,6 @@ void NodeReducer::process()
qDebug()<<"Total nodes reduced: "<<m_count<<endl;
}
-GeoDataLineString* NodeReducer::reduce(GeoDataLineString* lineString)
-{
- qint64 prevSize = lineString->size();
-
- GeoDataLineString* reducedLine;
- if(lineString->nodeType() == GeoDataTypes::GeoDataLineStringType) {
- if(prevSize < 2) {
- reducedLine = new GeoDataLineString(*lineString);
- return reducedLine;
- }
- else{
- reducedLine = new GeoDataLineString;
- }
- }
- else if(lineString->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
- if(prevSize < 2) {
- reducedLine = new GeoDataLinearRing(*lineString);
- return reducedLine;
- }
- reducedLine = new GeoDataLinearRing;
- } else {
- Q_ASSERT(false && "Unexpected GeoDataLineString subtype");
- return nullptr;
- }
-
-
- QVector<GeoDataCoordinates>::iterator itCoords = lineString->begin();
- GeoDataCoordinates currentCoords = *itCoords;
- reducedLine->append(*itCoords);
- ++itCoords;
- for(; itCoords != (lineString->end() - 1); ++itCoords) {
- if(distanceSphere( currentCoords, *itCoords ) >= m_resolution) {
- currentCoords = *itCoords;
- reducedLine->append(*itCoords);
- }
- }
- reducedLine->append(*itCoords);
-
- qint64 reducedSize = reducedLine->size();
- m_count += (prevSize - reducedSize);
- return reducedLine;
- //qDebug()<<"Nodes reduced "<<(prevSize - reducedSize)<<endl;
-}
-
qreal NodeReducer::resolutionForLevel(int level) {
switch (level) {
case 0:
diff --git a/tools/osm-simplify/NodeReducer.h b/tools/osm-simplify/NodeReducer.h
index 72bbbde..3064dec 100644
--- a/tools/osm-simplify/NodeReducer.h
+++ b/tools/osm-simplify/NodeReducer.h
@@ -13,6 +13,7 @@
#include "PlacemarkFilter.h"
#include "GeoDataLineString.h"
+#include "MarbleMath.h"
class NodeReducer : public PlacemarkFilter {
public:
@@ -20,7 +21,37 @@ public:
void process() override;
private:
- GeoDataLineString* reduce(GeoDataLineString* lineString);
+ template<class T>
+ T* reduce(T* lineString)
+ {
+ qint64 prevSize = lineString->size();
+
+ T* reducedLine;
+ if (prevSize < 2) {
+ reducedLine = new T(*lineString);
+ return reducedLine;
+ } else {
+ reducedLine = new T;
+ }
+
+ QVector<GeoDataCoordinates>::iterator itCoords = lineString->begin();
+ GeoDataCoordinates currentCoords = *itCoords;
+ reducedLine->append(*itCoords);
+ ++itCoords;
+ for (; itCoords != (lineString->end() - 1); ++itCoords) {
+ if (distanceSphere( currentCoords, *itCoords ) >= m_resolution) {
+ currentCoords = *itCoords;
+ reducedLine->append(*itCoords);
+ }
+ }
+ reducedLine->append(*itCoords);
+
+ qint64 reducedSize = reducedLine->size();
+ m_count += (prevSize - reducedSize);
+ return reducedLine;
+ //qDebug()<<"Nodes reduced "<<(prevSize - reducedSize)<<endl;
+ }
+
static qreal resolutionForLevel(int level);
qreal m_resolution;