[Sofaswitch-svn] [commit] r358 - sofaswitch/trunk/callflow/src
Author: derek Date: Thu Jul 19 19:39:09 2007 New Revision: 358 Modified: sofaswitch/trunk/callflow/src/joinblocks.cpp sofaswitch/trunk/callflow/src/joinblocks.h Log: Correctly handle the case for when selecting a region of the screen. Now, it handles the joinblocks structure corectly, and tests to see if the joinblocks does indeed intersect with the region of the screen. Modified: sofaswitch/trunk/callflow/src/joinblocks.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/joinblocks.cpp (original) +++ sofaswitch/trunk/callflow/src/joinblocks.cpp Thu Jul 19 19:39:09 2007 @@ -15,6 +15,13 @@ #include "joinblocks.h" +#ifndef MIN +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif ///////////////////////////////////////////////////////////////////////////// DndShapeJoinBlocks::DndShapeJoinBlocks() @@ -197,15 +204,159 @@ } } +bool DndShapeJoinBlocks::LinesDoCrossVerticalUnknown(const wxPoint & ptA, const wxPoint &ptB, + const wxPoint & ptY, const wxPoint & ptZ) const +{ + if (ptY.x == ptZ.x) { + if (ptY.x != ptA.x) + return false; + if (MIN(ptY.y, ptZ.y) > MAX(ptA.y, ptB.y)) + return false; + if (MIN(ptA.y, ptB.y) > MAX(ptY.y, ptB.y)) + return false; + return true; + } + + double m = ((double)ptY.y - ptZ.y)/((double)ptY.x - ptZ.x); + double yzC = ptY.y - (ptY.x * m); + double cross = (ptA.x * m) + yzC; + + bool doCross = (cross >= MIN(ptA.y, ptB.y)) && (cross <= MAX (ptA.y, ptB.y)); + + return doCross; +} + +bool DndShapeJoinBlocks::LinesDoCrossOtherOther(const wxPoint & ptA, const wxPoint &ptB, + const wxPoint & ptY, const wxPoint & ptZ) const +{ + double yzM = ((double)ptY.y - ptZ.y)/((double)ptY.x - ptZ.x); + double yzC = ptY.y - (ptY.x * yzM); + //std::cerr << ptY.x << "." << ptY.y << "--" << ptZ.x << "." << ptZ.y << " " << yzM <<" " << yzC << std::endl; + double abM = ((double)ptA.y - ptB.y)/((double)ptA.x - ptB.x); + double abC = ptA.y - (ptA.x * abM); + //std::cerr << ptA.x << "." << ptA.y << "--" << ptB.x << "." << ptB.y << " " << abM <<" " << abC << std::endl; + double cross = (abC - yzC) / (yzM - abM); + double crossY = (cross * abM) + abC; + //std::cerr << "Cross Y is " << crossY << std::endl; + bool doCross = (crossY >= MIN(ptA.y, ptB.y)) && (crossY <= MAX (ptA.y, ptB.y)) + && (crossY >= MIN(ptY.y, ptZ.y)) && (crossY <= MAX (ptY.y, ptZ.y)); + + return doCross; +} + + + +bool DndShapeJoinBlocks::LinesDoCross(const wxPoint & ptA, const wxPoint &ptB, + const wxPoint & ptY, const wxPoint & ptZ) const +{ + if (MIN(ptA.x, ptB.x) > MAX(ptY.x, ptZ.x)) + return false; + + if (MIN(ptA.y, ptB.y) > MAX(ptY.y, ptZ.y)) + return false; + + if (MAX(ptA.x, ptB.x) < MIN(ptY.x, ptZ.x)) + return false; + + if (MAX(ptA.y, ptB.y) < MIN(ptY.y, ptZ.y)) + return false; + + if (ptA.x == ptB.x) + return LinesDoCrossVerticalUnknown(ptA, ptB, ptY, ptZ); + + if (ptY.x == ptZ.x) + return LinesDoCrossVerticalUnknown(ptY, ptZ, ptA, ptB); + + return LinesDoCrossOtherOther(ptA, ptB, ptY, ptZ); +} bool DndShapeJoinBlocks::Intersects(const wxRect & testRectangle) const { - if (DndShape::Intersects(testRectangle)) { - return true; - } else { + wxNode *node = (wxNode *)points.GetFirst(); + if (node == NULL) + return false; + + if ((testRectangle.x == 0) && (testRectangle.y == 0)) + return true; + + wxRect markedRectangle = testRectangle.Inflate(5, 5); +#if 0 + std::cerr << " compare rectangle " << testRectangle.x << "."<<testRectangle.y << "---" + << testRectangle.GetWidth() << "x" << testRectangle.GetHeight() << std::endl; + + std::cerr << " compare rectangle " << markedRectangle.x << "."<< markedRectangle.y << "---" + << markedRectangle.GetWidth() << "x" << markedRectangle.GetHeight() << std::endl; +#endif + + while (node != NULL) { + wxPoint aPoint = *((wxPoint *)node->GetData()); +// std::cerr << aPoint.x << "." << aPoint.y <<" "; + node = node->GetNext(); + } +// std::cerr << std::endl; + + node = (wxNode *)points.GetFirst(); + while(node != NULL) { + wxPoint thisPoint = *((wxPoint *)node->GetData()); + bool isInside = false; +#if WXWIN_COMPATIBILITY_2_6 + isInside = markedRectangle.Contains(thisPoint); +#else + isInside = markedRectangle.Inside(thisPoint); +#endif + if (isInside) { +// std::cerr << "point " << thisPoint.x << " " << thisPoint.y << " is inside\n"; + return true; + } + node = node->GetNext(); + } + +/***********************************************************************/ + wxPoint mRa(markedRectangle.x, markedRectangle.y); + wxPoint mRb(mRa.x + markedRectangle.GetWidth(), mRa.y); + wxPoint mRc(mRb.x, mRb.y + markedRectangle.GetHeight()); + wxPoint mRd(mRa.x, mRc.y); + +#if 0 + std::cerr << " Rectangle is " + << mRa.x <<"." <<mRa.y <<" " + << mRb.x <<"." <<mRb.y <<" " + << mRc.x <<"." <<mRc.y <<" " + << mRd.x <<"." <<mRd.y << std::endl; +#endif + + node = (wxNode *)points.GetFirst(); + + wxPoint firstPoint = *((wxPoint *)node->GetData()); + node = node->GetNext(); + while(node != NULL) { + wxPoint thisPoint = *((wxPoint *)node->GetData()); + + if (LinesDoCross(mRa, mRb, firstPoint, thisPoint)) { + //std::cerr << "lines cross top edge\n" << std::endl; + return true; + } + + if (LinesDoCross(mRb, mRc, firstPoint, thisPoint)) { + //std::cerr << "lnes do cross right edge \n"; + return true; + } + + if (LinesDoCross(mRc, mRd, firstPoint, thisPoint)) { + //std::cerr << "lines do cross bottom edge \n"; + return true; + } + + if (LinesDoCross(mRd, mRa, firstPoint, thisPoint)) { + //std::cerr << "lines do cross left edge\n"; + return true; + } + firstPoint = thisPoint; + node = node->GetNext(); + } + return false; - } } bool DndShapeJoinBlocks::Intersects(const wxPoint & testPoint) const Modified: sofaswitch/trunk/callflow/src/joinblocks.h ============================================================================== --- sofaswitch/trunk/callflow/src/joinblocks.h (original) +++ sofaswitch/trunk/callflow/src/joinblocks.h Thu Jul 19 19:39:09 2007 @@ -89,6 +89,30 @@ /**Report the distance between the test point and the line.which joins the endpoints of the line */ double DistancePointToLine(const wxPoint & point, const wxPoint & lineA, wxPoint & lineB) const; + + /**For the two sets of supplied points, see if the line between each + * endpoint crosses + + @return true if the lines do cross, false if they do not cross*/ + bool LinesDoCross(const wxPoint & ptA, const wxPoint &ptB, + const wxPoint & ptY, const wxPoint & ptZ) const; + + /**For the two sets of supplied points, see if the line between each + endpoint crosses. The first set of point is known to be vertical. The + second set of points may be vertical. + + @return true if the lines do cross, false if they do not cross*/ + bool LinesDoCrossVerticalUnknown(const wxPoint & ptA, const wxPoint &ptB, + const wxPoint & ptY, const wxPoint & ptZ) const; + + /**For the two sets of supplied points, see if the line between each + endpoint crosses. Both sets of points are such that neither line is + veritcal. + + @return true if the lines do cross, false if they do not cross*/ + bool LinesDoCrossOtherOther(const wxPoint & ptA, const wxPoint &ptB, + const wxPoint & ptY, const wxPoint & ptZ) const; + /**Calculate the value of the argument squared */ int sqr(const int & aa) const;
participants (1)
-
SofaSWITCH SVN