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

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

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

11
using Circle = GenericCircle<qreal, QPointF>;
12 13

namespace PlanimetryCalculus {
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
enum IntersectType {
  InsideNoIntersection,
  InsideTouching,
  InsideIntersection,
  OutsideIntersection,
  OutsideTouching,
  OutsideNoIntersection,
  CirclesEqual, // Circle Circle intersection

  Tangent,
  Secant, // Circle Line Intersetion

  EdgeCornerIntersection,
  EdgeEdgeIntersection,
  CornerCornerIntersection,
  LinesParallel,
  LinesEqual, // Line Line intersection

  Interior, // Polygon contains

  NoIntersection,
  Error // general
};

typedef QVector<QPair<int, int>> NeighbourVector;
typedef QVector<QPointF> QPointFVector;
typedef QVector<IntersectType> IntersectVector;

void rotateReference(QPointF &point, double alpha);
void rotateReference(QPointFVector &points, double alpha);
void rotateReference(QLineF &line, double alpha);
// void rotateReference(QPolygonF &polygon, double alpha);

QPointF rotateReturn(QPointF point, double alpha);
QPointFVector rotateReturn(QPointFVector points, double alpha);
QLineF rotateReturn(QLineF line, double alpha);
// QPolygonF       rotateReturn(QPolygonF &polygon, double alpha);

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,
                QPointFVector &intersectionPoints);
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, IntersectType &type);
bool intersects(const Circle &circle, const QLineF &line,
                QPointFVector &intersectionPoints);
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,
                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);

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, IntersectType &type);
//    bool intersectsFast(const QLineF &line1, const QLineF &line2, QPointF
//    &intersectionPt, IntersectType &type);
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);

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

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);

double distance(const QPointF &p1, const QPointF p2);
double norm(double x, double y);
double norm(const QPointF &p);
double angle(const QPointF &p1, const QPointF p2);
double angle(const QPointF &p1);
double angle(const QLineF &line);
double angleDegree(const QPointF &p1, const QPointF p2);
double truncateAngle(double angle);
double truncateAngleDegree(double angle);

/*!
 * \fntemplate <typename T> int signum(T val)
 * Returns the signum of a value \a val.
 *
 * \sa QPair, QVector
 */
template <typename T> int signum(T val) { return (T(0) < val) - (val < T(0)); }
} // namespace PlanimetryCalculus