Skip to content

Commit 613901d

Browse files
committed
Remove some macroses. Compatibility only with PostgreSQL 9.1+ is preserved.
1 parent 60e904c commit 613901d

22 files changed

+714
-1162
lines changed

box.c

Lines changed: 72 additions & 129 deletions
Large diffs are not rendered by default.

box.h

Lines changed: 124 additions & 238 deletions
Large diffs are not rendered by default.

circle.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#include "circle.h"
22

3-
/*!
4-
\file
5-
\brief Circle functions
6-
*/
7-
8-
9-
#ifndef DOXYGEN_SHOULD_SKIP_THIS
3+
/*
4+
* Circle functions
5+
*/
106

117
PG_FUNCTION_INFO_V1(spherecircle_in);
128
PG_FUNCTION_INFO_V1(spherecircle_equal);
@@ -33,16 +29,12 @@ PG_FUNCTION_INFO_V1(spherecircle_circ);
3329
PG_FUNCTION_INFO_V1(spheretrans_circle);
3430
PG_FUNCTION_INFO_V1(spheretrans_circle_inverse);
3531

36-
#endif
37-
3832

3933
bool
4034
scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2)
4135
{
42-
return (
43-
spoint_eq(&c1->center, &c2->center) &&
44-
FPeq(c1->radius, c2->radius)
45-
);
36+
return (spoint_eq(&c1->center, &c2->center)
37+
&& FPeq(c1->radius, c2->radius));
4638
}
4739

4840
bool
@@ -68,14 +60,12 @@ euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se)
6860
Datum
6961
spherecircle_in(PG_FUNCTION_ARGS)
7062
{
71-
SCIRCLE *c = (SCIRCLE *) MALLOC(sizeof(SCIRCLE));
63+
SCIRCLE *c = (SCIRCLE *) palloc(sizeof(SCIRCLE));
7264
char *s = PG_GETARG_CSTRING(0);
7365
double lng,
7466
lat,
7567
radius;
7668

77-
void sphere_yyparse(void);
78-
7969
init_buffer(s);
8070
sphere_yyparse();
8171
if (get_circle(&lng, &lat, &radius))
@@ -86,11 +76,11 @@ spherecircle_in(PG_FUNCTION_ARGS)
8676
reset_buffer();
8777

8878
/*
89-
* It's important to allow circles with radius 90deg!!
79+
* It's important to allow circles with radius 90 degrees!
9080
*/
9181
if (FPgt(c->radius, PIH))
9282
{
93-
FREE(c);
83+
pfree(c);
9484
c = NULL;
9585
elog(ERROR, "spherecircle_in: radius must be not greater than 90 degrees");
9686
}
@@ -104,7 +94,7 @@ spherecircle_in(PG_FUNCTION_ARGS)
10494
else
10595
{
10696
reset_buffer();
107-
FREE(c);
97+
pfree(c);
10898
c = NULL;
10999
elog(ERROR, "spherecircle_in: parse error");
110100
}
@@ -340,7 +330,7 @@ Datum
340330
spherecircle_center(PG_FUNCTION_ARGS)
341331
{
342332
SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0);
343-
SPoint *p = (SPoint *) MALLOC(sizeof(SPoint));
333+
SPoint *p = (SPoint *) palloc(sizeof(SPoint));
344334

345335
memcpy((void *) p, (void *) &c->center, sizeof(SPoint));
346336
PG_RETURN_POINTER(p);
@@ -358,7 +348,7 @@ Datum
358348
spherepoint_to_circle(PG_FUNCTION_ARGS)
359349
{
360350
SPoint *p = (SPoint *) PG_GETARG_POINTER(0);
361-
SCIRCLE *c = (SCIRCLE *) MALLOC(sizeof(SCIRCLE));
351+
SCIRCLE *c = (SCIRCLE *) palloc(sizeof(SCIRCLE));
362352

363353
memcpy((void *) &c->center, (void *) p, sizeof(SPoint));
364354
c->radius = 0;
@@ -377,7 +367,7 @@ spherecircle_by_center(PG_FUNCTION_ARGS)
377367
elog(ERROR, "radius must be not greater than 90 degrees or less than 0");
378368
PG_RETURN_NULL();
379369
}
380-
c = (SCIRCLE *) MALLOC(sizeof(SCIRCLE));
370+
c = (SCIRCLE *) palloc(sizeof(SCIRCLE));
381371
memcpy((void *) &c->center, (void *) p, sizeof(SPoint));
382372
c->radius = rad;
383373
PG_RETURN_POINTER(c);
@@ -404,7 +394,7 @@ spheretrans_circle(PG_FUNCTION_ARGS)
404394
{
405395
SCIRCLE *sc = (SCIRCLE *) PG_GETARG_POINTER(0);
406396
SEuler *se = (SEuler *) PG_GETARG_POINTER(1);
407-
SCIRCLE *out = (SCIRCLE *) MALLOC(sizeof(SCIRCLE));
397+
SCIRCLE *out = (SCIRCLE *) palloc(sizeof(SCIRCLE));
408398

409399
PG_RETURN_POINTER(euler_scircle_trans(out, sc, se));
410400
}
@@ -418,8 +408,7 @@ spheretrans_circle_inverse(PG_FUNCTION_ARGS)
418408
Datum ret;
419409

420410
spheretrans_inverse(&tmp, se);
421-
ret = DirectFunctionCall2(
422-
spheretrans_circle,
411+
ret = DirectFunctionCall2(spheretrans_circle,
423412
sc, PointerGetDatum(&tmp));
424413
PG_RETURN_DATUM(ret);
425414
}

circle.h

Lines changed: 34 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,190 +4,154 @@
44
#include "euler.h"
55

66
/*
7-
* ! \file \brief Spherical circle declarations
7+
* Spherical circle declarations
88
*/
99

1010
/*
11-
* ! \brief Spherical circle.
11+
* Spherical circle data structure: center and radius.
1212
*/
1313
typedef struct
1414
{
15-
SPoint center;
16-
/* !<the center of circle */
17-
float8 radius;
18-
/* !<the circle radius in radians */
15+
SPoint center; /* the center of circle */
16+
float8 radius; /* the circle radius in radians */
1917
} SCIRCLE;
2018

2119
/*
22-
* ! \brief Checks whether two circles are equal. \param c1 pointer to first
23-
* circle \param c2 pointer to second circle \return true, if equal
20+
* Checks whether two circles are equal.
2421
*/
2522
bool scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2);
2623

