Skip to content

Commit 1391d21

Browse files
committed
Initial.
1 parent 613901d commit 1391d21

25 files changed

+1408
-9715
lines changed

Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ OBJS = sscan.o sparse.o sbuffer.o vector3d.o point.o \
44
path.o box.o output.o gq_cache.o gist.o key.o \
55
crossmatch.o
66

7-
DATA_built = pg_sphere.sql
7+
EXTENSION = pg_sphere
8+
DATA_built = pg_sphere--1.0.sql
89
DOCS = README.pg_sphere COPYRIGHT.pg_sphere
910
REGRESS = init tables points euler circle line ellipse poly path box index
10-
EXTRA_CLEAN = pg_sphere.sql pg_sphere.sql.in $(PGS_SQL)
11+
EXTRA_CLEAN = pg_sphere--1.0.sql $(PGS_SQL)
1112

1213
CRUSH_TESTS = init_extended circle_extended
1314

@@ -30,15 +31,11 @@ else
3031
include $(top_srcdir)/contrib/contrib-global.mk
3132
endif
3233

33-
PGVERSION += $(shell $(PG_CONFIG) --version | sed 's,^PostgreSQL[[:space:]][[:space:]]*,,' | awk '{ split($$1,a,"."); printf( "v%02d%02d%02d" ,a[1], a[2], a[3]); }' )
34-
3534
crushtest: REGRESS += $(CRUSH_TESTS)
3635
crushtest: installcheck
3736

38-
pg_sphere.sql.in : $(addsuffix .in, $(PGS_SQL))
39-
echo 'BEGIN;' > $@
40-
for i in $+ ; do $(AWK) -v pg_version=$(PGVERSION) -f sql.awk < $$i >> $@ ; done
41-
echo 'COMMIT;' >> $@
37+
pg_sphere--1.0.sql: $(addsuffix .in, $(PGS_SQL))
38+
cat $^ > $@
4239

4340
sscan.o : sparse.c
4441

ellipse.c

Lines changed: 42 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ PG_FUNCTION_INFO_V1(spheretrans_ellipse);
5050
PG_FUNCTION_INFO_V1(spheretrans_ellipse_inv);
5151

5252

53-
/*
54-
* ! This function returns the arc cos of a value. If variable a is outside
55-
* the range between -1.00 and 1.00, the function returns corresponding PI/2
56-
* or 3*PI/2. \param a the arccos argument \return arccos of a value
57-
*/
53+
/*
54+
* This function returns the arccos of a value. If variable a is outside
55+
* the range between -1.00 and 1.00, the function returns corresponding PI/2
56+
* or 3*PI/2.
57+
*/
5858
static float8
5959
my_acos(float8 a)
6060
{
@@ -65,10 +65,9 @@ my_acos(float8 a)
6565
return acos(a);
6666
}
6767

68-
/*
69-
* ! \brief Checks the parameter of an ellipse \param e pointer to ellipse
70-
* \return pointer of (modified) ellipse
71-
*/
68+
/*
69+
* Checks the parameter of an ellipse.
70+
*/
7271
static SELLIPSE *
7372
sellipse_check(SELLIPSE *e)
7473
{
@@ -95,11 +94,9 @@ sellipse_check(SELLIPSE *e)
9594
return e;
9695
}
9796

98-
99-
/*
100-
* ! \brief Returns the boundary circle of an ellipse \param e pointer to
101-
* ellipse \param sc pointer to circle \return pointer to result circle
102-
*/
97+
/*
98+
* Returns the boundary circle of an ellipse.
99+
*/
103100
static SCIRCLE *
104101
sellipse_circle(SCIRCLE *sc, const SELLIPSE *e)
105102
{
@@ -111,14 +108,10 @@ sellipse_circle(SCIRCLE *sc, const SELLIPSE *e)
111108
return sc;
112109
}
113110

114-
115-
/*
116-
* ! \brief Returns the an ellipse from axes, center and inclination \param
117-
* r1 first axis length in radians \param r2 second axis length in radians
118-
* \param c pointer to center of ellipse \param inc inclination of ellipse
119-
* in radians \note The largest axis length is choosen for large axis \return
120-
* pointer to ellipse
121-
*/
111+
/*
112+
* Returns the an ellipse from axes, center and inclination. The largest axis
113+
* length is chosen for large axis.
114+
*/
122115
static SELLIPSE *
123116
sellipse_in(float8 r1, float8 r2, const SPoint *c, float8 inc)
124117
{
@@ -142,11 +135,13 @@ sellipse_in(float8 r1, float8 r2, const SPoint *c, float8 inc)
142135
return (e);
143136
}
144137

145-
/*
146-
* ! \brief Returns the radius of an ellipse depending on position angle
147-
* \param rada major axis length \param radb minor axis length \param ang
148-
* position angle in radians \return radius of ellipse in radians
149-
*/
138+
/*---
139+
* Returns the radius of an ellipse depending on position angle.
140+
*
141+
* rada - major axis length
142+
* radb - minor axis length
143+
* ang - position angle in radians
144+
*/
150145
static float8
151146
sellipse_dist(float8 rada, float8 radb, float8 ang)
152147
{
@@ -156,22 +151,15 @@ sellipse_dist(float8 rada, float8 radb, float8 ang)
156151
return (asin(sin(radb) / sqrt(1 - e * Sqr(cos(ang)))));
157152
}
158153

