13
0

C++ auto iteration FTW

This commit is contained in:
Paul Davis 2023-01-12 17:05:23 -07:00
parent 7e4a3dce01
commit 0f611b4efa
2 changed files with 19 additions and 23 deletions

View File

@ -1010,19 +1010,19 @@ Item::add_child_bounding_boxes (bool include_hidden) const
have_one = true; have_one = true;
} }
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) { for (auto const & item : _items) {
if (!(*i)->visible() && !include_hidden) { if (!item->visible() && !include_hidden) {
continue; continue;
} }
Rect item_bbox = (*i)->bounding_box (); Rect item_bbox = item->bounding_box ();
if (!item_bbox) { if (!item_bbox) {
continue; continue;
} }
Rect child_bbox = (*i)->item_to_parent (item_bbox); Rect child_bbox = item->item_to_parent (item_bbox);
if (have_one) { if (have_one) {
bbox = bbox.extend (child_bbox); bbox = bbox.extend (child_bbox);
} else { } else {

View File

@ -44,15 +44,14 @@ DumbLookupTable::DumbLookupTable (Item const & item)
vector<Item *> vector<Item *>
DumbLookupTable::get (Rect const &area) DumbLookupTable::get (Rect const &area)
{ {
list<Item *> const & items = _item.items ();
vector<Item *> vitems; vector<Item *> vitems;
#if 1 #if 1
for (list<Item *>::const_iterator i = items.begin(); i != items.end(); ++i) { for (auto const & item : _item.items()) {
Rect item_bbox = (*i)->bounding_box (); Rect item_bbox = item->bounding_box ();
if (!item_bbox) continue; if (!item_bbox) continue;
Rect item = (*i)->item_to_window (item_bbox); Rect item_rect = item->item_to_window (item_bbox);
if (item.intersection (area)) { if (item_rect.intersection (area)) {
vitems.push_back (*i); vitems.push_back (item);
} }
} }
#else #else
@ -66,13 +65,12 @@ DumbLookupTable::items_at_point (Duple const & point) const
{ {
/* Point is in window coordinate system */ /* Point is in window coordinate system */
list<Item *> const & items (_item.items ());
vector<Item *> vitems; vector<Item *> vitems;
for (list<Item *>::const_iterator i = items.begin(); i != items.end(); ++i) { for (auto const & item : _item.items()) {
if ((*i)->covers (point)) { if (item->covers (point)) {
vitems.push_back (*i); vitems.push_back (item);
} }
} }
@ -84,16 +82,15 @@ DumbLookupTable::has_item_at_point (Duple const & point) const
{ {
/* Point is in window coordinate system */ /* Point is in window coordinate system */
list<Item *> const & items (_item.items ());
vector<Item *> vitems; vector<Item *> vitems;
for (list<Item *>::const_iterator i = items.begin(); i != items.end(); ++i) { for (auto const & item : _item.items()) {
if (!(*i)->visible()) { if (!item->visible()) {
continue; continue;
} }
if ((*i)->covers (point)) { if (item->covers (point)) {
// std::cerr << "\t\t" << (*i)->whatami() << '/' << (*i)->name << " covers " << point << std::endl; // std::cerr << "\t\t" << (*i)->whatami() << '/' << (*i)->name << " covers " << point << std::endl;
return true; return true;
@ -133,16 +130,15 @@ OptimizingLookupTable::OptimizingLookupTable (Item const & item, int items_per_c
// cout << "BUILD bbox=" << bbox << ", cellsize=" << _cell_size << ", offset=" << _offset << ", dimension=" << _dimension << "\n"; // cout << "BUILD bbox=" << bbox << ", cellsize=" << _cell_size << ", offset=" << _offset << ", dimension=" << _dimension << "\n";
for (list<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) { for (auto const & our_item : _item.items()) {
/* item bbox in its own coordinates */ /* item bbox in its own coordinates */
Rect item_bbox = (*i)->bounding_box (); Rect item_bbox = our_item->bounding_box ();
if (!item_bbox) { if (!item_bbox) {
continue; continue;
} }
/* and in the item's coordinates */ /* and in the item's coordinates */
Rect const item_bbox_in_item = (*i)->item_to_parent (item_bbox); Rect const item_bbox_in_item = our_item->item_to_parent (item_bbox);
int x0, y0, x1, y1; int x0, y0, x1, y1;
area_to_indices (item_bbox_in_item, x0, y0, x1, y1); area_to_indices (item_bbox_in_item, x0, y0, x1, y1);
@ -176,7 +172,7 @@ OptimizingLookupTable::OptimizingLookupTable (Item const & item, int items_per_c
for (int x = x0; x < x1; ++x) { for (int x = x0; x < x1; ++x) {
for (int y = y0; y < y1; ++y) { for (int y = y0; y < y1; ++y) {
_cells[x][y].push_back (*i); _cells[x][y].push_back (our_item);
} }
} }
} }