void CLineCrossings::Compute(const CFixedRect& Band, COutlinePath* pPath) { // Add in the initial crossings to account for the universe and the band. // The band is a hole in the middle of the (solid) universe. AddCrossing(-0x7fffffff, 1); // Left of universe. AddCrossing(Band.Left, -1); // Left of band. AddCrossing(Band.Right, 1); // Right of band. AddCrossing(0x7fffffff, -1); // Right of universe. if (pPath != NULL) { AddPathCrossings(*pPath, Band.Top, Band.Bottom); } }
// // This fucntion will ad a crossing to this line and the other line // the crossing will be put in the link, because the line will be destructed // after use of the variable // void kbLine::AddLineCrossing( B_INT X, B_INT Y, kbLine *other_line ) { // the other line must exist assert( other_line ); // the links of the lines must exist assert( other_line->m_link && m_link ); other_line->AddCrossing( AddCrossing( X, Y ) ); }
void CLineCrossings::AddBandCrossing(int nEntryPlace, int nExitPlace, CFixed lEntryX, CFixed lExitX, CFixed lMin, CFixed lMax) { if (nEntryPlace == nExitPlace) { // The path has entered and exited on the same // side of the band. If the entry and exit cause // a "hump" (a piece of interior in empty space), // then we add it. If it causes a "negative hump" // (a piece of empty space in the interior), then // we ignore it. BOOL fHump = (lExitX > lEntryX); if (nExitPlace == -1) { fHump = !fHump; } if (fHump) { AddCrossing(lMin, 1); AddCrossing(lMax, -1); } } else { // The path has crossed the band. // We need to add one crossing which depends on // the crossing direction. if (nEntryPlace == 1) { ASSERT(nExitPlace == -1); // Crossing from bottom to top. AddCrossing(lMin, 1); } else { ASSERT(nExitPlace == 1); // Crossing from top to bottom. AddCrossing(lMax, -1); } } }
// Intersects two lines // input Line : another line // Marge: optional, standard on MARGE // // return 0: If there are no crossings // 1: If there is one crossing // 2: If there are two crossings int kbLine::Intersect( kbLine * lijn, double Marge ) { double distance = 0; // lijn must exist assert( lijn ); // points may not be equal // must be an if statement because if an assert is used there will // be a macro expansion error if ( m_link->GetBeginNode() == m_link->GetEndNode() ) assert( !m_link ); kbNode *bp, *ep; PointStatus Result_beginnode, Result_endnode; int Take_Action1, Take_Action2, Number_of_Crossings = 0; // Get the nodes from lijn via the link bp = lijn->m_link->GetBeginNode(); ep = lijn->m_link->GetEndNode(); Result_beginnode = PointInLine( bp, distance, Marge ); Result_endnode = PointInLine( ep, distance, Marge ); Take_Action1 = ActionOnTable1( Result_beginnode, Result_endnode ); // The first switch will insert a crosspoint immediatly switch ( Take_Action1 ) { // for the cases see the returnvalue of ActionTable1 case 2: case 6: AddCrossing( ep ); Number_of_Crossings = 1; break; case 3: case 5: AddCrossing( bp ); Number_of_Crossings = 1; break; case 4: AddCrossing( bp ); AddCrossing( ep ); Number_of_Crossings = 2; break; } // This switch wil investigate the points of this line in relation to lijn switch ( Take_Action1 ) { // for the cases see the returnvalue of ActionTable1 case 1: case 5: case 6: { // Get the nodes from this line via the link bp = m_link->GetBeginNode(); ep = m_link->GetEndNode(); Result_beginnode = lijn->PointInLine( bp, distance, Marge ); Result_endnode = lijn->PointInLine( ep, distance, Marge ); Take_Action2 = ActionOnTable2( Result_beginnode, Result_endnode ); switch ( Take_Action2 ) { // for the cases see the returnvalue of ActionTable2 case 1: { // begin of scope to calculate the intersection double X, Y, Denominator; CalculateLineParameters(); Denominator = ( m_AA * lijn->m_BB ) - ( lijn->m_AA * m_BB ); // Denominator may not be 0 assert( Denominator != 0.0 ); // Calculate intersection of both linesegments X = ( ( m_BB * lijn->m_CC ) - ( lijn->m_BB * m_CC ) ) / Denominator; Y = ( ( lijn->m_AA * m_CC ) - ( m_AA * lijn->m_CC ) ) / Denominator; //make a decent rounding to B_INT AddLineCrossing( ( B_INT )X, ( B_INT )Y, lijn ); } // end of scope to calculate the intersection Number_of_Crossings++; break; case 2: lijn->AddCrossing( ep ); Number_of_Crossings++; break; case 3: lijn->AddCrossing( bp ); Number_of_Crossings++; break; case 4: lijn->AddCrossing( bp ); lijn->AddCrossing( ep ); Number_of_Crossings = 2; break; } } ; break; // This break belongs to the outer switch } return Number_of_Crossings; //This is de final number of crossings }
// // see above // kbNode* kbLine::AddCrossing( B_INT X, B_INT Y ) { kbNode * result = new kbNode( X, Y, m_GC ); AddCrossing( result ); return result; }