37#ifdef DEBUG_INTERSECTION
59 const auto &curPolyPt = *iter;
60 if (inside && (lastIntersect != curPolyPt)) {
63 VERBOSE(std::cout <<
"Advance adds cross pt: (" << curPolyPt.X() <<
"," << curPolyPt.Y() <<
")\n");
89 VERBOSE(std::cout <<
"Area of P (" << P.
area() <<
"). Area of Q (" << Q.
area() <<
")\n");
91 VERBOSE(std::cout <<
"Area of P < Area of Q. Swapping order.\n");
95 V2D iPnt, startPnt, curIntersection;
97 eEdgeIn inflag = Unknown;
100 for (
size_t i = 1; i <= maxItns; ++i) {
101 VERBOSE(std::cout <<
"Iteration " << i <<
" Phase = " << phase <<
'\n');
106 VERBOSE(std::cout <<
"Class P Pt\n");
107 VERBOSE(std::cout <<
"Class Pt: (" << edgeP.
end().
X() <<
"," << edgeP.
end().
Y() <<
")\n");
108 VERBOSE(std::cout <<
"Edge Orig Pt (" << edgeQ.
start().
X() <<
"," << edgeQ.
start().
Y() <<
")\n");
109 VERBOSE(std::cout <<
"Edge Dest Pt (" << edgeQ.
end().
X() <<
"," << edgeQ.
end().
Y() <<
")\n");
110 VERBOSE(std::cout <<
"P pt class: " << pclass <<
'\n');
113 VERBOSE(std::cout <<
"Class Q Pt\n");
114 VERBOSE(std::cout <<
"Class Pt: (" << edgeQ.
end().
X() <<
"," << edgeQ.
end().
Y() <<
")\n");
115 VERBOSE(std::cout <<
"Edge Orig Pt (" << edgeP.
start().
X() <<
"," << edgeP.
start().
Y() <<
")\n");
116 VERBOSE(std::cout <<
"Edge Dest Pt (" << edgeP.
end().
X() <<
"," << edgeP.
end().
Y() <<
")\n");
117 VERBOSE(std::cout <<
"Q pt class: " << qclass <<
'\n');
120 VERBOSE(std::cout <<
"PQ Orient: " << crossType <<
'\n');
125 VERBOSE(std::cout <<
"Found a crossing pt: (" << iPnt.
X() <<
",");
126 VERBOSE(std::cout << iPnt.
Y() <<
")\n");
128 curIntersection = iPnt;
131 }
else if (iPnt != curIntersection) {
132 VERBOSE(std::cout <<
"Found a crossing pt: (" << iPnt.
X() <<
",");
133 VERBOSE(std::cout << iPnt.
Y() <<
")\n");
134 if (iPnt != startPnt) {
135 curIntersection = iPnt;
145 }
else if (qclass ==
OnRight) {
153 VERBOSE(std::cout <<
"Current in flag: " << inflag <<
'\n');
155 bool pAIMSq =
edgeAimsAt(edgeP, edgeQ, pclass, crossType);
156 bool qAIMSp =
edgeAimsAt(edgeQ, edgeP, qclass, crossType);
158 VERBOSE(std::cout <<
"P aims at Q:" << pAIMSq <<
'\n');
159 VERBOSE(std::cout <<
"Q aims at P:" << qAIMSp <<
'\n');
160 if (pAIMSq && qAIMSp) {
161 if ((inflag == QIsInside) || ((inflag == Unknown) && (pclass ==
OnLeft))) {
162 VERBOSE(std::cout <<
"Move edge on P\n");
163 advanceVertex(pIter, out, curIntersection,
false);
165 VERBOSE(std::cout <<
"Move edge on Q\n");
166 advanceVertex(qIter, out, curIntersection,
false);
169 VERBOSE(std::cout <<
"Move edge on P\n");
170 advanceVertex(pIter, out, curIntersection, inflag == PIsInside);
172 VERBOSE(std::cout <<
"Move edge on Q\n");
173 advanceVertex(qIter, out, curIntersection, inflag == QIsInside);
175 if ((inflag == QIsInside) || ((inflag == Unknown) && (pclass ==
OnLeft))) {
176 VERBOSE(std::cout <<
"Move edge on P\n");
177 advanceVertex(pIter, out, curIntersection,
false);
179 VERBOSE(std::cout <<
"Move edge on Q\n");
180 advanceVertex(qIter, out, curIntersection,
false);
#define VERBOSE(X)
Define a macro to include the logging statements if requested.
PolygonEdge edge() const
Create a directed edge between this and the next point.
An implementation of a convex polygon.
virtual size_t npoints() const
Return the number of vertices.
void insert(const Kernel::V2D &pt)
Insert a new vertex.
virtual double area() const
Compute the area of the polygon using triangulation.
bool isValid() const
Check if polygon is valid.
virtual bool contains(const Kernel::V2D &point) const
Is a point inside this polygon.
virtual ConvexPolygon toPoly() const
Return a new Polygon based on the current type.
PolygonEdge Defines a directed edge between two points on a polygon.
const Kernel::V2D & end() const
Access the end point.
const Kernel::V2D & start() const
Access the start point.
Orientation
Defines the orientation with respect to another edge.
@ Collinear
Edges lie on the same line.
@ SkewCross
Edges are at an angle and intersect.
The Logger class is in charge of the publishing messages from the framework through various channels.
Implements a 2-dimensional vector embedded in a 3D space, i.e.
double Y() const
Y position.
double X() const
X position.
Mantid::Kernel::Logger g_log("Goniometer")
MANTID_GEOMETRY_DLL PointClassification classify(const Kernel::V2D &pt, const PolygonEdge &edge)
Helper function for classification.
MANTID_GEOMETRY_DLL bool edgeAimsAt(const PolygonEdge &a, const PolygonEdge &b, PointClassification aclass, PolygonEdge::Orientation crossType)
Return if the edges aim at each other.
MANTID_GEOMETRY_DLL PolygonEdge::Orientation crossingPoint(const PolygonEdge &edgeOne, const PolygonEdge &edgeTwo, Kernel::V2D &crossPoint)
Calculate the crossing point of one edge with wrt another.
bool MANTID_GEOMETRY_DLL intersection(const ConvexPolygon &P, const ConvexPolygon &Q, ConvexPolygon &out)
Compute the instersection of two convex polygons.
PointClassification
Enumeration for point type w.r.t an edge.
@ OnRight
Point is to right of edge.
@ OnLeft
Point is to left of edge.
@ Behind
Point is left of edge origin.