144{
145 double increment, halfAngle, maxErr;
146 if ( max_deviation <= 0 )
147 {
148 lwerror(
"lwarc_linearize: max deviation must be bigger than 0, got %.15g", max_deviation);
149 return -1;
150 }
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 maxErr = max_deviation;
177 if ( maxErr > radius * 2 )
178 {
179 maxErr = radius * 2;
181 "lwarc_linearize: tolerance %g is too big, "
182 "using arc-max 2 * radius == %g",
183 max_deviation,
184 maxErr);
185 }
186 do {
187 halfAngle = acos( 1.0 - maxErr / radius );
188
189
190 if ( halfAngle != 0 ) break;
191 LWDEBUGF(2,
"lwarc_linearize: tolerance %g is too small for this arc"
192 " to compute approximation angle, doubling it", maxErr);
193 maxErr *= 2;
194 } while(1);
195 increment = 2 * halfAngle;
197 "lwarc_linearize: maxDiff:%g, radius:%g, halfAngle:%g, increment:%g (%g degrees)",
198 max_deviation,
199 radius,
200 halfAngle,
201 increment,
202 increment * 180 / M_PI);
203
204 return increment;
205}
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.