159-
160-
161-
162-
/*
163-
* ! \brief Returns distance between ellipse and point \param se pointer to
164-
* ellipse \param sp pointer to point \return distance in radians \note
165-
* returns -1.0 if ellipse contains point
166-
*/
154+
/*
155+
* Returns distance between ellipse and point.
156+
*/
167157
static float8
168158
sellipse_point_dist(const SELLIPSE *se, const SPoint *sp)
169159
{
170160
static SEuler e;
171161
static SPoint p;
172-
static float8 dist,
173-
rad,
174-
ang;
162+
static float8 dist, rad, ang;
175163

176164
sellipse_trans(&e, se);
177165
spheretrans_inv(&e);
@@ -208,11 +196,9 @@ sellipse_point_dist(const SELLIPSE *se, const SPoint *sp)
208196
return -1.0;
209197
}
210198

211-
/*
212-
* ! \brief Does an Euler transformation of ellipse \param out pointer to
213-
* transformed ellipse \param in pointer to input ellipse \param se pointer
214-
* to Euler transformation \return pointer to transformed ellipse
215-
*/
199+
/*
200+
* Does an Euler transformation of ellipse.
201+
*/
216202
static SELLIPSE *
217203
euler_sellipse_trans(SELLIPSE *out, const SELLIPSE *in, const SEuler *se)
218204
{
@@ -245,12 +231,10 @@ euler_sellipse_trans(SELLIPSE *out, const SELLIPSE *in, const SEuler *se)
245231
}
246232

247233

248-
/*
249-
* ! \brief Returns the relationship between two ellipses \param se1 pointer
250-
* to first ellipse \param se2 pointer to second ellipse \return
251-
* relationship as a \link PGS_ELLIPSE_ELLIPSE_REL int8 value \endlink (\ref
252-
* PGS_ELLIPSE_ELLIPSE_REL )
253-
*/
234+
/*
235+
* Returns the relationship between two ellipses as PGS_ELLIPSE_ELLIPSE_REL
236+
* int8 value.
237+
*/
254238
static int8
255239
sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
256240
{
@@ -288,7 +272,6 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
288272
}
289273

290274
/* se1 is circle or point */
291-
292275
if (FPeq(se1->rad[0], se1->rad[1]))
293276
{
294277

@@ -313,7 +296,6 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
313296
}
314297

315298
/* se2 is line */
316-
317299
if (FPzero(se2->rad[1]))
318300
{
319301
static SLine l;
@@ -335,7 +317,6 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
335317
}
336318

337319
/* se1 is line */
338-
339320
if (FPzero(se1->rad[1]))
340321
{
341322
static SLine l;
@@ -357,12 +338,10 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
357338
}
358339

359340
/* now we have two real ellipses */
360-
361341
do
362342
{
363343

364-
static SPoint p1,
365-
p2;
344+
static SPoint p1, p2;
366345
static float8 dist;
367346

368347
/* check inner and outer circles */
@@ -380,20 +359,18 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
380359
else if (FPle((dist + se2->rad[0]), se1->rad[1]))
381360
{
382361
return PGS_ELLIPSE_CONT;
383-
384362
}
385363
else
386364
{
387365

388-
static SEuler eul;
389-
static SELLIPSE etmp,
390-
e;
391-
static SPoint sp[3];
392-
static int i;
393-
static float8 diff[3];
394-
static float8 elng;
395-
static const int maxcntr = 100000;
396-
static int cntr;
366+
static SEuler eul;
367+
static SELLIPSE etmp, e;
368+
static SPoint sp[3];
369+
static int i;
370+
static float8 diff[3];
371+
static float8 elng;
372+
static const int maxcntr = 100000;
373+
static int cntr;
397374

398375
/* transform se1 to north pol */
399376
sellipse_trans(&eul, se1);
@@ -416,7 +393,6 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
416393

417394

418395
/* search for minimum distance */
419-
420396
sp[0].lat = sp[2].lat = PIH - se1->rad[0];
421397
sellipse_center(&sp[1], &e);
422398

@@ -445,7 +421,6 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
445421
cntr = 0;
446422
do
447423
{
448-
449424
for (i = 0; i < 3; i++)
450425
{
451426
diff[i] = sellipse_point_dist(&e, &sp[i]);
@@ -521,7 +496,6 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2)
521496
{
522497
return PGS_ELLIPSE_AVOID;
523498
}
524-
525499
}
526500
} while (0);
527501

@@ -741,7 +715,6 @@ sellipse_line_pos(const SELLIPSE *se, const SLine *sl)
741715
}
742716

743717
/* begin or end of line inside ellipse */
744-
745718
{
746719
bool bb,
747720
be;

0 commit comments

Comments
 (0)