Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Use std::accumulate for calculating the bounds of shapes and nodes

Dmitry Kazakov69daaa65ab7c
diff --git a/libs/flake/KoShape.cpp b/libs/flake/KoShape.cpp
index fa54b747f2..15abc6cabd 100644
--- a/libs/flake/KoShape.cpp
+++ b/libs/flake/KoShape.cpp
@@ -10,6 +10,7 @@
#include <limits>
+#include "KisMpl.h"
#include "KoShape.h"
#include "KoShape_p.h"
#include "KoShapeContainer.h"
@@ -311,11 +312,8 @@ QRectF KoShape::boundingRect() const
QRectF KoShape::boundingRect(const QList<KoShape *> &shapes)
{
- QRectF boundingRect;
- Q_FOREACH (KoShape *shape, shapes) {
- boundingRect |= shape->boundingRect();
- }
- return boundingRect;
+ return std::accumulate(shapes.begin(), shapes.end(), QRectF(),
+ kismpl::mem_bit_or(&KoShape::boundingRect));
}
QRectF KoShape::absoluteOutlineRect() const
@@ -325,11 +323,8 @@ QRectF KoShape::absoluteOutlineRect() const
QRectF KoShape::absoluteOutlineRect(const QList<KoShape *> &shapes)
{
- QRectF absoluteOutlineRect;
- Q_FOREACH (KoShape *shape, shapes) {
- absoluteOutlineRect |= shape->absoluteOutlineRect();
- }
- return absoluteOutlineRect;
+ return std::accumulate(shapes.begin(), shapes.end(), QRectF(),
+ kismpl::mem_bit_or(&KoShape::absoluteOutlineRect));
}
QTransform KoShape::absoluteTransformation() const
diff --git a/libs/ui/kis_clipboard.cc b/libs/ui/kis_clipboard.cc
index eb13b478d8..4a699ec0ad 100644
--- a/libs/ui/kis_clipboard.cc
+++ b/libs/ui/kis_clipboard.cc
@@ -327,10 +327,9 @@ KisPaintDeviceSP KisClipboard::clipFromKritaLayers(const KoColorSpace *cs) const
if (nodes.size() > 1) {
// we explicitly include point (0,0) into the bounds since that
// is a requirement for the image
- QRect bounds = QRect(0, 0, 1, 1);
- Q_FOREACH (KisNodeSP node, nodes) {
- bounds |= node->exactBounds();
- }
+ const QRect bounds =
+ std::accumulate(nodes.begin(), nodes.end(), QRect(0, 0, 1, 1),
+ kismpl::mem_bit_or(&KisNode::exactBounds));
// if no color space provided choose the most used one in the layer data
if (cs == nullptr) {