1//----------------------------------------------------------------------------
2// Anti-Grain Geometry - Version 2.4
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#include <math.h>
17#include "agg_trans_warp_magnifier.h"
18
19namespace agg
20{
21
22    //------------------------------------------------------------------------
23    void trans_warp_magnifier::transform(double* x, double* y) const
24    {
25        double dx = *x - m_xc;
26        double dy = *y - m_yc;
27        double r = sqrt(dx * dx + dy * dy);
28        if(r < m_radius)
29        {
30            *x = m_xc + dx * m_magn;
31            *y = m_yc + dy * m_magn;
32            return;
33        }
34
35        double m = (r + m_radius * (m_magn - 1.0)) / r;
36        *x = m_xc + dx * m;
37        *y = m_yc + dy * m;
38    }
39
40    //------------------------------------------------------------------------
41    void trans_warp_magnifier::inverse_transform(double* x, double* y) const
42    {
43        trans_warp_magnifier t(*this);
44        t.magnification(1.0 / m_magn);
45        t.radius(m_radius * m_magn);
46        t.transform(x, y);
47    }
48
49
50}
51