Commit 552638b8 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Added ability to select multiple points in Warp and Cage transforms

Press Ctrl to select multiple points.

Move --- drag from the inside of the polygon
Rotate --- drag from the outside of the polygon

CCMAIL:kimageshop@kde.org
parent 87fbfaf9
......@@ -77,4 +77,12 @@ QPointF KRITAIMAGE_EXPORT transformAsBase(const QPointF &pt, const QPointF &base
return result;
}
qreal KRITAIMAGE_EXPORT angleBetweenVectors(const QPointF &v1, const QPointF &v2)
{
qreal a1 = std::atan2(v1.y(), v1.x());
qreal a2 = std::atan2(v2.y(), v2.x());
return a2 - a1;
}
}
......@@ -129,6 +129,43 @@ void KRITAIMAGE_EXPORT adjustIfOnPolygonBoundary(const QPolygonF &poly, int poly
**/
QPointF transformAsBase(const QPointF &pt, const QPointF &base1, const QPointF &base2);
qreal angleBetweenVectors(const QPointF &v1, const QPointF &v2);
namespace Private {
inline void resetEmptyRectangle(const QPoint &pt, QRect *rc) {
*rc = QRect(pt, QSize(1, 1));
}
inline void resetEmptyRectangle(const QPointF &pt, QRectF *rc) {
static qreal eps = 1e-10;
*rc = QRectF(pt, QSizeF(eps, eps));
}
}
template <class Point, class Rect>
inline void accumulateBounds(const Point &pt, Rect *bounds)
{
if (bounds->isEmpty()) {
Private::resetEmptyRectangle(pt, bounds);
}
if (pt.x() > bounds->right()) {
bounds->setRight(pt.x());
}
if (pt.x() < bounds->left()) {
bounds->setLeft(pt.x());
}
if (pt.y() > bounds->bottom()) {
bounds->setBottom(pt.y());
}
if (pt.y() < bounds->top()) {
bounds->setTop(pt.y());
}
}
}
#endif /* __KIS_ALGEBRA_2D_H */
......@@ -521,7 +521,7 @@ QImage KisCageTransformWorker::runOnQImage(QPointF *newOffset)
QRectF dstBounds;
foreach (const QPointF &pt, transformedPoints) {
kisAccumulateBounds(pt, &dstBounds);
KisAlgebra2D::accumulateBounds(pt, &dstBounds);
}
const QRectF srcBounds(m_d->srcImageOffset, m_d->srcImage.size());
......
......@@ -199,25 +199,5 @@ inline QRect kisEnsureInRect(QRect rc, const QRect &bounds)
return rc;
}
template <class Point, class Rect>
inline void kisAccumulateBounds(const Point &pt, Rect *bounds)
{
if (pt.x() > bounds->right()) {
bounds->setRight(pt.x());
}
if (pt.x() < bounds->left()) {
bounds->setLeft(pt.x());
}
if (pt.y() > bounds->bottom()) {
bounds->setBottom(pt.y());
}
if (pt.y() < bounds->top()) {
bounds->setTop(pt.y());
}
}
#endif // KISGLOBAL_H_
......@@ -250,5 +250,25 @@ void KisCageTransformWorkerTest::testTransformAsBase()
QCOMPARE(result, QPointF(-2.0, 0.0));
}
void KisCageTransformWorkerTest::testAngleBetweenVectors()
{
QPointF b1(1.0, 0.0);
QPointF b2(2.0, 0.0);
qreal result;
b1 = QPointF(1.0, 0.0);
b2 = QPointF(0.0, 1.0);
result = KisAlgebra2D::angleBetweenVectors(b1, b2);
QCOMPARE(result, M_PI_2);
b1 = QPointF(1.0, 0.0);
b2 = QPointF(std::sqrt(0.5), std::sqrt(0.5));
result = KisAlgebra2D::angleBetweenVectors(b1, b2);
QCOMPARE(result, M_PI / 4);
QTransform t;
t.rotateRadians(M_PI / 4);
QCOMPARE(t.map(b1), b2);
}
QTEST_KDEMAIN(KisCageTransformWorkerTest, GUI)
......@@ -36,6 +36,7 @@ private slots:
void testUnityGreenCoordinates();
void testTransformAsBase();
void testAngleBetweenVectors();
};
#endif /* __KIS_CAGE_TRANSFORM_WORKER_TEST_H */
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