mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-13 03:40:31 +02:00
Some image change
This commit is contained in:
39
IntelliPhoto/Painting/IntelliHelper/IntelliHelper.cpp
Normal file
39
IntelliPhoto/Painting/IntelliHelper/IntelliHelper.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include"IntelliHelper.h"
|
||||
#include<algorithm>
|
||||
|
||||
int IntelliHelper::orientation(QPoint& p1, QPoint& p2, QPoint& p3){
|
||||
int value = (p2.x()-p1.x())*(p3.x()-p2.x())-
|
||||
(p2.y()-p1.y())*(p3.y()-p2.y());
|
||||
if(value==0) return 0;
|
||||
return (value>0)?1:2;
|
||||
}
|
||||
|
||||
bool IntelliHelper::onSegment(QPoint& p1, QPoint& q, QPoint& p2){
|
||||
return (q.x() >= std::min(p1.x(),p2.x()) && q.x() <= std::max(p1.x(), p2.x()) &&
|
||||
q.y() >= std::min(p1.y(),p2.y()) && q.y() <= std::max(p1.y(), p2.y()));
|
||||
}
|
||||
|
||||
bool IntelliHelper::hasIntersection(QPoint& p1, QPoint& q1, QPoint& p2, QPoint& q2){
|
||||
int o1 = IntelliHelper::orientation(p1,q1,p2);
|
||||
int o2 = IntelliHelper::orientation(p1,q1,q2);
|
||||
int o3 = IntelliHelper::orientation(p2,q2,p1);
|
||||
int o4 = IntelliHelper::orientation(p2,q2,q1);
|
||||
|
||||
// General case
|
||||
if (o1 != o2 && o3 != o4)
|
||||
return true;
|
||||
|
||||
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
|
||||
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
|
||||
|
||||
// p1, q1 and q2 are colinear and q2 lies on segment p1q1
|
||||
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
|
||||
|
||||
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
|
||||
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
|
||||
|
||||
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
|
||||
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
|
||||
|
||||
return false; // Doesn't fall in any of the above cases
|
||||
}
|
||||
Reference in New Issue
Block a user