PlanimetryCalculus.h 4.64 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
                       };

29 30 31
    typedef QVector<QPair<int, int>> NeighbourVector;
    typedef QVector<QPointF> QPointFVector;
    typedef QVector<IntersectType> IntersectVector;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
32

Valentin Platzgummer's avatar
Valentin Platzgummer committed
33
    void rotateReference(QPointF &point, double alpha);
34
    void rotateReference(QPointFVector &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
    QPointF     rotateReturn(QPointF point, double alpha);
39
    QPointFVector rotateReturn(QPointFVector points, double alpha);
40
    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
    bool intersects(const Circle &circle1, const Circle &circle2);
    bool intersects(const Circle &circle1, const Circle &circle2, IntersectType &type);
45 46
    bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints);
    bool intersects(const Circle &circle1, const Circle &circle2, QPointFVector &intersectionPoints, IntersectType &type);
47

Valentin Platzgummer's avatar
Valentin Platzgummer committed
48 49
    bool intersects(const Circle &circle, const QLineF &line);
    bool intersects(const Circle &circle, const QLineF &line, IntersectType &type);
50 51
    bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints);
    bool intersects(const Circle &circle, const QLineF &line, QPointFVector &intersectionPoints, IntersectType &type);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
52

53
    bool intersects(const Circle &circle, const QPolygonF &polygon);
54 55 56 57
    bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints);
    bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, IntersectVector &typeList);
    bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, NeighbourVector &neighbourList);
    bool intersects(const Circle &circle, const QPolygonF &polygon, QVector<QPointFVector> &intersectionPoints, NeighbourVector &neighbourList, IntersectVector &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
    bool intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt);
    bool intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt, IntersectType &type);
62
//    bool intersectsFast(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt, IntersectType &type);
63 64 65 66
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList);
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList,  IntersectVector &typeList);
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList,  NeighbourVector &neighbourList);
    bool intersects(const QPolygonF &polygon, const QLineF &line, QPointFVector &intersectionList,  NeighbourVector &neighbourList, IntersectVector &typeList);
67

68 69 70

    bool intersectsFast(const QPolygonF &polygon, const QLineF &line);

Valentin Platzgummer's avatar
Valentin Platzgummer committed
71 72 73 74 75 76
    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);


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

87 88 89 90
    /*!
     * \fntemplate <typename T> int signum(T val)
     * Returns the signum of a value \a val.
     *
91
     * \sa QPair, QVector
92 93 94 95 96
     */
    template <typename T> int signum(T val)
    {
        return (T(0) < val) - (val < T(0));
    }
97 98
}

99

100