PolygonCalculus.h 2.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#pragma once


#include <QPointF>
#include <QPolygonF>
#include <QVector3D>



namespace PolygonCalculus {

    enum JoinPolygonError { NotSimplePolygon, PolygonJoined, Disjoint, PathSizeLow, Error};

    typedef QList<QVector3D> QVector3DList;
    typedef QList<QPointF> QPointFList;
    typedef QVector<QPointF> QPointFVector;

    int              closestVertexIndex  (const QPolygonF &polygon, const QPointF &coordinate);
    QPointF          closestVertex       (const QPolygonF &polygon, const QPointF &coordinate);
    int              nextVertexIndex     (int pathsize, int index);
    int              previousVertexIndex (int pathsize, int index);
    JoinPolygonError join                (QPolygonF polygon1, QPolygonF polygon2, QPolygonF &joinedPolygon);
    bool             isSimplePolygon     (const QPolygonF &polygon);
    bool             hasClockwiseWinding (const QPolygonF &path);
    void             reversePath         (QPolygonF &path);
    void             reversePath         (QPointFList &path);
    void             reversePath         (QPointFVector &path);
    void             offsetPolygon       (QPolygonF &polygon, double offset);
    // returns true if the line c1-c2 is fully inside the polygon
    bool             containsPath        (QPolygonF polygon, const QPointF &c1, const QPointF &c2);
    // same as containsPath(), but works only if c1 and c2 are inside the polygon!
    bool             containsPathFast    (QPolygonF polygon, const QPointF &c1, const QPointF &c2);
    void             decomposeToConvex   (const QPolygonF &polygon, QList<QPolygonF> &convexPolygons);
    bool             shortestPath        (const QPolygonF &polygon, const QPointF &startVertex, const QPointF &endVertex, QVector<QPointF> &shortestPath);

    QPolygonF toQPolygonF(const QVector3DList &polygon);
    QPolygonF toQPolygonF(const QPointFList &polygon);
    QLineF toQLineF(const QVector3DList &line);
    QPointFList toQPointFList(const QVector3DList &list);
    QPointFList toQPointFList(const QPolygonF &list);
    QVector3DList toQVector3DList(const QPointFList &listF);
    QVector3DList toQVector3DList(const QPolygonF &listF);
}