2724
/*
28-
* ! \brief checks whether circle contains point \param p pointer to point
29-
* \param c pointer to circle \return true, if circle contains point
25+
* Checks whether circle contains point.
3026
*/
3127
bool spoint_in_circle(const SPoint *p, const SCIRCLE *c);
3228

3329
/*
34-
* ! \brief transforms a circle using Euler transformation \param out pointer
35-
* to transformed circle \param in pointer to circle \param se pointer to
36-
* Euler transformation \return pointer to transformed circle
30+
* Transforms a circle using Euler transformation.
3731
*/
3832
SCIRCLE *euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se);
3933

4034
/*
41-
* ! Takes the input and stores it as spherical circle. \brief a circle input
42-
* function \return a spherical circle datum \note PostgreSQL function
35+
* Takes the input and stores it as spherical circle.
4336
*/
4437
Datum spherecircle_in(PG_FUNCTION_ARGS);
4538

4639
/*
47-
* ! Checks whether two circles are equal. \brief equality of two circles
48-
* \return boolean datum \note PostgreSQL function
40+
* Checks whether two circles are equal.
4941
*/
5042
Datum spherecircle_equal(PG_FUNCTION_ARGS);
5143

5244
/*
53-
* ! Checks whether two circles are not equal. \brief Checks whether two
54-
* circles are not equal \return boolean datum \note PostgreSQL function
45+
* Checks whether two circles are not equal.
5546
*/
5647
Datum spherecircle_equal_neg(PG_FUNCTION_ARGS);
5748

5849
/*
59-
* ! Calculate the distance of two circles. If overlapping, this function
60-
* returns 0.0. \brief distance of two circles \return float8 datum \note
61-
* PostgreSQL function
50+
* Calculate the distance of two circles. If overlapping, this function
51+
* returns 0.0.
6252
*/
6353
Datum spherecircle_distance(PG_FUNCTION_ARGS);
6454

6555
/*
66-
* ! Calculate the distance of circle and point. If circle contains point,
67-
* this function returns 0.0. \brief distance of circle and point \return
68-
* float8 datum \note PostgreSQL function \see
69-
* spherecircle_point_distance_com(PG_FUNCTION_ARGS)
56+
* Calculate the distance of circle and point. If circle contains point,
57+
* this function returns 0.0.
7058
*/
7159
Datum spherecircle_point_distance(PG_FUNCTION_ARGS);
7260

