gtedges.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 512 行 · 第 1/2 页

CPP
512
字号
    } else {
        minRhsX = ( *lineRhs )->_lineCoords.x2;
    }

    if( minLhsX < minRhsX ) {
        return -1;
    } else if ( minLhsX > minRhsX ) {
        return 1;
    } else {
        return 0;
    }
}

void TreeEdgeBreaker::breakLinesV( void )
//--------------------------------------
// Breaks vertical edges into component lines so that they do not
// overlap any horizontal lines
//
{
    TreeCoord _horizontalY;
    TreeCoord minHX, maxHX;
    TreeCoord startY, firstY, lastY;
    int indexH, indexV;

    /*
     * It's important that the horizontal lines be sorted; the algorithm
     * requires this because it needs to be able to find the next
     * horizontal line that is intercepted by each vertical line
     */
    if( !_horizontalSorted ) {
        _horizontalLines.sort( (TComp) TreeEdgeBreaker::compareLinesV );
        _horizontalSorted = TRUE;
    }

    /*
     * Break vertical lines.  If a_vertical line is broken into components,
     * these component_vertical lines are added to the end of the
     * _verticalLines container and the original pointer in _verticalLines
     * is set to NULL.
     */
    for( indexV = 0; indexV < _verticalLines.count(); indexV += 1 ) {

        /*
         * We don't want to break any of the node borders
         */
        if( _verticalLines[ indexV ]->getLineType() == TreeLine::Node ) {
            continue;
        }

        bool overlapNode = FALSE;

        if( _verticalLines[ indexV ]->_lineCoords.y1 < _verticalLines[ indexV ]->_lineCoords.y2 ) {
            startY = _verticalLines[ indexV ]->_lineCoords.y1;
            firstY = _verticalLines[ indexV ]->_lineCoords.y1;
            lastY = _verticalLines[ indexV ]->_lineCoords.y2;
        } else {
            startY = _verticalLines[ indexV ]->_lineCoords.y2;
            firstY = _verticalLines[ indexV ]->_lineCoords.y2;
            lastY = _verticalLines[ indexV ]->_lineCoords.y1;
        }

        /*
         * Scan our way from top to bottom
         */
        for( indexH = 0; indexH < _horizontalLines.count(); indexH += 1 ) {

            /*
             * Since horizontal lines are sorted by vertical position (top
             * to bottom), we can stop looking when a horizontal line
             * is below the vertical line.
             */
            _horizontalY = _horizontalLines[ indexH ]->_lineCoords.y1;
            if( _horizontalY > lastY ) break;

            if( _horizontalLines[ indexH ]->_lineCoords.x1 < _horizontalLines[ indexH ]->_lineCoords.x2 ) {
                minHX = _horizontalLines[ indexH ]->_lineCoords.x1;
                maxHX = _horizontalLines[ indexH ]->_lineCoords.x2;
            } else {
                minHX = _horizontalLines[ indexH ]->_lineCoords.x2;
                maxHX = _horizontalLines[ indexH ]->_lineCoords.x1;
            }

            /*
             * Check if we're overlapping something
             */
            if(( _horizontalY > startY ) && ( _horizontalY < lastY ) &&
               (_verticalLines[ indexV ]->_lineCoords.x1 < maxHX ) &&
               (_verticalLines[ indexV ]->_lineCoords.x1 > minHX )) {

                /*
                 * Case 1:
                 *      - just met a node; break the ptr just above the node
                 */
                if( _horizontalLines[ indexH ]->getLineType() == TreeLine::Node
                    && !overlapNode ) {

                   _verticalLines[ indexV ]->addSeg( _verticalLines[ indexV ]->_lineCoords.x1,
                                                     startY,
                                                     _verticalLines[ indexV ]->_lineCoords.x1,
                                                     _horizontalY - HSKIP );

                    overlapNode = TRUE;

                /*
                 * Case 2:
                 *  - other end of a node; start new line just below node
                 */
                } else if( _horizontalLines[ indexH ]->getLineType() == TreeLine::Node
                           && overlapNode ) {
                    startY = _horizontalY + HSKIP;
                    overlapNode = FALSE;
                /*
                 * Case 3:
                 *      - met an ordinary type of line (tree ring connector or ptr)
                 *    so add new line segment ending just above the intersecting
                 *    line and start a new line just below it
                 */
                } else if( _horizontalLines[ indexH ]->getLineType() != TreeLine::Node ) {
                    _verticalLines[ indexV ]->addSeg( _verticalLines[ indexV ]->_lineCoords.x1,
                                                      startY,
                                                      _verticalLines[ indexV ]->_lineCoords.x1,
                                                      _horizontalY - HSKIP );

                    startY = _horizontalY + HSKIP;
                }
            }
        }

        if( startY != firstY ) {
            _verticalLines[ indexV ]->addSeg( _verticalLines[ indexV ]->_lineCoords.x1,
                                              startY,
                                              _verticalLines[ indexV ]->_lineCoords.x1,
                                              lastY );
        }
    }
}

