Integrated Polygon Test

Use calculate traingles and the isInPolygon with theese triangles, this is done because of performance reasons
This commit is contained in:
Sonaion
2019-12-18 16:32:11 +01:00
parent 21ade76563
commit 4953abc791
5 changed files with 150 additions and 22 deletions

View File

@@ -2,17 +2,20 @@
#define INTELLIHELPER_H
#include<QPoint>
#include<vector>
struct Triangle{
QPoint A,B,C;
};
namespace IntelliHelper {
class IntelliHelper{
public:
static inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
}
static inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){
inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){
float val1, val2, val3;
bool neg, pos;
@@ -25,6 +28,11 @@ public:
return !(neg && pos);
}
};
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
}
#endif