7361
/*
74-
* ! Calculate the distance of point and circle. If circle contains point,
75-
* this function returns 0.0. \brief distance of point and circle \return
76-
* float8 datum \note PostgreSQL function \see
77-
* spherecircle_point_distance(PG_FUNCTION_ARGS)
62+
* Calculate the distance of point and circle. If circle contains point,
63+
* this function returns 0.0.
7864
*/
7965
Datum spherecircle_point_distance_com(PG_FUNCTION_ARGS);
8066

8167
/*
82-
* ! \brief Checks whether circle contains point \return boolean datum \note
83-
* PostgreSQL function
68+
* Checks whether circle contains point.
8469
*/
8570
Datum spherepoint_in_circle(PG_FUNCTION_ARGS);
8671

8772
/*
88-
* ! \brief Checks whether circle doesn't contain point \return boolean datum
89-
* \note PostgreSQL function
73+
* Checks whether circle doesn't contain point.
9074
*/
9175
Datum spherepoint_in_circle_neg(PG_FUNCTION_ARGS);
9276

9377
/*
94-
* ! \brief Checks whether circle contains point \return boolean datum \note
95-
* PostgreSQL function
78+
* Checks whether circle contains point.
9679
*/
9780
Datum spherepoint_in_circle_com(PG_FUNCTION_ARGS);
9881

9982
/*
100-
* ! \brief Checks whether circle doesn't contain point \return boolean datum
101-
* \note PostgreSQL function
83+
* Checks whether circle doesn't contain point.
10284
*/
10385
Datum spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS);
10486

10587
/*
106-
* ! \brief Checks whether circle is contained by other circle \return
107-
* boolean datum \note PostgreSQL function
88+
* Checks whether circle is contained by other circle.
10889
*/
10990
Datum spherecircle_in_circle(PG_FUNCTION_ARGS);
11091

11192
/*
112-
* ! \brief Checks whether circle is not contained by other circle \return
113-
* boolean datum \note PostgreSQL function
93+
* Checks whether circle is not contained by other circle.
11494
*/
11595
Datum spherecircle_in_circle_neg(PG_FUNCTION_ARGS);
11696

11797
/*
118-
* ! \brief Checks whether circle contains other circle \return boolean datum
119-
* \note PostgreSQL function
98+
* Checks whether circle contains other circle.
12099
*/
121100
Datum spherecircle_in_circle_com(PG_FUNCTION_ARGS);
122101

123102
/*
124-
* ! \brief Checks whether circle does not contain other circle \return
125-
* boolean datum \note PostgreSQL function
103+
* Checks whether circle does not contain other circle.
126104
*/
127105
Datum spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS);
128106

129107
/*
130-
* ! \brief Checks whether two circle overlap \return boolean datum \note
131-
* PostgreSQL function
108+
* Checks whether two circle overlap.
132109
*/
133110
Datum spherecircle_overlap(PG_FUNCTION_ARGS);
134111

135112
/*
136-
* ! \brief Checks whether two circle overlap \return boolean datum \note
137-
* PostgreSQL function
113+
* Checks whether two circle overlap.
138114
*/
139115
Datum spherecircle_overlap_neg(PG_FUNCTION_ARGS);
140116

141117
/*
142-
* ! \brief returns the center of circle \return spherical point datum \note
143-
* PostgreSQL function
118+
* Returns the center of circle.
144119
*/
145120
Datum spherecircle_center(PG_FUNCTION_ARGS);
146121

147122
/*
148-
* ! \brief returns the radius of circle \return float8 datum \note
149-
* PostgreSQL function
123+
* Returns the radius of circle.
150124
*/
151125
Datum spherecircle_radius(PG_FUNCTION_ARGS);
152126

153127
/*
154-
* ! \brief converts a point to a circle \return spherical circle datum \note
155-
* PostgreSQL function
128+
* Converts a point to a circle.
156129
*/
157130
Datum spherepoint_to_circle(PG_FUNCTION_ARGS);
158131

159132
/*
160-
* ! \brief Creates a circle from center and radius \return spherical circle
161-
* datum \note PostgreSQL function
133+
* Creates a circle from center and radius.
162134
*/
163135
Datum spherecircle_by_center(PG_FUNCTION_ARGS);
164136