void TreeEdgeBreaker::breakLinesH( void )
//--------------------------------------
// Breaks horizontal edges into component lines so that they do not
// overlap any vertical lines
//
{
    TreeCoord _verticalX;
    TreeCoord minHY, maxHY;
    TreeCoord startX, firstX, lastX;
    int indexV, indexH;

    if( !_verticalSorted ) {
        _verticalLines.sort( (TComp) TreeEdgeBreaker::compareLinesH );
        _verticalSorted = TRUE;
    }

    /*
     * Break horizontal lines.  If a horizontal line is broken into components,
     * these component horizontal lines are added to the end of the
     * _horizontalLines container and the original pointer in _horizontalLines
     * is set to NULL.
     */
    for( indexH = 0; indexH < _horizontalLines.count(); indexH += 1 ) {

        /*
         * We don't want to break any of the node borders
         */
        if( _horizontalLines[ indexH ]->getLineType() == TreeLine::Node ) {
            continue;
        }

        bool overlapNode = FALSE;

        if( _horizontalLines[ indexH ]->_lineCoords.x1 < _horizontalLines[ indexH ]->_lineCoords.x2 ) {
            startX = _horizontalLines[ indexH ]->_lineCoords.x1;
            firstX = _horizontalLines[ indexH ]->_lineCoords.x1;
            lastX = _horizontalLines[ indexH ]->_lineCoords.x2;
        } else {
            startX = _horizontalLines[ indexH ]->_lineCoords.x2;
            firstX = _horizontalLines[ indexH ]->_lineCoords.x2;
            lastX = _horizontalLines[ indexH ]->_lineCoords.x1;
        }

        /*
         * Scan our way from left to right
         */
        for( indexV = 0; indexV < _verticalLines.count(); indexV += 1 ) {

            /*
             * Since vertical lines are sorted by horizontal position (left
             * to right), we can stop looking when a vertical line
             * is to the right of the horizontal line.
             */
            _verticalX = _verticalLines[ indexV ]->_lineCoords.x1;
            if( _verticalX > lastX ) break;

            if( _verticalLines[ indexV ]->_lineCoords.y1 < _verticalLines[ indexV ]->_lineCoords.y2 ) {
                minHY = _verticalLines[ indexV ]->_lineCoords.y1;
                maxHY = _verticalLines[ indexV ]->_lineCoords.y2;
            } else {
                minHY = _verticalLines[ indexV ]->_lineCoords.y2;
                maxHY = _verticalLines[ indexV ]->_lineCoords.y1;
            }


            /*
             * Check if we're overlapping something
             */
            if(( _verticalX > startX ) && ( _verticalX < lastX ) &&
               (_horizontalLines[ indexH ]->_lineCoords.y1 < maxHY ) &&
               (_horizontalLines[ indexH ]->_lineCoords.y1 > minHY )) {

                /*
                 * Case 1:
                 *      - just met a node; break the ptr just above the node
                 */
                if( _verticalLines[ indexV ]->getLineType() == TreeLine::Node
                    && !overlapNode ) {

                    _horizontalLines[ indexH ]->addSeg( startX,
                                                        _horizontalLines[ indexH ]->_lineCoords.y1,
                                                        _verticalX - VSKIP,
                                                        _horizontalLines[ indexH ]->_lineCoords.y1 );
                    overlapNode = TRUE;

                /*
                 * Case 2:
                 *  - other end of a node; start new line just below node
                 */
                } else if( _verticalLines[ indexV ]->getLineType() == TreeLine::Node
                           && overlapNode ) {
                    startX = _verticalX + VSKIP;
                    overlapNode = FALSE;
                /*
                 * Case 3:
                 *      - met an ordinary type of line (tree ring connector or ptr)
                 *    so add new line segment ending just above the intersecting
                 *    line and start a new line just below it
                 */
                } else if( _verticalLines[ indexV ]->getLineType() != TreeLine::Node ) {
                    _horizontalLines[ indexH ]->addSeg( startX,
                                              _horizontalLines[ indexH ]->_lineCoords.y1,
                                              _verticalX - VSKIP,
                                              _horizontalLines[ indexH ]->_lineCoords.y1 );
                    startX = _verticalX + VSKIP;
                }
            }
        }

        if( startX != firstX ) {
            _horizontalLines[ indexH ]->addSeg( startX,
                                      _horizontalLines[ indexH ]->_lineCoords.y1,
                                      lastX,
                                      _horizontalLines[ indexH ]->_lineCoords.y1 );
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?