toSourcePoint function

Offset toSourcePoint(
  1. Offset viewport, {
  2. required Matrix4 hostCamera,
  3. Matrix4? viewerCamera,
  4. CropImageLayer? crop,
})

Map a viewport-space pointer position into source-image space: undo the user's viewerCamera pan/zoom, then invert the cropped-view transform when crop has applied edits, else the plain hostCamera fit.

Implementation

Offset toSourcePoint(
  Offset viewport, {
  required vmath.Matrix4 hostCamera,
  vmath.Matrix4? viewerCamera,
  CropImageLayer? crop,
}) {
  var v = viewport;
  if (viewerCamera != null) {
    final inv = vmath.Matrix4.copy(viewerCamera)..invert();
    final vec = vmath.Vector3(v.dx, v.dy, 0)..applyMatrix4(inv);
    v = Offset(vec.x, vec.y);
  }
  if (crop != null && crop.hasAppliedEdits) {
    return crop.viewportToSource(v, camera: hostCamera);
  }
  return DrawImageLayer.toImageSpace(v, hostCamera);
}