Krita Source Code Documentation
Loading...
Searching...
No Matches
KisFillIntervalMap Struct Reference

#include <kis_fill_interval_map.h>

+ Inheritance diagram for KisFillIntervalMap:

Classes

struct  IteratorRange
 

Public Types

typedef QHash< int, LineIntervalMapGlobalMap
 
typedef QMap< int, KisFillIntervalLineIntervalMap
 

Public Member Functions

void clear ()
 
void cropInterval (KisFillInterval *interval)
 
QStack< KisFillIntervalfetchAllIntervals (int rowCorrection=0) const
 
IteratorRange findFirstIntersectingInterval (const KisFillInterval &interval)
 
void insertInterval (const KisFillInterval &interval)
 
 KisFillIntervalMap ()
 
 ~KisFillIntervalMap ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Public Attributes

GlobalMap map
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Attributes

const QScopedPointer< Privatem_d
 

Friends

class KisFillIntervalMapTest
 

Detailed Description

Definition at line 17 of file kis_fill_interval_map.h.

Member Typedef Documentation

◆ GlobalMap

Definition at line 12 of file kis_fill_interval_map_p.h.

◆ LineIntervalMap

Definition at line 11 of file kis_fill_interval_map_p.h.

Constructor & Destructor Documentation

◆ KisFillIntervalMap()

KisFillIntervalMap::KisFillIntervalMap ( )

Definition at line 13 of file kis_fill_interval_map.cpp.

14 : m_d(new Private)
15{
16}
const QScopedPointer< Private > m_d

◆ ~KisFillIntervalMap()

KisFillIntervalMap::~KisFillIntervalMap ( )

Definition at line 18 of file kis_fill_interval_map.cpp.

19{
20}

Member Function Documentation

◆ clear()

void KisFillIntervalMap::clear ( )

Definition at line 159 of file kis_fill_interval_map.cpp.

160{
161 m_d->map.clear();
162}

References m_d.

◆ cropInterval()

void KisFillIntervalMap::cropInterval ( KisFillInterval * interval)

It might happen that we need to split a backward interval into two pieces

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)

The BW-interval is eaten by the FW-interval. See a comment above

Definition at line 32 of file kis_fill_interval_map.cpp.

33{
34 Private::IteratorRange range;
35 range = m_d->findFirstIntersectingInterval(*interval);
36
37 Private::LineIntervalMap::iterator it = range.beginIt;
38
39 while (interval->isValid() && it != range.endIt) {
40 bool needsIncrement = true;
41
42 if (it->start <= interval->start && it->end >= interval->start) {
43 int savedIntervalStart = interval->start;
44 interval->start = it->end + 1;
45
50 if (it->end > interval->end) {
51 KisFillInterval newInterval(interval->end + 1, it->end, it->row);
52 range.rowMapIt->insert(newInterval.start, newInterval);
53 }
54
55 it->end = savedIntervalStart - 1;
56
64 if (!it->isValid()) {
65 it = range.rowMapIt->erase(it);
66 needsIncrement = false;
67 }
68 } else if (it->start <= interval->end && it->end >= interval->end) {
69 int savedIntervalEnd = interval->end;
70 interval->end = it->start - 1;
71 it->start = savedIntervalEnd + 1;
72
77 if (!it->isValid()) {
78 it = range.rowMapIt->erase(it);
79 needsIncrement = false;
80 }
81 } else if (it->start > interval->end) {
82 break;
83 }
84
85#ifdef ENABLE_FILL_SANITY_CHECKS
86 else if (it->start > interval->start && it->end < interval->end) {
87 SANITY_ASSERT_MSG(0, "FATAL: The backward interval cannot fully reside inside the forward interval");
88 interval->invalidate();
89 it->invalidate();
90 it = range.rowMapIt->erase(it);
91 needsIncrement = false;
92 }
93
94 // The code above should have removed the invalidated backward interval,
95 // just verify that
96 KIS_SAFE_ASSERT_RECOVER((it == range.endIt || it->isValid()) &&
97 "FATAL: The backward interval cannot become "
98 "invalid during the crop action") {
99 it = range.rowMapIt->erase(it);
100 needsIncrement = false;
101 }
102#endif /* ENABLE_FILL_SANITY_CHECKS */
103
104 if (needsIncrement) {
105 it++;
106 }
107 }
108}
bool isValid() const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define SANITY_ASSERT_MSG(cond, msg)

References KisFillInterval::end, KisFillInterval::invalidate(), KisFillInterval::isValid(), KIS_SAFE_ASSERT_RECOVER, m_d, SANITY_ASSERT_MSG, and KisFillInterval::start.

◆ fetchAllIntervals()

QStack< KisFillInterval > KisFillIntervalMap::fetchAllIntervals ( int rowCorrection = 0) const

Definition at line 135 of file kis_fill_interval_map.cpp.

136{
137 QStack<KisFillInterval> intervals;
138
139 Private::GlobalMap::const_iterator rowMapIt = m_d->map.constBegin();
140 Private::GlobalMap::const_iterator rowMapEndIt = m_d->map.constEnd();
141
142 while (rowMapIt != rowMapEndIt) {
143 Private::LineIntervalMap::const_iterator it = rowMapIt->constBegin();
144 Private::LineIntervalMap::const_iterator end = rowMapIt->constEnd();
145
146 while(it != end) {
147 KisFillInterval interval = *it;
148 interval.row += rowCorrection;
149 intervals.append(interval);
150 ++it;
151 }
152
153 ++rowMapIt;
154 }
155
156 return intervals;
157}

References m_d, and KisFillInterval::row.

◆ findFirstIntersectingInterval()

IteratorRange KisFillIntervalMap::findFirstIntersectingInterval ( const KisFillInterval & interval)

◆ insertInterval()

void KisFillIntervalMap::insertInterval ( const KisFillInterval & interval)

Definition at line 22 of file kis_fill_interval_map.cpp.

23{
24 Private::GlobalMap::iterator rowMap = m_d->map.find(interval.row);
25 if (rowMap == m_d->map.end()) {
26 rowMap = m_d->map.insert(interval.row, Private::LineIntervalMap());
27 }
28
29 rowMap->insert(interval.start, interval);
30}

References m_d, KisFillInterval::row, and KisFillInterval::start.

Friends And Related Symbol Documentation

◆ KisFillIntervalMapTest

friend class KisFillIntervalMapTest
friend

Definition at line 32 of file kis_fill_interval_map.h.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisFillIntervalMap::m_d
private

Definition at line 36 of file kis_fill_interval_map.h.

◆ map

GlobalMap KisFillIntervalMap::map

Definition at line 33 of file kis_fill_interval_map_p.h.


The documentation for this struct was generated from the following files: