diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-03-07 11:24:51 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-03-07 11:24:51 -0500 |
commit | 621887cfaac4bef4b6849037c0d72f7e7b66fa03 (patch) | |
tree | 678cac70a5d86372c487105981ec40635f99706a /libs/canvas/poly_item.cc | |
parent | 170aee13ebc48a8b47733e189d11ad7e29cdc426 (diff) |
slightly optimize bounding box computation for ArdourCanvas::PolyItem by avoiding inner conditional
Diffstat (limited to 'libs/canvas/poly_item.cc')
-rw-r--r-- | libs/canvas/poly_item.cc | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc index 3b2e2efad9..eeb186fd7f 100644 --- a/libs/canvas/poly_item.cc +++ b/libs/canvas/poly_item.cc @@ -37,27 +37,28 @@ PolyItem::PolyItem (Group* parent) void PolyItem::compute_bounding_box () const { - bool have_one = false; - Rect bbox; + + if (!_points.empty()) { - for (Points::const_iterator i = _points.begin(); i != _points.end(); ++i) { - if (have_one) { + Rect bbox; + Points::const_iterator i = _points.begin(); + + bbox.x0 = bbox.x1 = i->x; + bbox.y0 = bbox.y1 = i->y; + + while (i != _points.end()) { bbox.x0 = min (bbox.x0, i->x); bbox.y0 = min (bbox.y0, i->y); bbox.x1 = max (bbox.x1, i->x); bbox.y1 = max (bbox.y1, i->y); - } else { - bbox.x0 = bbox.x1 = i->x; - bbox.y0 = bbox.y1 = i->y; - have_one = true; + ++i; } - } + _bounding_box = bbox.expand (_outline_width / 2); - if (!have_one) { - _bounding_box = boost::optional<Rect> (); + } else { - _bounding_box = bbox.expand (_outline_width / 2); + _bounding_box = boost::optional<Rect> (); } _bounding_box_dirty = false; |