예제 #1
0
    inline void swapDirection() {
        rowIncrement *= -1;
        SANITY_ASSERT_MSG(forwardStack.isEmpty(),
                          "FATAL: the forward stack must be empty "
                          "on a direction swap");

        forwardStack = QStack<KisFillInterval>(backwardMap.fetchAllIntervals(rowIncrement));
        backwardMap.clear();
    }
예제 #2
0
void KisFillIntervalMap::cropInterval(KisFillInterval *interval)
{
    Private::IteratorRange range;
    range = m_d->findFirstIntersectingInterval(*interval);

    Private::LineIntervalMap::iterator it = range.beginIt;

    while (interval->isValid() && it != range.endIt) {
        bool needsIncrement = true;

        if (it->start <= interval->start && it->end >= interval->start) {
            int savedIntervalStart = interval->start;
            interval->start = it->end + 1;

            /**
             * It might happen that we need to split a backward
             * interval into two pieces
             */
            if (it->end > interval->end) {
                KisFillInterval newInterval(interval->end + 1, it->end, it->row);
                range.rowMapIt->insert(newInterval.start, newInterval);
            }

            it->end = savedIntervalStart - 1;

            /**
             * It might also happen that the backward interval is
             * fully eaten by the forward interval. This is possible
             * only in case the BW-interval was generated by the
             * strictly adjacent FW-interval, that is (it->start ==
             * interval->start)
             */
            if (!it->isValid()) {
                it = range.rowMapIt->erase(it);
                needsIncrement = false;
            }
        } else if (it->start <= interval->end && it->end >= interval->end) {
            int savedIntervalEnd = interval->end;
            interval->end = it->start - 1;
            it->start = savedIntervalEnd + 1;

            /**
             * The BW-interval is eaten by the FW-interval. See a
             * comment above
             */
            if (!it->isValid()) {
                it = range.rowMapIt->erase(it);
                needsIncrement = false;
            }
        } else if (it->start > interval->end) {
            break;
        }

#ifdef ENABLE_FILL_SANITY_CHECKS
        else if (it->start > interval->start && it->end < interval->end) {
            SANITY_ASSERT_MSG(0, "FATAL: The backward interval cannot fully reside inside the forward interval");
            it->invalidate();
            interval->invalidate();
        }

        SANITY_ASSERT_MSG(it == range.endIt || it->isValid(), "FATAL: The backward interval cannot become invalid during the crop action");

#endif /* ENABLE_FILL_SANITY_CHECKS */

        if (needsIncrement) {
            it++;
        }
    }
}