~kalon33/corsix-th/master

« back to all changes in this revision

Viewing changes to agg/src/agg_bspline.cpp

  • Committer: corsixth.bot at gmail
  • Date: 2014-03-31 23:30:23 UTC
  • Revision ID: svn-v4:c39591fa-788f-11de-a72b-d90af8dea425:trunk:2687
Remove trailing whitespaces in .h, .cpp, .c and .lua files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Anti-Grain Geometry - Version 2.4
3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
4
//
5
 
// Permission to copy, use, modify, sell and distribute this software 
6
 
// is granted provided this copyright notice appears in all copies. 
 
5
// Permission to copy, use, modify, sell and distribute this software
 
6
// is granted provided this copyright notice appears in all copies.
7
7
// This software is provided "as is" without express or implied
8
8
// warranty, and with no claim as to its suitability for any purpose.
9
9
//
53
53
        init(num, x, y);
54
54
    }
55
55
 
56
 
    
 
56
 
57
57
    //------------------------------------------------------------------------
58
58
    void bspline::init(int max)
59
59
    {
87
87
        if(m_num > 2)
88
88
        {
89
89
            int i, k, n1;
90
 
            double* temp; 
91
 
            double* r; 
 
90
            double* temp;
 
91
            double* r;
92
92
            double* s;
93
93
            double h, p, d, f, e;
94
 
    
95
 
            for(k = 0; k < m_num; k++) 
 
94
 
 
95
            for(k = 0; k < m_num; k++)
96
96
            {
97
97
                m_am[k] = 0.0;
98
98
            }
102
102
            pod_array<double> al(n1);
103
103
            temp = &al[0];
104
104
 
105
 
            for(k = 0; k < n1; k++) 
 
105
            for(k = 0; k < n1; k++)
106
106
            {
107
107
                temp[k] = 0.0;
108
108
            }
114
114
            d = m_x[1] - m_x[0];
115
115
            e = (m_y[1] - m_y[0]) / d;
116
116
 
117
 
            for(k = 1; k < n1; k++) 
 
117
            for(k = 1; k < n1; k++)
118
118
            {
119
119
                h     = d;
120
120
                d     = m_x[k + 1] - m_x[k];
125
125
                s[k]  = 6.0 * (e - f) / (h + d);
126
126
            }
127
127
 
128
 
            for(k = 1; k < n1; k++) 
 
128
            for(k = 1; k < n1; k++)
129
129
            {
130
130
                p = 1.0 / (r[k] * al[k - 1] + 2.0);
131
131
                al[k] *= -p;
132
 
                s[k] = (s[k] - r[k] * s[k - 1]) * p; 
 
132
                s[k] = (s[k] - r[k] * s[k - 1]) * p;
133
133
            }
134
134
 
135
135
            m_am[n1]     = 0.0;
136
136
            al[n1 - 1]   = s[n1 - 1];
137
137
            m_am[n1 - 1] = al[n1 - 1];
138
138
 
139
 
            for(k = n1 - 2, i = 0; i < m_num - 2; i++, k--) 
 
139
            for(k = n1 - 2, i = 0; i < m_num - 2; i++, k--)
140
140
            {
141
141
                al[k]   = al[k] * al[k + 1] + s[k];
142
142
                m_am[k] = al[k];
165
165
 
166
166
 
167
167
    //------------------------------------------------------------------------
168
 
    void bspline::bsearch(int n, const double *x, double x0, int *i) 
 
168
    void bspline::bsearch(int n, const double *x, double x0, int *i)
169
169
    {
170
170
        int j = n - 1;
171
171
        int k;
172
 
          
173
 
        for(*i = 0; (j - *i) > 1; ) 
 
172
 
 
173
        for(*i = 0; (j - *i) > 1; )
174
174
        {
175
 
            if(x0 < x[k = (*i + j) >> 1]) j = k; 
 
175
            if(x0 < x[k = (*i + j) >> 1]) j = k;
176
176
            else                         *i = k;
177
177
        }
178
178
    }
196
196
    double bspline::extrapolation_left(double x) const
197
197
    {
198
198
        double d = m_x[1] - m_x[0];
199
 
        return (-d * m_am[1] / 6 + (m_y[1] - m_y[0]) / d) * 
200
 
               (x - m_x[0]) + 
 
199
        return (-d * m_am[1] / 6 + (m_y[1] - m_y[0]) / d) *
 
200
               (x - m_x[0]) +
201
201
               m_y[0];
202
202
    }
203
203
 
205
205
    double bspline::extrapolation_right(double x) const
206
206
    {
207
207
        double d = m_x[m_num - 1] - m_x[m_num - 2];
208
 
        return (d * m_am[m_num - 2] / 6 + (m_y[m_num - 1] - m_y[m_num - 2]) / d) * 
209
 
               (x - m_x[m_num - 1]) + 
 
208
        return (d * m_am[m_num - 2] / 6 + (m_y[m_num - 1] - m_y[m_num - 2]) / d) *
 
209
               (x - m_x[m_num - 1]) +
210
210
               m_y[m_num - 1];
211
211
    }
212
212
 
248
248
                if(x < m_x[m_last_idx] || x > m_x[m_last_idx + 1])
249
249
                {
250
250
                    // Check if x between next points (most probably)
251
 
                    if(m_last_idx < m_num - 2 && 
 
251
                    if(m_last_idx < m_num - 2 &&
252
252
                       x >= m_x[m_last_idx + 1] &&
253
253
                       x <= m_x[m_last_idx + 2])
254
254
                    {
255
255
                        ++m_last_idx;
256
256
                    }
257
257
                    else
258
 
                    if(m_last_idx > 0 && 
259
 
                       x >= m_x[m_last_idx - 1] && 
 
258
                    if(m_last_idx > 0 &&
 
259
                       x >= m_x[m_last_idx - 1] &&
260
260
                       x <= m_x[m_last_idx])
261
261
                    {
262
262
                        // x is between pevious points