| 116 | } |
| 117 | |
| 118 | Vector3D Transform::mapSceneToLogical(QPointF scenePoint, const DatapickerImage::ReferencePoints& axisPoints) { |
| 119 | X[3] = scenePoint.x(); |
| 120 | Y[3] = scenePoint.y(); |
| 121 | |
| 122 | if (mapTypeToCartesian(axisPoints)) { |
| 123 | double sin; |
| 124 | double cos; |
| 125 | double scaleOfX; |
| 126 | double scaleOfY; |
| 127 | if (((Y[1] - Y[0]) * (x[2] - x[0]) - (Y[2] - Y[0]) * (x[1] - x[0])) != 0) { |
| 128 | double tan = ((X[1] - X[0]) * (x[2] - x[0]) - (X[2] - X[0]) * (x[1] - x[0])) / ((Y[1] - Y[0]) * (x[2] - x[0]) - (Y[2] - Y[0]) * (x[1] - x[0])); |
| 129 | sin = tan / sqrt(1 + tan * tan); |
| 130 | cos = sqrt(1 - sin * sin); |
| 131 | } else { |
| 132 | sin = 1; |
| 133 | cos = 0; |
| 134 | } |
| 135 | |
| 136 | if ((x[1] - x[0]) != 0) |
| 137 | scaleOfX = (x[1] - x[0]) / ((X[1] - X[0]) * cos - (Y[1] - Y[0]) * sin); |
| 138 | else |
| 139 | scaleOfX = (x[2] - x[0]) / ((X[2] - X[0]) * cos - (Y[2] - Y[0]) * sin); |
| 140 | |
| 141 | if ((y[1] - y[0]) != 0) |
| 142 | scaleOfY = (y[1] - y[0]) / ((X[1] - X[0]) * sin + (Y[1] - Y[0]) * cos); |
| 143 | else |
| 144 | scaleOfY = (y[2] - y[0]) / ((X[2] - X[0]) * sin + (Y[2] - Y[0]) * cos); |
| 145 | |
| 146 | x[3] = x[0] + (((X[3] - X[0]) * cos - (Y[3] - Y[0]) * sin) * scaleOfX); |
| 147 | y[3] = y[0] + (((X[3] - X[0]) * sin + (Y[3] - Y[0]) * cos) * scaleOfY); |
| 148 | return mapCartesianToType(QPointF(x[3], y[3]), axisPoints); |
| 149 | } |
| 150 | return {}; |
| 151 | } |
| 152 | |
| 153 | Vector3D Transform::mapSceneLengthToLogical(QPointF errorSpan, const DatapickerImage::ReferencePoints& axisPoints) { |
| 154 | return mapSceneToLogical(errorSpan, axisPoints) - mapSceneToLogical(QPointF(0, 0), axisPoints); |
no test coverage detected