Example #1
0
bool NodeList_sV::add(Node_sV node)
{
    bool add = true;

#ifdef DEBUG_NL
    qDebug() << "Before adding: \n" << *this;
#endif

    node.setX(qMax(.0, node.x()));
    node.setY(qMax(.0, qMin(m_maxY, node.y())));

    int pos = find(node.x());
    if (pos >= 0 && m_list.size() > pos) {
        add = fabs(node.x()-m_list.at(pos).x()) > m_minDist;
#ifdef DEBUG_NL
        qDebug() << "Left distance is " << fabs(node.x()-m_list.at(pos).x());
#endif
        if (add && m_list.size() > pos+1) {
            add = fabs(node.x()-m_list.at(pos+1).x()) > m_minDist;
#ifdef DEBUG_NL
            qDebug() << "Right distance is " << fabs(node.x()-m_list.at(pos+1).x());
#endif
        }
    }
#ifdef DEBUG_NL
    qDebug() << "Adding? " << add;
#endif
    if (add) {
        m_list.append(node);
        qSort(m_list);

        if (m_list.size() > 1) {
            m_segments.grow();
        }

        // Reset curve type of neighbours if this is a linear node
        int index = m_list.indexOf(node);
        if (index > 0 && node.leftCurveType() == CurveType_Linear) {
            m_list[index-1].setRightCurveType(CurveType_Linear);
        }
        if (index < m_list.size()-1 && node.rightCurveType() == CurveType_Linear) {
            m_list[index+1].setLeftCurveType(CurveType_Linear);
        }

        fixHandles(index-1);
        fixHandles(index);
    }
#ifdef DEBUG_NL
    qDebug() << "After adding: \n" << *this;
#endif

    validate();
    return add;
}