# HG changeset patch # User Sebastien Jodogne # Date 1555657695 -7200 # Node ID 919226caca825a11786686df7b129d7942bbe593 # Parent 911297a277c4d4ac60c697dcc8350200f0cdaf19 AffineTransform2D::ComputeZoom() diff -r 911297a277c4 -r 919226caca82 Framework/Toolbox/AffineTransform2D.cpp --- a/Framework/Toolbox/AffineTransform2D.cpp Thu Apr 18 18:06:29 2019 +0200 +++ b/Framework/Toolbox/AffineTransform2D.cpp Fri Apr 19 09:08:15 2019 +0200 @@ -130,6 +130,36 @@ } + double AffineTransform2D::ComputeZoom() const + { + // Compute the length of the (0,0)-(1,1) diagonal (whose + // length is sqrt(2)) instead of the (0,0)-(1,0) unit segment, + // in order to cope with possible anisotropic zooming + + double x1 = 0; + double y1 = 0; + Apply(x1, y1); + + double x2 = 1; + double y2 = 1; + Apply(x2, y2); + + double dx = x2 - x1; + double dy = y2 - y1; + + double zoom = sqrt(dx * dx + dy * dy) / sqrt(2.0); + + if (LinearAlgebra::IsCloseToZero(zoom)) + { + return 1; // Default value if transform is ill-conditioned + } + else + { + return zoom; + } + } + + AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a) { AffineTransform2D t; diff -r 911297a277c4 -r 919226caca82 Framework/Toolbox/AffineTransform2D.h --- a/Framework/Toolbox/AffineTransform2D.h Thu Apr 18 18:06:29 2019 +0200 +++ b/Framework/Toolbox/AffineTransform2D.h Fri Apr 19 09:08:15 2019 +0200 @@ -60,6 +60,8 @@ void ConvertToOpenGLMatrix(float target[16], unsigned int canvasWidth, unsigned int canvasHeight) const; + + double ComputeZoom() const; static AffineTransform2D Invert(const AffineTransform2D& a);