165137
/*
166-
* ! Calculates the area of a circle in square radians \brief calculate the
167-
* area of a circle \return float8 datum \note PostgreSQL function
138+
* Calculates the area of a circle in square radians.
168139
*/
169140
Datum spherecircle_area(PG_FUNCTION_ARGS);
170141

171142
/*
172-
* ! Calculates the circumference of a circle in radians. \brief calculate
173-
* the circumference of a circle \return float8 datum \note PostgreSQL
174-
* function
143+
* Calculates the circumference of a circle in radians.
175144
*/
176145
Datum spherecircle_circ(PG_FUNCTION_ARGS);
177146

178147
/*
179-
* ! Transforms a circle using Euler transformation \brief transforms a
180-
* circle \return spherical circle datum \note PostgreSQL function
148+
* Transforms a circle using Euler transformation.
181149
*/
182150
Datum spheretrans_circle(PG_FUNCTION_ARGS);
183151

184152
/*
185-
* ! Invers transformation of a circle using Euler transformation \brief
186-
* inverse transformation of a circle \return spherical circle datum \note
187-
* PostgreSQL function
153+
* Inverse transformation of a circle using Euler transformation.
188154
*/
189155
Datum spheretrans_circle_inverse(PG_FUNCTION_ARGS);
190156

191-
192-
193157
#endif

crossmatch.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ pointLineSweep(CrossmatchContext *ctx, PointInfo *points1, int count1,
326326
avg1 += points1[i1].v[coordIdx];
327327
avg1 /= count1;
328328
for (i1 = 0; i1 < count1; i1++)
329-
stddev += sqr(points1[i1].v[coordIdx] - avg1);
329+
stddev += Sqr(points1[i1].v[coordIdx] - avg1);
330330

331331
for (i2 = 0; i2 < count2; i2++)
332332
avg2 += points2[i2].v[coordIdx];
333333
avg2 /= count2;
334334
for (i2 = 0; i2 < count2; i2++)
335-
stddev += sqr(points2[i2].v[coordIdx] - avg2);
335+
stddev += Sqr(points2[i2].v[coordIdx] - avg2);
336336

337337
stddev = sqrt(stddev / (count1 + count2 - 2));
338338
factor = Abs(avg1 - avg2) / stddev;
@@ -374,9 +374,9 @@ pointLineSweep(CrossmatchContext *ctx, PointInfo *points1, int count1,
374374
{
375375

376376
/* Add result pair if two points is threshold close to each other */
377-
if (sqrt(sqr(points2[j].v[0] - points1[i1].v[0]) +
378-
sqr(points2[j].v[1] - points1[i1].v[1]) +
379-
sqr(points2[j].v[2] - points1[i1].v[2])) <= threshold)
377+
if (sqrt(Sqr(points2[j].v[0] - points1[i1].v[0]) +
378+
Sqr(points2[j].v[1] - points1[i1].v[1]) +
379+
Sqr(points2[j].v[2] - points1[i1].v[2])) <= threshold)
380380
{
381381
addResultPair(ctx, &points1[i1].iptr, &points2[j].iptr);
382382
}
@@ -477,7 +477,7 @@ box3DLineSweep(CrossmatchContext *ctx, Box3DInfo *boxes1, int count1,
477477
{
478478
avg1 += (float8) boxes1[i1].v[coordIdx];
479479
avg1 += (float8) boxes1[i1].v[coordIdx + 3];
480-
avgsize += sqr((float8) (boxes1[i1].v[coordIdx + 3]
480+
avgsize += Sqr((float8) (boxes1[i1].v[coordIdx + 3]
481481
- boxes1[i1].v[coordIdx] + 1));
482482
}
483483
avg1 /= 2 * count1;
@@ -486,7 +486,7 @@ box3DLineSweep(CrossmatchContext *ctx, Box3DInfo *boxes1, int count1,
486486
{
487487
avg2 += (float8) boxes2[i2].v[coordIdx];
488488
avg2 += (float8) boxes2[i2].v[coordIdx + 3];
489-
avgsize += sqr((float8) (boxes2[i2].v[coordIdx + 3]
489+
avgsize += Sqr((float8) (boxes2[i2].v[coordIdx + 3]
490490
- boxes2[i2].v[coordIdx] + 1));
491491
}
492492
avg2 /= 2 * count2;

0 commit comments

Comments
 (0)