MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / insert

Method insert

utilities/olcUTIL_QuadTree.h:104–129  ·  view source on GitHub ↗

Insert a region into this area

Source from the content-addressed store, hash-verified

102
103 // Insert a region into this area
104 QuadTreeItemLocation<pT> insert(const pT item, const geom2d::rect<CTYPE>& itemsize)
105 {
106 for (int i = 0; i < 4; i++)
107 {
108 if (geom2d::contains(m_rChild[i], itemsize))
109 {
110 // Have we reached depth limit?
111 if (m_depth + 1 < m_maxdepth)
112 {
113 // No, so does child exist?
114 if (!m_pChild[i])
115 {
116 // No, so create it
117 m_pChild[i] = std::make_shared<DynamicQuadTree<pT>>(m_rChild[i], m_depth + 1, m_maxdepth);
118 }
119
120 // Yes, so add item to it
121 return m_pChild[i]->insert(item, itemsize);
122 }
123 }
124 }
125
126 // It didnt fit, so item must belong to this geom2d::rect<CTYPE>
127 m_pItems.push_back({ itemsize, item });
128 return { &m_pItems, std::prev(m_pItems.end()) };
129 }
130
131 void relocate(pT item, const geom2d::rect<CTYPE>& rArea)
132 {

Callers 6

UpdateTextEntryMethod · 0.45
insert_afterMethod · 0.45
insertMethod · 0.45
relocateMethod · 0.45
intersectsFunction · 0.45
projectFunction · 0.45

Calls 3

containsFunction · 0.85
push_backMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected