Commit eb91135f authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix assert when trying to access outside of the cached gradient

parent 206f2477
......@@ -132,4 +132,32 @@ QRect blowRect(const QRect &rect, qreal coeff)
return rect.adjusted(-w, -h, w, h);
}
template <class Point, class Rect>
inline Point ensureInRectImpl(Point pt, const Rect &bounds)
{
if (pt.x() > bounds.right()) {
pt.rx() = bounds.right();
} else if (pt.x() < bounds.left()) {
pt.rx() = bounds.left();
}
if (pt.y() > bounds.bottom()) {
pt.ry() = bounds.bottom();
} else if (pt.y() < bounds.top()) {
pt.ry() = bounds.top();
}
return pt;
}
QPoint ensureInRect(QPoint pt, const QRect &bounds)
{
return ensureInRectImpl(pt, bounds);
}
QPointF ensureInRect(QPointF pt, const QRectF &bounds)
{
return ensureInRectImpl(pt, bounds);
}
}
......@@ -222,6 +222,9 @@ QPainterPath KRITAIMAGE_EXPORT smallArrow();
*/
QRect KRITAIMAGE_EXPORT blowRect(const QRect &rect, qreal coeff);
QPoint ensureInRect(QPoint pt, const QRect &bounds);
QPointF ensureInRect(QPointF pt, const QRectF &bounds);
}
#endif /* __KIS_ALGEBRA_2D_H */
......@@ -23,10 +23,11 @@
#include <cmath>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include "kis_algebra_2d.h"
using namespace KisBSplines;
......@@ -76,5 +77,6 @@ KisCachedGradientShapeStrategy::~KisCachedGradientShapeStrategy()
double KisCachedGradientShapeStrategy::valueAt(double x, double y) const
{
return m_d->spline->value(x, y);
QPointF pt = KisAlgebra2D::ensureInRect(QPointF(x, y), m_d->rc);
return m_d->spline->value(pt.x(), pt.y());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment