1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.1 3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 4 // 5 // Permission to copy, use, modify, sell and distribute this software 6 // is granted provided this copyright notice appears in all copies. 7 // This software is provided "as is" without express or implied 8 // warranty, and with no claim as to its suitability for any purpose. 9 // 10 //---------------------------------------------------------------------------- 11 // Contact: mcseem@antigrain.com 12 // mcseemagg@yahoo.com 13 // http://www.antigrain.com 14 //---------------------------------------------------------------------------- 15 16 #ifndef AGG_WARP_MAGNIFIER_INCLUDED 17 #define AGG_WARP_MAGNIFIER_INCLUDED 18 19 #include <math.h> 20 #include "agg_basics.h" 21 22 23 namespace agg 24 { 25 26 class trans_warp_magnifier 27 { 28 public: trans_warp_magnifier()29 trans_warp_magnifier() : m_xc(0.0), m_yc(0.0), m_magn(1.0), m_radius(1.0), m_warp(false) {} 30 center(double x,double y)31 void center(double x, double y) { m_xc = x; m_yc = y; } magnification(double m)32 void magnification(double m) { m_magn = m; } radius(double r)33 void radius(double r) { m_radius = r; } warp(bool w)34 void warp(bool w) { m_warp = w; } 35 transform(double * x,double * y)36 void transform(double* x, double* y) const 37 { 38 double dx = *x - m_xc; 39 double dy = *y - m_yc; 40 double r = sqrt(dx * dx + dy * dy); 41 double rm = m_radius / m_magn; 42 if(r < rm) 43 { 44 *x = m_xc + dx * m_magn; 45 *y = m_yc + dy * m_magn; 46 return; 47 } 48 49 if(m_warp) 50 { 51 double m = (r + rm * (m_magn - 1.0)) / r; 52 *x = m_xc + dx * m; 53 *y = m_yc + dy * m; 54 return; 55 } 56 57 if(r < m_radius) 58 { 59 double m = m_radius / r; 60 *x = m_xc + dx * m; 61 *y = m_yc + dy * m; 62 } 63 } 64 65 private: 66 double m_xc; 67 double m_yc; 68 double m_magn; 69 double m_radius; 70 bool m_warp; 71 }; 72 73 74 75 } 76 77 78 #endif 79 80