Skip to content
PlanimetryCalculus.h 4.64 KiB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#pragma once

#include <QLineF>
#include <QPointF>
#include <QPolygonF>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#include <QtMath>
#include <QLineF>

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

class Circle;

namespace PlanimetryCalculus {
    enum IntersectType{InsideNoIntersection, InsideTouching, InsideIntersection,
                       OutsideIntersection, OutsideTouching, OutsideNoIntersection,
                       CirclesEqual, //Circle Circle intersection
Valentin Platzgummer's avatar
Valentin Platzgummer committed
                       Tangent, Secant, // Circle Line Intersetion
                       EdgeCornerIntersection, EdgeEdgeIntersection, CornerCornerIntersection,
                       LinesParallel, LinesEqual, // Line Line intersection

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

Valentin Platzgummer's avatar
Valentin Platzgummer committed
                       NoIntersection, Error // general
    typedef QVector<QPair<int, int>> NeighbourVector;
    typedef QVector<QPointF> QPointFVector;
    typedef QVector<IntersectType> IntersectVector;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    void rotateReference(QPointF &point, double alpha);
    void rotateReference(QPointFVector &points, double alpha);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    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);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    //QPolygonF       rotateReturn(QPolygonF &polygon, double alpha);

Valentin Platzgummer's avatar
Valentin Platzgummer committed
    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);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    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);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    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);

Valentin Platzgummer's avatar
Valentin Platzgummer committed
    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);


Valentin Platzgummer's avatar
Valentin Platzgummer committed
    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.
     *
     */
    template <typename T> int signum(T val)
    {
        return (T(0) < val) - (val < T(0));
    }