-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsbuffer.c
332 lines (268 loc) · 7.03 KB
/
sbuffer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#include "pg_sphere.h"
#include "sbuffer.h"
/*!
\file
\brief functions to buffer the parser input
*/
#define MAX_BUF_ANGLE 20 //!< maximum count of buffered angles
unsigned char spheretype; //!< the type of parsed spherical object
float8 bufangle[MAX_BUF_ANGLE]; //!< the angle buffer
/*!
\brief a simple spherical point
*/
typedef struct {
double lng; //!< longitude
double lat; //!< latitude
} bpoint;
//! spherical point buffer
struct {
int m; //! count of buffered points
bpoint *p; //! pointer to array of points
} bufpoints;
//! ID of line's length angle
int bufline ;
/*!
First element is the ID of spherical point ( center ).
Second element is the ID of radius angle.
\brief Buffer of circle
*/
int bufcircle[2];
/*!
\brief Buffer of ellipse
*/
int bufellipse[5];
/*!
\brief Buffer of ID's of Euler transformation values
*/
int bufeuler[3];
//! Structure to buffer the axes of Euler transformation
struct {
unsigned char phi , //! first axis
theta, //! second axis
psi ; //! third axis
} bufeulertype ;
//! Current angle ID
int bufapos ;
//! Current point ID
int bufspos ;
//! Pointer to input buffer
char * parse_buffer;
void set_spheretype ( unsigned char st )
{
spheretype = st;
}
void init_buffer ( char * buffer )
{
spheretype = STYPE_UNKNOWN;
parse_buffer = buffer ;
bufapos = 0;
bufspos = 0;
bufeulertype.phi = bufeulertype.psi = EULER_AXIS_Z;
bufeulertype.theta = EULER_AXIS_X;
bufpoints.m = 2;
bufpoints.p = ( bpoint * ) MALLOC ( bufpoints.m * sizeof ( bpoint ) );
}
void reset_buffer( void )
{
sphere_flush_scanner_buffer();
FREE ( bufpoints.p );
bufpoints.p = NULL;
bufpoints.m = 0;
init_buffer( NULL );
}
int set_angle_sign ( int apos , int s )
{
if ( bufangle[apos] > 0 && s<0 ){
bufangle[apos] *= -1;
}
if ( bufangle[apos] < 0 && s>0 ){
bufangle[apos] *= -1;
}
return apos;
}
int set_angle ( unsigned char is_deg , float8 a )
{
if ( is_deg ){
a /= RADIANS ;
}
bufangle[bufapos] = a;
bufapos++;
return ( bufapos - 1 );
}
int set_point ( int lngpos , int latpos )
{
if ( bufspos >= bufpoints.m ){
bpoint * p = bufpoints.p;
int i = ( bufpoints.m * 2 ) ;
bufpoints.p = ( bpoint * ) MALLOC ( i * sizeof (bpoint) );
memcpy ( (void*) bufpoints.p, (void*) p, bufpoints.m * sizeof (bpoint) );
bufpoints.m = i;
FREE( p );
}
bufpoints.p[bufspos].lng = bufangle[lngpos];
bufpoints.p[bufspos].lat = bufangle[latpos];
bufspos++;
lngpos = 0;
latpos = 0;
if ( ( bufapos + 3 ) > MAX_BUF_ANGLE ){
bufapos = 0;
}
return ( bufspos - 1 );
}
void set_circle ( int spos , int rpos )
{
bufcircle[0] = spos;
bufcircle[1] = rpos;
}
void set_ellipse ( int r1, int r2, int sp , int inc )
{
bufellipse[0] = r1;
bufellipse[1] = r2;
bufellipse[2] = sp;
bufellipse[3] = inc;
}
void set_line ( int length )
{
bufline = length;
}
void set_euler ( int phi, int theta , int psi , char * etype )
{
int i ;
unsigned char t = 0 ;
bufeuler[0] = phi;
bufeuler[1] = theta;
bufeuler[2] = psi;
for ( i=0; i<3; i++ ){
switch ( etype[i] ){
case 'x':
case 'X': t = EULER_AXIS_X; break;
case 'y':
case 'Y': t = EULER_AXIS_Y; break;
case 'z':
case 'Z': t = EULER_AXIS_Z; break;
}
switch ( i ){
case 0: bufeulertype.phi = t; break;
case 1: bufeulertype.theta = t; break;
case 2: bufeulertype.psi = t; break;
}
}
}
int get_point ( double * lng , double * lat )
{
if ( spheretype == STYPE_POINT )
{
*lng = bufpoints.p[0].lng ;
*lat = bufpoints.p[0].lat ;
return 1;
} else {
return 0;
}
}
int get_line ( double * phi , double * theta ,
double * psi , unsigned char * etype, double * length )
{
int i;
if ( spheretype != STYPE_LINE ){
return 0;
}
*phi = bufangle[bufeuler[0]] ;
*theta = bufangle[bufeuler[1]] ;
*psi = bufangle[bufeuler[2]] ;
for ( i=0; i<3; i++ ){
switch ( i ){
case 0: etype[i] = bufeulertype.phi ; break;
case 1: etype[i] = bufeulertype.theta; break;
case 2: etype[i] = bufeulertype.psi ; break;
}
}
*length = bufangle[bufline];
return 1;
}
int get_euler ( double * phi , double * theta ,
double * psi , unsigned char * etype )
{
int i;
if ( spheretype != STYPE_EULER ){
return 0;
}
*phi = bufangle[bufeuler[0]] ;
*theta = bufangle[bufeuler[1]] ;
*psi = bufangle[bufeuler[2]] ;
for ( i=0; i<3; i++ ){
switch ( i ){
case 0: etype[i] = bufeulertype.phi ; break;
case 1: etype[i] = bufeulertype.theta; break;
case 2: etype[i] = bufeulertype.psi ; break;
}
}
return 1;
}
int get_circle ( double * lng , double * lat , double * radius )
{
if ( spheretype == STYPE_CIRCLE )
{
*lng = bufpoints.p[bufcircle[0]].lng ;
*lat = bufpoints.p[bufcircle[0]].lat ;
*radius = bufangle[bufcircle[1]] ;
return 1;
} else {
return 0;
}
}
int get_ellipse ( double * lng , double * lat ,
double * r1, double * r2, double * inc )
{
if ( spheretype == STYPE_ELLIPSE )
{
*lng = bufpoints.p[bufellipse[2]].lng ;
*lat = bufpoints.p[bufellipse[2]].lat ;
*r1 = bufangle[bufellipse[0]] ;
*r2 = bufangle[bufellipse[1]] ;
*inc = bufangle[bufellipse[3]] ;
return 1;
} else {
return 0;
}
}
int get_path_count ( void )
{
return ( bufspos );
}
int get_path_elem ( int spos, double * lng , double * lat )
{
if ( spheretype == STYPE_PATH )
{
*lng = bufpoints.p[spos].lng ;
*lat = bufpoints.p[spos].lat ;
return 1;
} else {
return 0;
}
}
int get_box ( double * lng1 , double * lat1, double * lng2 , double * lat2 )
{
if ( spheretype == STYPE_BOX )
{
*lng1 = bufpoints.p[0].lng ;
*lat1 = bufpoints.p[0].lat ;
*lng2 = bufpoints.p[1].lng ;
*lat2 = bufpoints.p[1].lat ;
return 1;
}
return 0;
}
int get_buffer( char * buf , int offset )
{
int slen = 0 ;
slen = strlen( parse_buffer );
if ( ! parse_buffer || ! ( slen > 0 ) ){
return 0 ;
}
if ( slen >= offset ){
slen = offset;
}
memcpy ( ( void * ) buf, ( void * ) parse_buffer , slen );
parse_buffer += slen;
return slen;
}