// Copyright 1999 // College of Computer Science // Northeastern University Boston MA 02115 // This software may be used for educational purposes as long as this copyright // notice is retained at the top of all files // Should this software be modified, the words "Modified from Original" must be // included as a comment below this notice // All publication rights are retained. This software or its documentation may // not be published in any media either in whole or in part. /////////////////////////////////////////////////////////////////////////////// // Scale2D.cpp /////////////////////////////////////////////////////////////////////////////// #include "CoreTools.h" // needed for core tools compile in Win32 #include "Scale2D.h" // LinearScale2D Set LinearScale2D& LinearScale2D::Set(const Rect2D& Bounds, const RectData& Limits) { double X1; double Y1; double X2; double Y2; Bounds.Get(X1, Y1, X2, Y2); short x1; short y1; short x2; short y2; Limits.Get(x1, y1, x2, y2); sx.Set(X1, X2, x1, x2); // maintain x direction sy.Set(Y1, Y2, y2, y1); // reverse y direction return *this; } // LinearScale2D SetTrueShape LinearScale2D& LinearScale2D::SetTrueShape(const Rect2D& Bounds, const RectData& Limits) { // extract rectangle data double X1; double Y1; double X2; double Y2; Bounds.Get(X1, Y1, X2, Y2); short x1; short y1; short x2; short y2; Limits.Get(x1, y1, x2, y2); // compute factors and offsets double FactorX; double FactorY; double OffsetX; double OffsetY; // maintain x direction when computing FactorX FactorX = ComputeFactor(X1, X2, x1, x2); // reverse y direction when computing FactorY FactorY = - ComputeFactor(Y1, Y2, y1, y2); // now equalize factors in magnitude EqualizeSize(FactorX, FactorY); // finally compute offsets to center image of Bounds within Limits OffsetX = ComputeOffset(X1, X2, x1, x2, FactorX); OffsetY = ComputeOffset(Y1, Y2, y1, y2, FactorY); // now set scale objects sx.Set(FactorX, OffsetX); sy.Set(FactorY, OffsetY); return *this; }