Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_four_point_interpolator_forward.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_FOUR_POINT_INTERPOLATOR_FORWARD_H
8#define __KIS_FOUR_POINT_INTERPOLATOR_FORWARD_H
9
10#include <QPolygon>
11#include <QPointF>
12
13
14
23{
24public:
25 KisFourPointInterpolatorForward(const QPolygonF &srcPolygon, const QPolygonF &dstPolygon) {
26 m_srcBase = srcPolygon[0];
27 m_dstBase = dstPolygon[0];
28
29 m_h0 = dstPolygon[1] - dstPolygon[0]; // BA
30 m_h1 = dstPolygon[2] - dstPolygon[3]; // DC
31
32 m_v0 = dstPolygon[3] - dstPolygon[0]; // CA
33
34 m_forwardCoeffX = 1.0 / (srcPolygon[1].x() - srcPolygon[0].x());
35 m_forwardCoeffY = 1.0 / (srcPolygon[3].y() - srcPolygon[0].y());
36
37 m_xProp = 0;
38 m_yProp = 0;
39 }
40
41 inline QPointF map(const QPointF &pt) {
42 setX(pt.x());
43 setY(pt.y());
44 return getValue();
45 }
46
47 inline void setX(qreal x) {
48 qreal diff = x - m_srcBase.x();
49 m_xProp = diff * m_forwardCoeffX;
50 }
51
52 inline void setY(qreal y) {
53 qreal diff = y - m_srcBase.y();
54 m_yProp = diff * m_forwardCoeffY;
55 }
56
57 inline QPointF getValue() const {
58 QPointF dstPoint = m_dstBase +
59 m_yProp * m_v0 +
60 m_xProp * (m_yProp * m_h1 + (1.0 - m_yProp) * m_h0);
61
62 return dstPoint;
63 }
64
65private:
66 QPointF m_srcBase;
67 QPointF m_dstBase;
68
69 QPointF m_h0;
70 QPointF m_h1;
71 QPointF m_v0;
72
75
76 qreal m_xProp;
77 qreal m_yProp;
78};
79
80#endif /* __KIS_FOUR_POINT_INTERPOLATOR_FORWARD_H */
QPointF dstPoint
KisFourPointInterpolatorForward(const QPolygonF &srcPolygon, const QPolygonF &dstPolygon)