Commit 2a3ae917 authored by Valentin Platzgummer's avatar Valentin Platzgummer

after QList -> QVector, circ survey 4 times faster

parent 19b98503
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -88,38 +88,38 @@ QPointF Circle::origin() const ...@@ -88,38 +88,38 @@ QPointF Circle::origin() const
/*! /*!
* \fn QList<QPointF> Circle::approximate(int numberOfCorners) * \fn QVector<QPointF> Circle::approximate(int numberOfCorners)
* Returns a polygon with \a numberOfCorners corners which approximates the circle. * Returns a polygon with \a numberOfCorners corners which approximates the circle.
* *
* \sa QPointF * \sa QPointF
*/ */
QList<QPointF> Circle::approximate(int numberOfCorners) const QVector<QPointF> Circle::approximate(int numberOfCorners) const
{ {
if ( numberOfCorners < 3) if ( numberOfCorners < 3)
return QList<QPointF>(); return QVector<QPointF>();
return approximateSektor(numberOfCorners+1, 0, 2*M_PI); return approximateSektor(numberOfCorners+1, 0, 2*M_PI);
} }
QList<QPointF> Circle::approximate(double angleDiscretisation) const QVector<QPointF> Circle::approximate(double angleDiscretisation) const
{ {
return approximateSektor(angleDiscretisation, 0, 2*M_PI); return approximateSektor(angleDiscretisation, 0, 2*M_PI);
} }
QList<QPointF> Circle::approximateSektor(int numberOfCorners, double alpha1, double alpha2) const QVector<QPointF> Circle::approximateSektor(int numberOfCorners, double alpha1, double alpha2) const
{ {
if ( numberOfCorners < 2) { if ( numberOfCorners < 2) {
qWarning("numberOfCorners < 2"); qWarning("numberOfCorners < 2");
return QList<QPointF>(); return QVector<QPointF>();
} }
return approximateSektor(PlanimetryCalculus::truncateAngle(alpha2-alpha1)/double(numberOfCorners-1), alpha1, alpha2); return approximateSektor(PlanimetryCalculus::truncateAngle(alpha2-alpha1)/double(numberOfCorners-1), alpha1, alpha2);
} }
QList<QPointF> Circle::approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const QVector<QPointF> Circle::approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const
{ {
using namespace PlanimetryCalculus; using namespace PlanimetryCalculus;
// check if input is valid // check if input is valid
if ( qFuzzyCompare(alpha1, alpha2) ) if ( qFuzzyCompare(alpha1, alpha2) )
return QList<QPointF>(); return QVector<QPointF>();
alpha1 = truncateAngle(alpha1); alpha1 = truncateAngle(alpha1);
alpha2 = truncateAngle(alpha2); alpha2 = truncateAngle(alpha2);
...@@ -130,10 +130,10 @@ QList<QPointF> Circle::approximateSektor(double angleDiscretisation, double alph ...@@ -130,10 +130,10 @@ QList<QPointF> Circle::approximateSektor(double angleDiscretisation, double alph
// check if input is valid // check if input is valid
if ( qFuzzyIsNull(angleDiscretisation)) if ( qFuzzyIsNull(angleDiscretisation))
return QList<QPointF>(); return QVector<QPointF>();
QList<QPointF> sector; QVector<QPointF> sector;
double currentAngle = alpha1; double currentAngle = alpha1;
// how many nodes? // how many nodes?
int j = floor(fabs(deltaAlpha/angleDiscretisation)); int j = floor(fabs(deltaAlpha/angleDiscretisation));
......
...@@ -27,10 +27,10 @@ public: ...@@ -27,10 +27,10 @@ public:
QPointF origin() const; QPointF origin() const;
// Member methodes // Member methodes
QList<QPointF> approximate (int numberOfCorners) const; QVector<QPointF> approximate (int numberOfCorners) const;
QList<QPointF> approximate (double angleDiscretisation) const; QVector<QPointF> approximate (double angleDiscretisation) const;
QList<QPointF> approximateSektor(int numberOfCorners, double alpha1, double alpha2) const; QVector<QPointF> approximateSektor(int numberOfCorners, double alpha1, double alpha2) const;
QList<QPointF> approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const; QVector<QPointF> approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const;
void toCoordinate (QPointF &toCoordinate, double alpha) const; void toCoordinate (QPointF &toCoordinate, double alpha) const;
QPointF toCoordinate (double alpha) const; QPointF toCoordinate (double alpha) const;
bool isNull() const; bool isNull() const;
......
...@@ -462,14 +462,14 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -462,14 +462,14 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
// generate transects // generate transects
QList<QList<QPointF>> transectPath; QVector<QVector<QPointF>> transectPath;
double r = r_min; double r = r_min;
while (r < r_max) { while (r < r_max) {
Circle circle(r, origin); Circle circle(r, origin);
QList<QPointFList> intersectPoints; QVector<QPointFVector> intersectPoints;
QList<IntersectType> typeList; QVector<IntersectType> typeList;
QList<QPair<int, int>> neighbourList; QVector<QPair<int, int>> neighbourList;
if (intersects(circle, surveyPolygon, intersectPoints, neighbourList, typeList)) { if (intersects(circle, surveyPolygon, intersectPoints, neighbourList, typeList)) {
// intersection Points between circle and polygon, entering polygon // intersection Points between circle and polygon, entering polygon
...@@ -480,7 +480,7 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -480,7 +480,7 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
QPointFList exitPoints; QPointFList exitPoints;
// determine entryPoints and exit Points // determine entryPoints and exit Points
for (int j = 0; j < intersectPoints.size(); j++) { for (int j = 0; j < intersectPoints.size(); j++) {
QList<QPointF> intersects = intersectPoints[j]; // one pt = tangent, two pt = sekant QVector<QPointF> intersects = intersectPoints[j]; // one pt = tangent, two pt = sekant
QPointF p1 = surveyPolygon[neighbourList[j].first]; QPointF p1 = surveyPolygon[neighbourList[j].first];
QPointF p2 = surveyPolygon[neighbourList[j].second]; QPointF p2 = surveyPolygon[neighbourList[j].second];
...@@ -544,7 +544,7 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -544,7 +544,7 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
// qDebug() << "dAlpha" << dAlpha; // qDebug() << "dAlpha" << dAlpha;
// qDebug() << "numNodes" << numNodes; // qDebug() << "numNodes" << numNodes;
QList<QPointF> sectorPath = circle.approximateSektor(numNodes, alpha1, alpha2); QVector<QPointF> sectorPath = circle.approximateSektor(numNodes, alpha1, alpha2);
// use shortestPath() here if necessary, could be a problem if dr >> // use shortestPath() here if necessary, could be a problem if dr >>
if (sectorPath.size() > 0) if (sectorPath.size() > 0)
transectPath.append(sectorPath); transectPath.append(sectorPath);
...@@ -552,7 +552,7 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -552,7 +552,7 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
} else if (originInside) { } else if (originInside) {
// circle fully inside polygon // circle fully inside polygon
int numNodes = int(ceil(2*M_PI/dalpha)) + 1; int numNodes = int(ceil(2*M_PI/dalpha)) + 1;
QList<QPointF> sectorPath = circle.approximateSektor(numNodes, 0, 2*M_PI); QVector<QPointF> sectorPath = circle.approximateSektor(numNodes, 0, 2*M_PI);
// use shortestPath() here if necessary, could be a problem if dr >> // use shortestPath() here if necessary, could be a problem if dr >>
transectPath.append(sectorPath); transectPath.append(sectorPath);
} }
...@@ -579,10 +579,10 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -579,10 +579,10 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
// optimize path to snake or zig-zag pattern // optimize path to snake or zig-zag pattern
bool isSnakePattern = _isSnakePath.rawValue().toBool(); bool isSnakePattern = _isSnakePath.rawValue().toBool();
QList<QPointF> currentSection = transectPath.takeFirst(); QVector<QPointF> currentSection = transectPath.takeFirst();
if ( currentSection.isEmpty() ) if ( currentSection.isEmpty() )
return; return;
QList<QList<QPointF>> optiPath; // optimized path QVector<QPointF> optiPath; // optimized path
while( !transectPath.empty() ) { while( !transectPath.empty() ) {
optiPath.append(currentSection); optiPath.append(currentSection);
QPointF endVertex = currentSection.last(); QPointF endVertex = currentSection.last();
...@@ -616,24 +616,21 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -616,24 +616,21 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
// convert to CoordInfo_t // convert to CoordInfo_t
for ( QList<QPointF> &transect : optiPath) { if (_reverse.rawValue().toBool())
// for ( const QList<QPointF> &transect : fullPath) { PolygonCalculus::reversePath(optiPath);
if (_reverse.rawValue().toBool())
PolygonCalculus::reversePath(transect); QList<QGeoCoordinate> geoPath = toGeo(optiPath, _referencePoint);
QList<CoordInfo_t> transectList;
QList<QGeoCoordinate> geoPath = toGeo(transect, _referencePoint); for ( const QGeoCoordinate &coordinate : geoPath) {
QList<CoordInfo_t> transectList; CoordInfo_t coordinfo = {coordinate, CoordTypeInterior};
for ( const QGeoCoordinate &coordinate : geoPath) { transectList.append(coordinfo);
CoordInfo_t coordinfo = {coordinate, CoordTypeInterior};
transectList.append(coordinfo);
}
_transects.append(transectList);
} }
_transects.append(transectList);
qDebug() << "CircularSurveyComplexItem::_rebuildTransectsPhase1(): calls: " << _updateCounter; qDebug() << "CircularSurveyComplexItem::_rebuildTransectsPhase1(): calls: " << _updateCounter;
auto delta = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startTime).count(); auto delta = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
qDebug() << "CircularSurveyComplexItem::_rebuildTransectsPhase1(): time: " << delta; qDebug() << "CircularSurveyComplexItem::_rebuildTransectsPhase1(): time: " << delta << " ms";
qDebug() << sizeof(QPointF); //qDebug() << sizeof(QPointF);
} }
......
...@@ -101,5 +101,14 @@ namespace GeoUtilities { ...@@ -101,5 +101,14 @@ namespace GeoUtilities {
return coordinates; return coordinates;
} }
QGeoList toGeo(const QPointFVector &points, const QGeoCoordinate &origin)
{
QGeoList coordinates;
for ( auto point : points)
coordinates.append(toGeo(point, origin));
return coordinates;
}
} }
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
namespace GeoUtilities { namespace GeoUtilities {
typedef QList<QVector3D> QVector3DList; typedef QList<QVector3D> QVector3DList;
typedef QList<QPointF> QPointFList; typedef QList<QPointF> QPointFList;
typedef QList<QGeoCoordinate> QGeoList; typedef QVector<QPointF> QPointFVector;
typedef QList<QGeoCoordinate> QGeoList;
const double earthRadius = 6378137; // meter const double earthRadius = 6378137; // meter
...@@ -21,6 +22,7 @@ namespace GeoUtilities { ...@@ -21,6 +22,7 @@ namespace GeoUtilities {
QGeoList toGeo (const QVector3DList &points, const QGeoCoordinate &origin); QGeoList toGeo (const QVector3DList &points, const QGeoCoordinate &origin);
QGeoCoordinate toGeo (const QPointF &point, const QGeoCoordinate &origin); QGeoCoordinate toGeo (const QPointF &point, const QGeoCoordinate &origin);
QGeoList toGeo (const QPointFList &points, const QGeoCoordinate &origin); QGeoList toGeo (const QPointFList &points, const QGeoCoordinate &origin);
QGeoList toGeo (const QPointFVector &points, const QGeoCoordinate &origin);
QVector3D toCartesian (const QGeoCoordinate &coordinate, const QGeoCoordinate &origin); QVector3D toCartesian (const QGeoCoordinate &coordinate, const QGeoCoordinate &origin);
QVector3DList toCartesian (const QGeoList &coordinates, const QGeoCoordinate &origin); QVector3DList toCartesian (const QGeoList &coordinates, const QGeoCoordinate &origin);
QPointF toCartesian2D (const QGeoCoordinate &point, const QGeoCoordinate &origin); QPointF toCartesian2D (const QGeoCoordinate &point, const QGeoCoordinate &origin);
......
...@@ -12,7 +12,7 @@ namespace PlanimetryCalculus { ...@@ -12,7 +12,7 @@ namespace PlanimetryCalculus {
\sa QPointF, Circle \sa QPointF, Circle
*/ */
bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints, IntersectType &type, bool calcInstersect) bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints, IntersectType &type, bool calcInstersect)
{ {
if (!circle.isNull() && ! line.isNull()) { if (!circle.isNull() && ! line.isNull()) {
QPointF translationVector = line.p1(); QPointF translationVector = line.p1();
...@@ -87,7 +87,7 @@ namespace PlanimetryCalculus { ...@@ -87,7 +87,7 @@ namespace PlanimetryCalculus {
\sa Circle \sa Circle
*/ */
bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &intersectionPoints, IntersectType type, bool calcIntersection) bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints, IntersectType type, bool calcIntersection)
{ {
if (!circle1.isNull() && !circle2.isNull()) { if (!circle1.isNull() && !circle2.isNull()) {
double r1 = circle1.radius(); double r1 = circle1.radius();
...@@ -180,7 +180,7 @@ namespace PlanimetryCalculus { ...@@ -180,7 +180,7 @@ namespace PlanimetryCalculus {
} }
} }
void rotateReference(QPointFList &points, double alpha) void rotateReference(QPointFVector &points, double alpha)
{ {
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
rotateReference(points[i], alpha); rotateReference(points[i], alpha);
...@@ -196,7 +196,7 @@ namespace PlanimetryCalculus { ...@@ -196,7 +196,7 @@ namespace PlanimetryCalculus {
rotateReference(point, alpha/180*M_PI); rotateReference(point, alpha/180*M_PI);
} }
void rotateReferenceDegree(QPointFList &points, double alpha) void rotateReferenceDegree(QPointFVector &points, double alpha)
{ {
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
rotateReferenceDegree(points[i], alpha); rotateReferenceDegree(points[i], alpha);
...@@ -212,12 +212,12 @@ namespace PlanimetryCalculus { ...@@ -212,12 +212,12 @@ namespace PlanimetryCalculus {
*/ */
bool intersects(const Circle &circle, const QLineF &line) bool intersects(const Circle &circle, const QLineF &line)
{ {
QPointFList dummyList; QPointFVector dummyList;
IntersectType type = NoIntersection; IntersectType type = NoIntersection;
return intersects(circle, line, dummyList, type, false /* calculate intersection points*/); return intersects(circle, line, dummyList, type, false /* calculate intersection points*/);
} }
bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints) bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints)
{ {
IntersectType type = NoIntersection; IntersectType type = NoIntersection;
return intersects(circle, line, intersectionPoints, type, true /* calculate intersection points*/); return intersects(circle, line, intersectionPoints, type, true /* calculate intersection points*/);
...@@ -396,15 +396,15 @@ angle ...@@ -396,15 +396,15 @@ angle
* \a neighbourList has entries of type \c {QPair<int, int>}, where \c{pair.first} would contain 1 and \c{pair.second} would contain 2, when * \a neighbourList has entries of type \c {QPair<int, int>}, where \c{pair.first} would contain 1 and \c{pair.second} would contain 2, when
* relating to the above example. * relating to the above example.
* *
* Returns the \c IntersectionType of each intersection point within a QList. * Returns the \c IntersectionType of each intersection point within a QVector.
* *
* \sa QPair, QList * \sa QPair, QVector
*/ */
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList, NeighbourList &neighbourList, IntersectList &typeList) bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList, NeighbourVector &neighbourList, IntersectVector &typeList)
{ {
if (polygon.size() >= 2) { if (polygon.size() >= 2) {
IntersectList intersectionTypeList; IntersectVector intersectionTypeList;
// Assemble a line form each tow consecutive polygon vertices and check whether it intersects with line // Assemble a line form each tow consecutive polygon vertices and check whether it intersects with line
for (int i = 0; i < polygon.size(); i++) { for (int i = 0; i < polygon.size(); i++) {
...@@ -442,12 +442,12 @@ angle ...@@ -442,12 +442,12 @@ angle
* \overload IntersectType intersects(const QPolygonF &polygon, const QLineF &line) * \overload IntersectType intersects(const QPolygonF &polygon, const QLineF &line)
* Returns \c true if any intersection between \a polygon and \a line exists, \c false else. * Returns \c true if any intersection between \a polygon and \a line exists, \c false else.
* *
* \sa QPair, QList * \sa QPair, QVector
*/ */
bool intersects(const QPolygonF &polygon, const QLineF &line) bool intersects(const QPolygonF &polygon, const QLineF &line)
{ {
QPointFList dummyGeo; QPointFVector dummyGeo;
QList<QPair<int, int>> dummyNeighbour; QVector<QPair<int, int>> dummyNeighbour;
intersects(polygon, line, dummyGeo, dummyNeighbour); intersects(polygon, line, dummyGeo, dummyNeighbour);
if (dummyGeo.size() > 0) if (dummyGeo.size() > 0)
...@@ -468,7 +468,7 @@ angle ...@@ -468,7 +468,7 @@ angle
return point; return point;
} }
QPointFList rotateReturn(QPointFList points, double alpha) QPointFVector rotateReturn(QPointFVector points, double alpha)
{ {
rotateReference(points, alpha); rotateReference(points, alpha);
return points; return points;
...@@ -488,22 +488,22 @@ angle ...@@ -488,22 +488,22 @@ angle
return intersects(line1, line2, intersectionPt, dummyType); return intersects(line1, line2, intersectionPt, dummyType);
} }
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList, NeighbourList &neighbourList) bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList, NeighbourVector &neighbourList)
{ {
IntersectList typeList; IntersectVector typeList;
return intersects(polygon, line, intersectionList, neighbourList, typeList); return intersects(polygon, line, intersectionList, neighbourList, typeList);
} }
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList, IntersectList &typeList) bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList, IntersectVector &typeList)
{ {
NeighbourList neighbourList; NeighbourVector neighbourList;
return intersects(polygon, line, intersectionList, neighbourList, typeList); return intersects(polygon, line, intersectionList, neighbourList, typeList);
} }
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList) bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList)
{ {
NeighbourList neighbourList; NeighbourVector neighbourList;
IntersectList typeList; IntersectVector typeList;
return intersects(polygon, line, intersectionList, neighbourList, typeList); return intersects(polygon, line, intersectionList, neighbourList, typeList);
} }
...@@ -518,23 +518,23 @@ angle ...@@ -518,23 +518,23 @@ angle
bool intersects(const Circle &circle1, const Circle &circle2) bool intersects(const Circle &circle1, const Circle &circle2)
{ {
IntersectType type = NoIntersection; IntersectType type = NoIntersection;
QPointFList intersectionPoints; QPointFVector intersectionPoints;
return intersects(circle1, circle2, intersectionPoints, type, false /*calculate intersection points*/); return intersects(circle1, circle2, intersectionPoints, type, false /*calculate intersection points*/);
} }
bool intersects(const Circle &circle1, const Circle &circle2, IntersectType &type) bool intersects(const Circle &circle1, const Circle &circle2, IntersectType &type)
{ {
QPointFList intersectionPoints; QPointFVector intersectionPoints;
return intersects(circle1, circle2, intersectionPoints, type, false /*calculate intersection points*/); return intersects(circle1, circle2, intersectionPoints, type, false /*calculate intersection points*/);
} }
bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &intersectionPoints) bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints)
{ {
IntersectType type; IntersectType type;
return intersects(circle1, circle2, intersectionPoints, type); return intersects(circle1, circle2, intersectionPoints, type);
} }
bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &intersectionPoints, IntersectType &type) bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints, IntersectType &type)
{ {
return intersects(circle1, circle2, intersectionPoints, type, true /*calculate intersection points*/); return intersects(circle1, circle2, intersectionPoints, type, true /*calculate intersection points*/);
} }
...@@ -623,7 +623,7 @@ angle ...@@ -623,7 +623,7 @@ angle
return truncateAngle(qAtan2(p1.y(), p1.x())); return truncateAngle(qAtan2(p1.y(), p1.x()));
} }
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, NeighbourList &neighbourList, IntersectList &typeList) bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, NeighbourVector &neighbourList, IntersectVector &typeList)
{ {
using namespace PolygonCalculus; using namespace PolygonCalculus;
for (int i = 0; i < polygon.size(); i++) { for (int i = 0; i < polygon.size(); i++) {
...@@ -632,7 +632,7 @@ angle ...@@ -632,7 +632,7 @@ angle
QPointF p2 = polygon[j]; QPointF p2 = polygon[j];
QLineF line(p1, p2); QLineF line(p1, p2);
QPointFList lineIntersecPts; QPointFVector lineIntersecPts;
IntersectType type; IntersectType type;
if (intersects(circle, line, lineIntersecPts, type)) { if (intersects(circle, line, lineIntersecPts, type)) {
QPair<int, int> neigbours; QPair<int, int> neigbours;
...@@ -652,27 +652,27 @@ angle ...@@ -652,27 +652,27 @@ angle
} }
} }
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, NeighbourList &neighbourList) bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, NeighbourVector &neighbourList)
{ {
QList<IntersectType> types; QVector<IntersectType> types;
return intersects(circle, polygon, intersectionPoints, neighbourList, types); return intersects(circle, polygon, intersectionPoints, neighbourList, types);
} }
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, IntersectList &typeList) bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, IntersectVector &typeList)
{ {
NeighbourList neighbourList; NeighbourVector neighbourList;
return intersects(circle, polygon, intersectionPoints, neighbourList, typeList); return intersects(circle, polygon, intersectionPoints, neighbourList, typeList);
} }
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints) bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints)
{ {
NeighbourList neighbourList; NeighbourVector neighbourList;
return intersects(circle, polygon, intersectionPoints, neighbourList); return intersects(circle, polygon, intersectionPoints, neighbourList);
} }
bool intersects(const Circle &circle, const QPolygonF &polygon) bool intersects(const Circle &circle, const QPolygonF &polygon)
{ {
QList<QPointFList> intersectionPoints; QVector<QPointFVector> intersectionPoints;
return intersects(circle, polygon, intersectionPoints); return intersects(circle, polygon, intersectionPoints);
} }
...@@ -682,7 +682,7 @@ angle ...@@ -682,7 +682,7 @@ angle
return intersects(line1, line2, intersectionPoint); return intersects(line1, line2, intersectionPoint);
} }
bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints, IntersectType &type) bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints, IntersectType &type)
{ {
return intersects(circle, line, intersectionPoints, type, true /* calculate intersection points*/); return intersects(circle, line, intersectionPoints, type, true /* calculate intersection points*/);
} }
......
...@@ -26,43 +26,43 @@ namespace PlanimetryCalculus { ...@@ -26,43 +26,43 @@ namespace PlanimetryCalculus {
NoIntersection, Error // general NoIntersection, Error // general
}; };
typedef QList<QPair<int, int>> NeighbourList; typedef QVector<QPair<int, int>> NeighbourVector;
typedef QList<QPointF> QPointFList; typedef QVector<QPointF> QPointFVector;
typedef QList<IntersectType> IntersectList; typedef QVector<IntersectType> IntersectVector;
void rotateReference(QPointF &point, double alpha); void rotateReference(QPointF &point, double alpha);
void rotateReference(QPointFList &points, double alpha); void rotateReference(QPointFVector &points, double alpha);
void rotateReference(QLineF &line, double alpha); void rotateReference(QLineF &line, double alpha);
//void rotateReference(QPolygonF &polygon, double alpha); //void rotateReference(QPolygonF &polygon, double alpha);
QPointF rotateReturn(QPointF point, double alpha); QPointF rotateReturn(QPointF point, double alpha);
QPointFList rotateReturn(QPointFList points, double alpha); QPointFVector rotateReturn(QPointFVector points, double alpha);
QLineF rotateReturn(QLineF line, double alpha); QLineF rotateReturn(QLineF line, double alpha);
//QPolygonF rotateReturn(QPolygonF &polygon, double alpha); //QPolygonF rotateReturn(QPolygonF &polygon, double alpha);
bool intersects(const Circle &circle1, const Circle &circle2); bool intersects(const Circle &circle1, const Circle &circle2);
bool intersects(const Circle &circle1, const Circle &circle2, IntersectType &type); bool intersects(const Circle &circle1, const Circle &circle2, IntersectType &type);
bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &intersectionPoints); bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints);
bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &intersectionPoints, IntersectType &type); bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints, IntersectType &type);
bool intersects(const Circle &circle, const QLineF &line); bool intersects(const Circle &circle, const QLineF &line);
bool intersects(const Circle &circle, const QLineF &line, IntersectType &type); bool intersects(const Circle &circle, const QLineF &line, IntersectType &type);
bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints); bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints);
bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints, IntersectType &type); bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints, IntersectType &type);
bool intersects(const Circle &circle, const QPolygonF &polygon); bool intersects(const Circle &circle, const QPolygonF &polygon);
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints); bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints);
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, IntersectList &typeList); bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, IntersectVector &typeList);
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, NeighbourList &neighbourList); bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, NeighbourVector &neighbourList);
bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, NeighbourList &neighbourList, IntersectList &typeList); bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, NeighbourVector &neighbourList, IntersectVector &typeList);
bool intersects(const QLineF &line1, const QLineF &line2); bool intersects(const QLineF &line1, const QLineF &line2);
bool intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt); bool intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt);
bool intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt, IntersectType &type); bool intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt, IntersectType &type);
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList); bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList);
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList, IntersectList &typeList); bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList, IntersectVector &typeList);
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList, NeighbourList &neighbourList); bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList, NeighbourVector &neighbourList);
bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList, NeighbourList &neighbourList, IntersectList &typeList); bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList, NeighbourVector &neighbourList, IntersectVector &typeList);
bool contains(const QLineF &line, const QPointF &point); bool contains(const QLineF &line, const QPointF &point);
bool contains(const QLineF &line, const QPointF &point, IntersectType &type); bool contains(const QLineF &line, const QPointF &point, IntersectType &type);
...@@ -84,7 +84,7 @@ namespace PlanimetryCalculus { ...@@ -84,7 +84,7 @@ namespace PlanimetryCalculus {
* \fntemplate <typename T> int signum(T val) * \fntemplate <typename T> int signum(T val)
* Returns the signum of a value \a val. * Returns the signum of a value \a val.
* *
* \sa QPair, QList * \sa QPair, QVector
*/ */
template <typename T> int signum(T val) template <typename T> int signum(T val)
{ {
......
...@@ -32,11 +32,11 @@ namespace PolygonCalculus { ...@@ -32,11 +32,11 @@ namespace PolygonCalculus {
if ( !polygon.containsPoint(c1, Qt::FillRule::OddEvenFill) if ( !polygon.containsPoint(c1, Qt::FillRule::OddEvenFill)
|| !polygon.containsPoint(c2, Qt::FillRule::OddEvenFill)) || !polygon.containsPoint(c2, Qt::FillRule::OddEvenFill))
return false; return false;
QList<QPointF> intersectionList; QVector<QPointF> intersectionList;
QLineF line; QLineF line;
line.setP1(c1); line.setP1(c1);
line.setP2(c2); line.setP2(c2);
PlanimetryCalculus::IntersectList intersectTypeList; PlanimetryCalculus::IntersectVector intersectTypeList;
bool retValue = PlanimetryCalculus::intersects(polygon, line, intersectionList, intersectTypeList); bool retValue = PlanimetryCalculus::intersects(polygon, line, intersectionList, intersectTypeList);
if (retValue) { if (retValue) {
...@@ -191,8 +191,8 @@ namespace PolygonCalculus { ...@@ -191,8 +191,8 @@ namespace PolygonCalculus {
walkerPolySegment.setP1(currentVertex); walkerPolySegment.setP1(currentVertex);
walkerPolySegment.setP2(protoNextVertex); walkerPolySegment.setP2(protoNextVertex);
QList<QPair<int, int>> neighbourList; QVector<QPair<int, int>> neighbourList;
QList<QPointF> intersectionList; QVector<QPointF> intersectionList;
//qDebug("IntersectionList.size() on init: %i", intersectionList.size()); //qDebug("IntersectionList.size() on init: %i", intersectionList.size());
PlanimetryCalculus::intersects(*crossPoly, walkerPolySegment, intersectionList, neighbourList); PlanimetryCalculus::intersects(*crossPoly, walkerPolySegment, intersectionList, neighbourList);
...@@ -538,10 +538,19 @@ namespace PolygonCalculus { ...@@ -538,10 +538,19 @@ namespace PolygonCalculus {
for ( auto element : path) { for ( auto element : path) {
pathReversed.prepend(element); pathReversed.prepend(element);
} }
path.clear(); path = pathReversed;
path.append(pathReversed);
} }
void reversePath(QPointFVector &path)
{
QPointFVector pathReversed;
for ( auto element : path) {
pathReversed.prepend(element);
}
path = pathReversed;
}
} // end PolygonCalculus namespace } // end PolygonCalculus namespace
...@@ -13,6 +13,7 @@ namespace PolygonCalculus { ...@@ -13,6 +13,7 @@ namespace PolygonCalculus {
typedef QList<QVector3D> QVector3DList; typedef QList<QVector3D> QVector3DList;
typedef QList<QPointF> QPointFList; typedef QList<QPointF> QPointFList;
typedef QVector<QPointF> QPointFVector;
int closestVertexIndex (const QPolygonF &polygon, const QPointF &coordinate); int closestVertexIndex (const QPolygonF &polygon, const QPointF &coordinate);
QPointF closestVertex (const QPolygonF &polygon, const QPointF &coordinate); QPointF closestVertex (const QPolygonF &polygon, const QPointF &coordinate);
...@@ -23,6 +24,7 @@ namespace PolygonCalculus { ...@@ -23,6 +24,7 @@ namespace PolygonCalculus {
bool hasClockwiseWinding (const QPolygonF &path); bool hasClockwiseWinding (const QPolygonF &path);
void reversePath (QPolygonF &path); void reversePath (QPolygonF &path);
void reversePath (QPointFList &path); void reversePath (QPointFList &path);
void reversePath (QPointFVector &path);
void offsetPolygon (QPolygonF &polygon, double offset); void offsetPolygon (QPolygonF &polygon, double offset);
bool containsPath (QPolygonF polygon, const QPointF &c1, const QPointF &c2); bool containsPath (QPolygonF polygon, const QPointF &c1, const QPointF &c2);
void decomposeToConvex (const QPolygonF &polygon, QList<QPolygonF> &convexPolygons); void decomposeToConvex (const QPolygonF &polygon, QList<QPolygonF> &convexPolygons);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment