PlanimetryCalculus.h 4.39 KB
Newer Older
1 2 3 4
#pragma once

#include <QLineF>
#include <QPointF>
5
#include <QPolygonF>
6 7 8
#include <QtMath>
#include <QLineF>

Valentin Platzgummer's avatar
Valentin Platzgummer committed
9 10
#include "PolygonCalculus.h"

11 12 13
class Circle;

namespace PlanimetryCalculus {
14

15 16 17
    enum IntersectType{InsideNoIntersection, InsideTouching, InsideIntersection,
                       OutsideIntersection, OutsideTouching, OutsideNoIntersection,
                       CirclesEqual, //Circle Circle intersection
18

Valentin Platzgummer's avatar
Valentin Platzgummer committed
19
                       Tangent, Secant, // Circle Line Intersetion
20

21 22 23
                       EdgeCornerIntersection, EdgeEdgeIntersection, CornerCornerIntersection,
                       LinesParallel, LinesEqual, // Line Line intersection

Valentin Platzgummer's avatar
Valentin Platzgummer committed
24 25
                       Interior, // Polygon contains

Valentin Platzgummer's avatar
Valentin Platzgummer committed
26
                       NoIntersection, Error // general
27 28
                       };

Valentin Platzgummer's avatar
Valentin Platzgummer committed
29 30 31 32
    typedef QList<QPair<int, int>> NeighbourList;
    typedef QList<QPointF> QPointFList;
    typedef QList<IntersectType> IntersectList;

Valentin Platzgummer's avatar
Valentin Platzgummer committed
33
    void rotateReference(QPointF &point, double alpha);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
34
    void rotateReference(QPointFList &points, double alpha);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
35 36 37
    void rotateReference(QLineF &line, double alpha);
    //void rotateReference(QPolygonF &polygon, double alpha);

38 39 40
    QPointF     rotateReturn(QPointF point, double alpha);
    QPointFList rotateReturn(QPointFList points, double alpha);
    QLineF      rotateReturn(QLineF line, double alpha);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
41 42
    //QPolygonF       rotateReturn(QPolygonF &polygon, double alpha);

Valentin Platzgummer's avatar
Valentin Platzgummer committed
43 44 45 46
    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, QPointFList &intersectionPoints);
    bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &intersectionPoints, IntersectType &type);
47

Valentin Platzgummer's avatar
Valentin Platzgummer committed
48 49 50 51 52
    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, QPointFList &intersectionPoints);
    bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints, IntersectType &type);

53 54 55 56 57
    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, QList<QPointFList> &intersectionPoints, IntersectList &typeList);
    bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, NeighbourList &neighbourList);
    bool intersects(const Circle &circle, const QPolygonF &polygon, QList<QPointFList> &intersectionPoints, NeighbourList &neighbourList, IntersectList &typeList);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
58

59
    bool intersects(const QLineF &line1, const QLineF &line2);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
60 61 62 63 64 65
    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 QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList);
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList,  IntersectList &typeList);
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList,  NeighbourList &neighbourList);
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFList &intersectionList,  NeighbourList &neighbourList, IntersectList &typeList);
66

Valentin Platzgummer's avatar
Valentin Platzgummer committed
67 68 69 70 71 72
    bool contains(const QLineF &line, const QPointF &point);
    bool contains(const QLineF &line, const QPointF &point, IntersectType &type);
    bool contains(const QPolygonF &polygon, const QPointF &point);
    bool contains(const QPolygonF &polygon, const QPointF &point, IntersectType &type);


73
    double distance(const QPointF &p1, const QPointF p2);
74 75
    double norm(double x, double y);
    double norm(const QPointF &p);
76
    double angle(const QPointF &p1, const QPointF p2);
77
    double angle(const QPointF &p1);
78
    double angle(const QLineF &line);
79
    double angleDegree(const QPointF &p1, const QPointF p2);
80 81
    double truncateAngle(double angle);
    double truncateAngleDegree(double angle);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
82

83 84 85 86 87 88 89 90 91 92
    /*!
     * \fntemplate <typename T> int signum(T val)
     * Returns the signum of a value \a val.
     *
     * \sa QPair, QList
     */
    template <typename T> int signum(T val)
    {
        return (T(0) < val) - (val < T(0));
    }
93 94
}

95

96