#pragma once

#include <QLineF>
#include <QPointF>
#include <QPolygonF>
#include <QtMath>
#include <QLineF>

#include "PolygonCalculus.h"

class Circle;

namespace PlanimetryCalculus {

    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

                       NoIntersection, Error // general
                       };

    typedef QList<QPair<int, int>> NeighbourList;
    typedef QList<QPointF> QPointFList;
    typedef QList<IntersectType> IntersectList;

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

    QPointF     rotateReturn(QPointF point, double alpha);
    QPointFList rotateReturn(QPointFList 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, QPointFList &intersectionPoints);
    bool intersects(const Circle &circle1, const Circle &circle2, QPointFList &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, QPointFList &intersectionPoints);
    bool intersects(const Circle &circle, const QLineF &line, QPointFList &intersectionPoints, IntersectType &type);


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

    double distance(const QPointF &p1, const QPointF p2);
    double angle(const QPointF &p1, const QPointF p2);
    double angleDegree(const QPointF &p1, const QPointF p2);
    double truncateAngle(double angle);
    double truncateAngleDegree(double angle);

    template <typename T> int signum(T val);
}



