59 {
60
61 qreal xx, yy;
62 m_template.imageToScreenTransform().map(x, y, &xx, &yy);
63
65 yy -= std::floor(yy /
m_template.macrocellSize().height()) *
m_template.macrocellSize().height();
66
67 QPointF templatePoint =
m_template.screenToTemplateTransform().map(QPointF(xx, yy)) +
69
70
71
72 const int ix0 =
73 templatePoint.x() < 0.0 ?
m_template.templateSize().width() - 1 :
74 (templatePoint.x() >=
m_template.templateSize().width() ? 0.0 :
75 static_cast<int>(std::floor(templatePoint.x())));
76 const int iy0 =
77 templatePoint.y() < 0.0 ?
m_template.templateSize().height() - 1 :
78 (templatePoint.y() >=
m_template.templateSize().height() ? 0.0 :
79 static_cast<int>(std::floor(templatePoint.y())));
80 const int ix1 = ix0 ==
m_template.templateSize().width() - 1 ? 0 : ix0 + 1;
81 const int iy1 = iy0 ==
m_template.templateSize().height() - 1 ? 0 : iy0 + 1;
82
83 const qreal topLeftValue =
m_template.templateData()[iy0 *
m_template.templateSize().width() + ix0];
84 const qreal topRightValue =
m_template.templateData()[iy0 *
m_template.templateSize().width() + ix1];
85 const qreal bottomLeftValue =
m_template.templateData()[iy1 *
m_template.templateSize().width() + ix0];
86 const qreal bottomRightValue =
m_template.templateData()[iy1 *
m_template.templateSize().width() + ix1];
87
88 const qreal fractionalX = templatePoint.x() - std::floor(templatePoint.x());
89 const qreal fractionalY = templatePoint.y() - std::floor(templatePoint.y());
90
91 const qreal a = topLeftValue * (1.0 - fractionalX) + topRightValue * fractionalX;
92 const qreal
b = bottomLeftValue * (1.0 - fractionalX) + bottomRightValue * fractionalX;
93 const qreal c = a * (1.0 - fractionalY) + b * fractionalY;
94
95 return c;
96 }