From 2c245e7f295091010a2c4ae47f968422c668f0eb Mon Sep 17 00:00:00 2001 From: Vitaly Davydov Date: Thu, 28 Sep 2023 15:36:16 +0300 Subject: [PATCH] Format the code with pgindent --- src/box.c | 73 +++-- src/box.h | 152 +++++----- src/brin.c | 8 +- src/circle.c | 80 ++--- src/circle.h | 60 ++-- src/ellipse.c | 76 ++--- src/ellipse.h | 108 +++---- src/epochprop.c | 140 +++++---- src/epochprop.h | 38 +-- src/euler.c | 37 ++- src/euler.h | 62 ++-- src/gist.c | 156 +++++----- src/gist.h | 84 ++--- src/gnomo.c | 52 ++-- src/gnomo.h | 4 +- src/healpix.c | 168 ++++++---- src/key.c | 29 +- src/key.h | 68 +++-- src/line.c | 143 +++++---- src/line.h | 106 +++---- src/moc.c | 741 ++++++++++++++++++++++++--------------------- src/output.c | 103 ++++--- src/path.c | 93 +++--- src/path.h | 118 ++++---- src/pg_sphere.h | 13 +- src/pgs_chealpix.h | 2 +- src/pgs_healpix.h | 38 +-- src/pgs_moc.h | 120 ++++---- src/pgs_util.h | 18 +- src/point.c | 38 +-- src/point.h | 40 +-- src/polygon.c | 45 +-- src/polygon.h | 146 ++++----- src/sbuffer.c | 42 +-- src/sbuffer.h | 72 ++--- src/vector3d.c | 4 +- src/vector3d.h | 22 +- 37 files changed, 1749 insertions(+), 1550 deletions(-) diff --git a/src/box.c b/src/box.c index d21e140..b8932fe 100644 --- a/src/box.c +++ b/src/box.c @@ -84,7 +84,7 @@ sbox_check(SBOX *box) if (FPgt(box->sw.lat, box->ne.lat)) { /* swap */ - SPoint sp; + SPoint sp; memcpy((void *) &sp, (void *) &box->sw, sizeof(SPoint)); memcpy((void *) &box->sw, (void *) &box->ne, sizeof(SPoint)); @@ -130,10 +130,10 @@ sbox_circle_pos(const SCIRCLE *sc, const SBOX *sb) const SPoint tmps = {0.0, -PIH}; if (spoint_eq(&sb->ne, &tmpn) && - FPge(sc->center.lat - sc->radius, sb->sw.lat)) + FPge(sc->center.lat - sc->radius, sb->sw.lat)) { if (spoint_eq(&sc->center, &tmpn) && - FPeq(sc->radius, (PIH - sb->sw.lat))) + FPeq(sc->radius, (PIH - sb->sw.lat))) { return PGS_BOX_CIRCLE_EQUAL; } @@ -146,7 +146,7 @@ sbox_circle_pos(const SCIRCLE *sc, const SBOX *sb) FPle(sc->center.lat + sc->radius, sb->ne.lat)) { if (spoint_eq(&sc->center, &tmps) && - FPeq(sc->radius, (PIH + sb->ne.lat))) + FPeq(sc->radius, (PIH + sb->ne.lat))) { return PGS_BOX_CIRCLE_EQUAL; } @@ -169,8 +169,8 @@ sbox_circle_pos(const SCIRCLE *sc, const SBOX *sb) else { bool lat_b_cont_c = - ((sc->center.lat + sc->radius) <= sb->ne.lat) && - ((sc->center.lat - sc->radius) >= sb->sw.lat); + ((sc->center.lat + sc->radius) <= sb->ne.lat) && + ((sc->center.lat - sc->radius) >= sb->sw.lat); bool bcc = sbox_cont_point(sb, &sc->center); bool ccb = false; int8 pw, @@ -218,8 +218,8 @@ sbox_circle_pos(const SCIRCLE *sc, const SBOX *sb) } if (bcc && lat_b_cont_c) { - bool touw = false, - toue = false; + bool touw = false, + toue = false; if (pw == PGS_CIRCLE_LINE_OVER) { @@ -255,11 +255,19 @@ sbox_circle_pos(const SCIRCLE *sc, const SBOX *sb) static int8 sbox_line_pos(const SLine *sl, const SBOX *sb) { - SPoint p1, p2, pbg, ped; - SPoint lc[4]; - int8 pw, pe, lcn, lcs; - SLine bw, be; - float8 minlat, maxlat; + SPoint p1, + p2, + pbg, + ped; + SPoint lc[4]; + int8 pw, + pe, + lcn, + lcs; + SLine bw, + be; + float8 minlat, + maxlat; sline_begin(&pbg, sl); sline_end(&ped, sl); @@ -308,7 +316,7 @@ sbox_line_pos(const SLine *sl, const SBOX *sb) /* special case: east/west boundaries are connected */ if ((FPeq(sb->ne.lat, PIH) || FPeq(sb->sw.lat, -PIH)) && - FPeq(fabs(sb->sw.lng - sb->ne.lng), PI)) + FPeq(fabs(sb->sw.lng - sb->ne.lng), PI)) { if (FPeq(sb->ne.lat, PIH)) { @@ -377,13 +385,13 @@ sbox_line_pos(const SLine *sl, const SBOX *sb) if (pw && pe) { - SPoint sp; - int i; + SPoint sp; + int i; for (i = 0; i < lcn; i++) { if (sbox_cont_point(sb, &lc[i]) && - (!spoint_eq(&pbg, &lc[i]) && !spoint_eq(&ped, &lc[i]))) + (!spoint_eq(&pbg, &lc[i]) && !spoint_eq(&ped, &lc[i]))) { return PGS_BOX_LINE_OVER; } @@ -403,7 +411,7 @@ sbox_line_pos(const SLine *sl, const SBOX *sb) } else if (!pw && !pe) { - int i; + int i; for (i = 0; i < lcn; i++) { @@ -558,7 +566,7 @@ sbox_ellipse_pos(const SELLIPSE *ell, const SBOX *box) if (spoint_eq(&box->sw, &box->ne)) { - bool scp = sellipse_cont_point(ell, &box->sw); + bool scp = sellipse_cont_point(ell, &box->sw); if (scp) { @@ -622,8 +630,8 @@ sbox_ellipse_pos(const SELLIPSE *ell, const SBOX *box) { /* full latitude range */ if ((po == PGS_CIRCLE_CONT_ELLIPSE - || po == PGS_ELLIPSE_CIRCLE_EQUAL) && - pi == PGS_ELLIPSE_CIRCLE_AVOID) + || po == PGS_ELLIPSE_CIRCLE_EQUAL) && + pi == PGS_ELLIPSE_CIRCLE_AVOID) { return PGS_BOX_CONT_ELLIPSE; } @@ -674,15 +682,15 @@ sbox_ellipse_pos(const SELLIPSE *ell, const SBOX *box) { /* center is between west and east meridians */ if ((FPgt(box->sw.lng, box->ne.lng) && - (FPle(ec.lng, box->ne.lng) || FPgt(ec.lng, box->sw.lng))) || + (FPle(ec.lng, box->ne.lng) || FPgt(ec.lng, box->sw.lng))) || (FPle(box->sw.lng, box->ne.lng) && - (FPge(ec.lng, box->sw.lng) && FPle(ec.lng, box->ne.lng)))) + (FPge(ec.lng, box->sw.lng) && FPle(ec.lng, box->ne.lng)))) { if (FPeq(sco.center.lat, sci.center.lat)) { if ((po == PGS_CIRCLE_CONT_ELLIPSE - || po == PGS_ELLIPSE_CIRCLE_EQUAL) && - pi == PGS_ELLIPSE_CIRCLE_AVOID) + || po == PGS_ELLIPSE_CIRCLE_EQUAL) && + pi == PGS_ELLIPSE_CIRCLE_AVOID) { return PGS_BOX_CONT_ELLIPSE; } @@ -710,7 +718,8 @@ sbox_ellipse_pos(const SELLIPSE *ell, const SBOX *box) } else { - SPoint p1, p2; + SPoint p1, + p2; /* create east/west boundaries */ p1.lat = box->sw.lat; @@ -744,10 +753,14 @@ sbox_ellipse_pos(const SELLIPSE *ell, const SBOX *box) static int8 sbox_box_pos(const SBOX *b1, const SBOX *b2, bool recheck) { - SPoint p1, p2, bc; - int8 pw, pe; - SLine bw, be; - bool scp; + SPoint p1, + p2, + bc; + int8 pw, + pe; + SLine bw, + be; + bool scp; if (spoint_eq(&b2->sw, &b2->ne)) { diff --git a/src/box.h b/src/box.h index 7314ac0..34acc10 100644 --- a/src/box.h +++ b/src/box.h @@ -11,8 +11,8 @@ */ typedef struct { - SPoint sw; /* South-west value of a box */ - SPoint ne; /* North-east value of a box */ + SPoint sw; /* South-west value of a box */ + SPoint ne; /* North-east value of a box */ } SBOX; @@ -56,373 +56,373 @@ typedef struct /* * Checks whether two boxes are equal. */ -bool sbox_eq(SBOX *b1, SBOX *b2); +bool sbox_eq(SBOX *b1, SBOX *b2); /* * Checks whether a point is contained by a box. */ -bool sbox_cont_point(const SBOX *b, const SPoint *p); +bool sbox_cont_point(const SBOX *b, const SPoint *p); /* * Input function of a box. */ -Datum spherebox_in(PG_FUNCTION_ARGS); +Datum spherebox_in(PG_FUNCTION_ARGS); /* * Input function of a box from two points. The first point * is the south-west position, the second the north-east position. */ -Datum spherebox_in_from_points(PG_FUNCTION_ARGS); +Datum spherebox_in_from_points(PG_FUNCTION_ARGS); /* * Returns the south-west edge of a box. */ -Datum spherebox_sw(PG_FUNCTION_ARGS); +Datum spherebox_sw(PG_FUNCTION_ARGS); /* * Returns the north-east edge of a box. */ -Datum spherebox_ne(PG_FUNCTION_ARGS); +Datum spherebox_ne(PG_FUNCTION_ARGS); /* * Returns the south-east edge of a box. */ -Datum spherebox_se(PG_FUNCTION_ARGS); +Datum spherebox_se(PG_FUNCTION_ARGS); /* * Returns the north-west edge of a box. */ -Datum spherebox_nw(PG_FUNCTION_ARGS); +Datum spherebox_nw(PG_FUNCTION_ARGS); /* * Returns the area of a box. */ -Datum spherebox_area(PG_FUNCTION_ARGS); +Datum spherebox_area(PG_FUNCTION_ARGS); /* * Returns the circumference of a box. */ -Datum spherebox_circ(PG_FUNCTION_ARGS); +Datum spherebox_circ(PG_FUNCTION_ARGS); /* * Checks whether two boxes are equal. */ -Datum spherebox_equal(PG_FUNCTION_ARGS); +Datum spherebox_equal(PG_FUNCTION_ARGS); /* * Checks whether two boxes are not equal. */ -Datum spherebox_equal_neg(PG_FUNCTION_ARGS); +Datum spherebox_equal_neg(PG_FUNCTION_ARGS); /* * Checks whether a point is contained by a box. */ -Datum spherebox_cont_point(PG_FUNCTION_ARGS); +Datum spherebox_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a point isn't contained by a box. */ -Datum spherebox_cont_point_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a point is contained by a box. */ -Datum spherebox_cont_point_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a point isn't contained by a box. */ -Datum spherebox_cont_point_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a circle. */ -Datum spherebox_cont_circle(PG_FUNCTION_ARGS); +Datum spherebox_cont_circle(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a circle. */ -Datum spherebox_cont_circle_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a circle. */ -Datum spherebox_cont_circle_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a circle. */ -Datum spherebox_cont_circle_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a box. */ -Datum spherecircle_cont_box(PG_FUNCTION_ARGS); +Datum spherecircle_cont_box(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a box. */ -Datum spherecircle_cont_box_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a box. */ -Datum spherecircle_cont_box_com(PG_FUNCTION_ARGS); +Datum spherecircle_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a box. */ -Datum spherecircle_cont_box_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box overlap. */ -Datum spherebox_overlap_circle(PG_FUNCTION_ARGS); +Datum spherebox_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box don't overlap. */ -Datum spherebox_overlap_circle_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box overlap. */ -Datum spherebox_overlap_circle_com(PG_FUNCTION_ARGS); +Datum spherebox_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box don't overlap. */ -Datum spherebox_overlap_circle_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a line. */ -Datum spherebox_cont_line(PG_FUNCTION_ARGS); +Datum spherebox_cont_line(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a line. */ -Datum spherebox_cont_line_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a line. */ -Datum spherebox_cont_line_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a line. */ -Datum spherebox_cont_line_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a line overlap. */ -Datum spherebox_overlap_line(PG_FUNCTION_ARGS); +Datum spherebox_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether a box and a line don't overlap. */ -Datum spherebox_overlap_line_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a line overlap. */ -Datum spherebox_overlap_line_com(PG_FUNCTION_ARGS); +Datum spherebox_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether a box and a line don't overlap. */ -Datum spherebox_overlap_line_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a path. */ -Datum spherebox_cont_path(PG_FUNCTION_ARGS); +Datum spherebox_cont_path(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a path. */ -Datum spherebox_cont_path_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a path. */ -Datum spherebox_cont_path_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a path. */ -Datum spherebox_cont_path_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a path overlap. */ -Datum spherebox_overlap_path(PG_FUNCTION_ARGS); +Datum spherebox_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether a box and a path don't overlap. */ -Datum spherebox_overlap_path_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a path overlap. */ -Datum spherebox_overlap_path_com(PG_FUNCTION_ARGS); +Datum spherebox_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether a box and a path don't overlap. */ -Datum spherebox_overlap_path_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a polygon. */ -Datum spherebox_cont_poly(PG_FUNCTION_ARGS); +Datum spherebox_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a polygon. */ -Datum spherebox_cont_poly_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a polygon. */ -Datum spherebox_cont_poly_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a polygon. */ -Datum spherebox_cont_poly_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a box. */ -Datum spherepoly_cont_box(PG_FUNCTION_ARGS); +Datum spherepoly_cont_box(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a box. */ -Datum spherepoly_cont_box_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a box. */ -Datum spherepoly_cont_box_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a box. */ -Datum spherepoly_cont_box_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box overlap. */ -Datum spherebox_overlap_poly(PG_FUNCTION_ARGS); +Datum spherebox_overlap_poly(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box don't overlap. */ -Datum spherebox_overlap_poly_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box overlap. */ -Datum spherebox_overlap_poly_com(PG_FUNCTION_ARGS); +Datum spherebox_overlap_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box don't overlap. */ -Datum spherebox_overlap_poly_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains an ellipse. */ -Datum spherebox_cont_ellipse(PG_FUNCTION_ARGS); +Datum spherebox_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain an ellipse. */ -Datum spherebox_cont_ellipse_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains an ellipse. */ -Datum spherebox_cont_ellipse_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain an ellipse. */ -Datum spherebox_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a box. */ -Datum sphereellipse_cont_box(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_box(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a box. */ -Datum sphereellipse_cont_box_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a box. */ -Datum sphereellipse_cont_box_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a box. */ -Datum sphereellipse_cont_box_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box overlap. */ -Datum spherebox_overlap_ellipse(PG_FUNCTION_ARGS); +Datum spherebox_overlap_ellipse(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box don't overlap. */ -Datum spherebox_overlap_ellipse_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box overlap. */ -Datum spherebox_overlap_ellipse_com(PG_FUNCTION_ARGS); +Datum spherebox_overlap_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box don't overlap. */ -Datum spherebox_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains another box. */ -Datum spherebox_cont_box(PG_FUNCTION_ARGS); +Datum spherebox_cont_box(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain another box. */ -Datum spherebox_cont_box_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains another box. */ -Datum spherebox_cont_box_com(PG_FUNCTION_ARGS); +Datum spherebox_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain another box. */ -Datum spherebox_cont_box_com_neg(PG_FUNCTION_ARGS); +Datum spherebox_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two boxes overlap. */ -Datum spherebox_overlap_box(PG_FUNCTION_ARGS); +Datum spherebox_overlap_box(PG_FUNCTION_ARGS); /* * Checks whether two boxes don't overlap. */ -Datum spherebox_overlap_box_neg(PG_FUNCTION_ARGS); +Datum spherebox_overlap_box_neg(PG_FUNCTION_ARGS); #endif diff --git a/src/brin.c b/src/brin.c index 1c5ae1b..eb9d4d4 100644 --- a/src/brin.c +++ b/src/brin.c @@ -61,7 +61,8 @@ spoint_brin_inclusion_add_value(PG_FUNCTION_ARGS) * The OpClass support empty entries: we need to set the "contains empty" * flag in the element (unless already set). */ - /* + + /* -------- if (spointkey == NULL) { if (!DatumGetBool(column->bv_values[INCLUSION_CONTAINS_EMPTY])) @@ -72,6 +73,7 @@ spoint_brin_inclusion_add_value(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } + * -------- */ /* if the recorded value is null, we just need to store the spherekey */ @@ -131,7 +133,8 @@ sbox_brin_inclusion_add_value(PG_FUNCTION_ARGS) * The OpClass support empty entries: we need to set the "contains empty" * flag in the element (unless already set). */ - /* + + /* -------- if (sboxkey == NULL) { if (!DatumGetBool(column->bv_values[INCLUSION_CONTAINS_EMPTY])) @@ -142,6 +145,7 @@ sbox_brin_inclusion_add_value(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } + * -------- */ /* if the recorded value is null, we just need to store the spherekey */ diff --git a/src/circle.c b/src/circle.c index e28fe0c..7489530 100644 --- a/src/circle.c +++ b/src/circle.c @@ -34,13 +34,13 @@ bool scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2) { return (spoint_eq(&c1->center, &c2->center) && - FPeq(c1->radius, c2->radius)); + FPeq(c1->radius, c2->radius)); } bool spoint_in_circle(const SPoint *p, const SCIRCLE *c) { - float8 dist = spoint_dist(p, &c->center); + float8 dist = spoint_dist(p, &c->center); if (FPle(dist, c->radius)) { @@ -59,7 +59,7 @@ euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se) Datum spherecircle_in(PG_FUNCTION_ARGS) { - SCIRCLE *c = (SCIRCLE *) palloc(sizeof(SCIRCLE)); + SCIRCLE *c = (SCIRCLE *) palloc(sizeof(SCIRCLE)); char *s = PG_GETARG_CSTRING(0); double lng, lat, @@ -103,8 +103,8 @@ spherecircle_in(PG_FUNCTION_ARGS) Datum spherecircle_equal(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(scircle_eq(c1, c2)); } @@ -112,8 +112,8 @@ spherecircle_equal(PG_FUNCTION_ARGS) Datum spherecircle_equal_neg(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(!scircle_eq(c1, c2)); } @@ -121,8 +121,8 @@ spherecircle_equal_neg(PG_FUNCTION_ARGS) Datum spherecircle_distance(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c1->center, &c2->center); dist -= (c1->radius + c2->radius); @@ -136,7 +136,7 @@ spherecircle_distance(PG_FUNCTION_ARGS) Datum spherecircle_point_distance(PG_FUNCTION_ARGS) { - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); SPoint *p = (SPoint *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c->center, p); @@ -152,7 +152,7 @@ Datum spherecircle_point_distance_com(PG_FUNCTION_ARGS) { SPoint *p = (SPoint *) PG_GETARG_POINTER(0); - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c->center, p); dist = dist - c->radius; @@ -167,7 +167,7 @@ Datum spherepoint_in_circle(PG_FUNCTION_ARGS) { SPoint *p = (SPoint *) PG_GETARG_POINTER(0); - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(spoint_in_circle(p, c)); } @@ -185,7 +185,7 @@ Datum spherepoint_in_circle_com(PG_FUNCTION_ARGS) { SPoint *p = (SPoint *) PG_GETARG_POINTER(1); - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); PG_RETURN_BOOL(spoint_in_circle(p, c)); } @@ -194,7 +194,7 @@ Datum spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS) { SPoint *p = (SPoint *) PG_GETARG_POINTER(1); - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); PG_RETURN_BOOL(!spoint_in_circle(p, c)); } @@ -202,8 +202,8 @@ spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS) Datum spherecircle_in_circle(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c1->center, &c2->center); if (scircle_eq(c1, c2)) @@ -223,8 +223,8 @@ spherecircle_in_circle(PG_FUNCTION_ARGS) Datum spherecircle_in_circle_neg(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c1->center, &c2->center); if (scircle_eq(c1, c2)) @@ -244,8 +244,8 @@ spherecircle_in_circle_neg(PG_FUNCTION_ARGS) Datum spherecircle_in_circle_com(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(1); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(0); float8 dist = spoint_dist(&c1->center, &c2->center); if (scircle_eq(c1, c2)) @@ -265,8 +265,8 @@ spherecircle_in_circle_com(PG_FUNCTION_ARGS) Datum spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(1); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(0); float8 dist = spoint_dist(&c1->center, &c2->center); if (scircle_eq(c1, c2)) @@ -286,8 +286,8 @@ spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS) Datum spherecircle_overlap(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c1->center, &c2->center); if (scircle_eq(c1, c2)) @@ -307,8 +307,8 @@ spherecircle_overlap(PG_FUNCTION_ARGS) Datum spherecircle_overlap_neg(PG_FUNCTION_ARGS) { - SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); - SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); + SCIRCLE *c1 = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c2 = (SCIRCLE *) PG_GETARG_POINTER(1); float8 dist = spoint_dist(&c1->center, &c2->center); if (scircle_eq(c1, c2)) @@ -328,7 +328,7 @@ spherecircle_overlap_neg(PG_FUNCTION_ARGS) Datum spherecircle_center(PG_FUNCTION_ARGS) { - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); SPoint *p = (SPoint *) palloc(sizeof(SPoint)); memcpy((void *) p, (void *) &c->center, sizeof(SPoint)); @@ -338,7 +338,7 @@ spherecircle_center(PG_FUNCTION_ARGS) Datum spherecircle_radius(PG_FUNCTION_ARGS) { - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); PG_RETURN_FLOAT8(c->radius); } @@ -347,7 +347,7 @@ Datum spherepoint_to_circle(PG_FUNCTION_ARGS) { SPoint *p = (SPoint *) PG_GETARG_POINTER(0); - SCIRCLE *c = (SCIRCLE *) palloc(sizeof(SCIRCLE)); + SCIRCLE *c = (SCIRCLE *) palloc(sizeof(SCIRCLE)); memcpy((void *) &c->center, (void *) p, sizeof(SPoint)); c->radius = 0; @@ -359,7 +359,7 @@ spherecircle_by_center(PG_FUNCTION_ARGS) { SPoint *p = (SPoint *) PG_GETARG_POINTER(0); float8 rad = PG_GETARG_FLOAT8(1); - SCIRCLE *c; + SCIRCLE *c; if (FPgt(rad, PIH) || FPlt(rad, 0.0)) { @@ -375,21 +375,21 @@ spherecircle_by_center(PG_FUNCTION_ARGS) Datum spherecircle_by_center_deg(PG_FUNCTION_ARGS) { - Datum res; + Datum res; SPoint *p = (SPoint *) PG_GETARG_POINTER(0); const float8 rad = deg_to_rad(PG_GETARG_FLOAT8(1)); - res = DirectFunctionCall2( - spherecircle_by_center, - PointerGetDatum(p), - Float8GetDatum(rad) - ); + + res = DirectFunctionCall2(spherecircle_by_center, + PointerGetDatum(p), + Float8GetDatum(rad)); + PG_RETURN_DATUM(res); } Datum spherecircle_area(PG_FUNCTION_ARGS) { - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); PG_RETURN_FLOAT8(PID * (1 - cos(c->radius))); } @@ -397,7 +397,7 @@ spherecircle_area(PG_FUNCTION_ARGS) Datum spherecircle_circ(PG_FUNCTION_ARGS) { - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); PG_RETURN_FLOAT8(PID * (sin(c->radius))); } @@ -405,9 +405,9 @@ spherecircle_circ(PG_FUNCTION_ARGS) Datum spheretrans_circle(PG_FUNCTION_ARGS) { - SCIRCLE *sc = (SCIRCLE *) PG_GETARG_POINTER(0); + SCIRCLE *sc = (SCIRCLE *) PG_GETARG_POINTER(0); SEuler *se = (SEuler *) PG_GETARG_POINTER(1); - SCIRCLE *out = (SCIRCLE *) palloc(sizeof(SCIRCLE)); + SCIRCLE *out = (SCIRCLE *) palloc(sizeof(SCIRCLE)); euler_scircle_trans(out, sc, se); PG_RETURN_POINTER(out); diff --git a/src/circle.h b/src/circle.h index b8aa520..6089fab 100644 --- a/src/circle.h +++ b/src/circle.h @@ -10,151 +10,151 @@ */ typedef struct { - SPoint center; /* the center of circle */ - float8 radius; /* the circle radius in radians */ + SPoint center; /* the center of circle */ + float8 radius; /* the circle radius in radians */ } SCIRCLE; /* * Checks whether two circles are equal. */ -bool scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2); +bool scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2); /* * Checks whether a circle contains a point. */ -bool spoint_in_circle(const SPoint *p, const SCIRCLE *c); +bool spoint_in_circle(const SPoint *p, const SCIRCLE *c); /* * Transforms a circle using an Euler transformation. */ -void euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se); +void euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se); /* * Takes the input and stores it as a spherical circle. */ -Datum spherecircle_in(PG_FUNCTION_ARGS); +Datum spherecircle_in(PG_FUNCTION_ARGS); /* * Checks whether two circles are equal. */ -Datum spherecircle_equal(PG_FUNCTION_ARGS); +Datum spherecircle_equal(PG_FUNCTION_ARGS); /* * Checks whether two circles are not equal. */ -Datum spherecircle_equal_neg(PG_FUNCTION_ARGS); +Datum spherecircle_equal_neg(PG_FUNCTION_ARGS); /* * Calculate the distance of two circles. If they overlap, this function * returns 0.0. */ -Datum spherecircle_distance(PG_FUNCTION_ARGS); +Datum spherecircle_distance(PG_FUNCTION_ARGS); /* * Calculate the distance of a circle and a point. If a circle contains a point, * this function returns 0.0. */ -Datum spherecircle_point_distance(PG_FUNCTION_ARGS); +Datum spherecircle_point_distance(PG_FUNCTION_ARGS); /* * Calculate the distance of a point and a circle. If a circle contains a point, * this function returns 0.0. */ -Datum spherecircle_point_distance_com(PG_FUNCTION_ARGS); +Datum spherecircle_point_distance_com(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a point. */ -Datum spherepoint_in_circle(PG_FUNCTION_ARGS); +Datum spherepoint_in_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a point. */ -Datum spherepoint_in_circle_neg(PG_FUNCTION_ARGS); +Datum spherepoint_in_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a point. */ -Datum spherepoint_in_circle_com(PG_FUNCTION_ARGS); +Datum spherepoint_in_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a point. */ -Datum spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS); +Datum spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle is contained by other circle. */ -Datum spherecircle_in_circle(PG_FUNCTION_ARGS); +Datum spherecircle_in_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle is not contained by other circle. */ -Datum spherecircle_in_circle_neg(PG_FUNCTION_ARGS); +Datum spherecircle_in_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains other circle. */ -Datum spherecircle_in_circle_com(PG_FUNCTION_ARGS); +Datum spherecircle_in_circle_com(PG_FUNCTION_ARGS); /* * Checks whether circle does not contain other circle. */ -Datum spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two circles overlap. */ -Datum spherecircle_overlap(PG_FUNCTION_ARGS); +Datum spherecircle_overlap(PG_FUNCTION_ARGS); /* * Checks whether two circles overlap. */ -Datum spherecircle_overlap_neg(PG_FUNCTION_ARGS); +Datum spherecircle_overlap_neg(PG_FUNCTION_ARGS); /* * Returns the center of a circle. */ -Datum spherecircle_center(PG_FUNCTION_ARGS); +Datum spherecircle_center(PG_FUNCTION_ARGS); /* * Returns the radius of a circle. */ -Datum spherecircle_radius(PG_FUNCTION_ARGS); +Datum spherecircle_radius(PG_FUNCTION_ARGS); /* * Converts a point to a circle. */ -Datum spherepoint_to_circle(PG_FUNCTION_ARGS); +Datum spherepoint_to_circle(PG_FUNCTION_ARGS); /* * Creates a circle from center and radius. */ -Datum spherecircle_by_center(PG_FUNCTION_ARGS); +Datum spherecircle_by_center(PG_FUNCTION_ARGS); /* * Creates a circle from center and radius(in degrees). */ -Datum spherecircle_by_center_deg(PG_FUNCTION_ARGS); +Datum spherecircle_by_center_deg(PG_FUNCTION_ARGS); /* * Calculates the area of a circle in square radians. */ -Datum spherecircle_area(PG_FUNCTION_ARGS); +Datum spherecircle_area(PG_FUNCTION_ARGS); /* * Calculates the circumference of a circle in radians. */ -Datum spherecircle_circ(PG_FUNCTION_ARGS); +Datum spherecircle_circ(PG_FUNCTION_ARGS); /* * Transforms a circle using an Euler transformation. */ -Datum spheretrans_circle(PG_FUNCTION_ARGS); +Datum spheretrans_circle(PG_FUNCTION_ARGS); /* * Inverse transformation of a circle using an Euler transformation. */ -Datum spheretrans_circle_inverse(PG_FUNCTION_ARGS); +Datum spheretrans_circle_inverse(PG_FUNCTION_ARGS); #endif diff --git a/src/ellipse.c b/src/ellipse.c index 0e535ac..73b75be 100644 --- a/src/ellipse.c +++ b/src/ellipse.c @@ -68,7 +68,7 @@ my_acos(float8 a) static void sellipse_check(SELLIPSE *e) { - SPoint sp; + SPoint sp; sp.lng = e->phi; spoint_check(&sp); @@ -92,7 +92,7 @@ sellipse_check(SELLIPSE *e) static void sellipse_circle(SCIRCLE *sc, const SELLIPSE *e) { - SPoint sp; + SPoint sp; sellipse_center(&sp, e); memcpy((void *) &sc->center, (void *) &sp, sizeof(SPoint)); @@ -136,7 +136,7 @@ sellipse_in(float8 r1, float8 r2, const SPoint *c, float8 inc) static float8 sellipse_dist(float8 rada, float8 radb, float8 ang) { - float8 e; + float8 e; e = (1 - Sqr(sin(radb)) / Sqr(sin(rada))); return (asin(sin(radb) / sqrt(1 - e * Sqr(cos(ang))))); @@ -148,9 +148,11 @@ sellipse_dist(float8 rada, float8 radb, float8 ang) static float8 sellipse_point_dist(const SELLIPSE *se, const SPoint *sp) { - SEuler e; - SPoint p; - float8 dist, rad, ang; + SEuler e; + SPoint p; + float8 dist, + rad, + ang; sellipse_trans(&e, se); spheretrans_inv(&e); @@ -193,9 +195,9 @@ sellipse_point_dist(const SELLIPSE *se, const SPoint *sp) static void euler_sellipse_trans(SELLIPSE *out, const SELLIPSE *in, const SEuler *se) { - SEuler et; - SLine sl[2]; - SPoint p[2]; + SEuler et; + SLine sl[2]; + SPoint p[2]; sellipse_trans(&et, in); sl[0].length = PIH; @@ -228,7 +230,7 @@ euler_sellipse_trans(SELLIPSE *out, const SELLIPSE *in, const SEuler *se) static int8 sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) { - int8 r; + int8 r; /* equality */ if (sellipse_eq(se1, se2)) @@ -240,7 +242,7 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) if (FPeq(se2->rad[0], se2->rad[1])) { - SCIRCLE c; + SCIRCLE c; sellipse_circle(&c, se2); r = sellipse_circle_pos(se1, &c); @@ -265,7 +267,7 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) if (FPeq(se1->rad[0], se1->rad[1])) { - SCIRCLE c; + SCIRCLE c; sellipse_circle(&c, se1); r = sellipse_circle_pos(se2, &c); @@ -288,7 +290,7 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) /* se2 is line */ if (FPzero(se2->rad[1])) { - SLine l; + SLine l; sellipse_line(&l, se2); r = sellipse_line_pos(se1, &l); @@ -309,7 +311,7 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) /* se1 is line */ if (FPzero(se1->rad[1])) { - SLine l; + SLine l; sellipse_line(&l, se1); r = sellipse_line_pos(se2, &l); @@ -331,8 +333,9 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) do { - SPoint p1, p2; - float8 dist; + SPoint p1, + p2; + float8 dist; /* check inner and outer circles */ sellipse_center(&p1, se1); @@ -353,7 +356,8 @@ sellipse_ellipse_pos(const SELLIPSE *se1, const SELLIPSE *se2) else { SEuler eul; - SELLIPSE etmp, e; + SELLIPSE etmp, + e; SPoint sp[3]; int i; float8 diff[3]; @@ -515,9 +519,9 @@ sellipse_line(SLine *sl, const SELLIPSE *e) { if (!FPzero(e->rad[0])) { - SEuler se; - SLine slt; - SPoint p[2]; + SEuler se; + SLine slt; + SPoint p[2]; p[0].lat = p[1].lat = 0.0; p[0].lng = -e->rad[0]; @@ -543,7 +547,7 @@ sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2) else if (FPzero(e1->rad[0])) { /* point */ - SPoint p[2]; + SPoint p[2]; sellipse_center(&p[0], e1); sellipse_center(&p[1], e2); @@ -552,7 +556,7 @@ sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2) else if (FPeq(e1->rad[0], e1->rad[1])) { /* circle */ - SCIRCLE c[2]; + SCIRCLE c[2]; sellipse_circle(&c[0], e1); sellipse_circle(&c[1], e2); @@ -560,7 +564,7 @@ sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2) } else { - SEuler se[2]; + SEuler se[2]; sellipse_trans(&se[0], e1); sellipse_trans(&se[1], e2); @@ -663,8 +667,8 @@ sellipse_line_pos(const SELLIPSE *se, const SLine *sl) /* ellipse is line */ if (FPzero(se->rad[1])) { - SLine l; - int8 res; + SLine l; + int8 res; sellipse_line(&l, se); res = sline_sline_pos(&l, sl); @@ -867,8 +871,8 @@ sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc) /* ellipse is circle */ if (FPeq(se->rad[0], se->rad[1])) { - SCIRCLE tc; - float8 dist; + SCIRCLE tc; + float8 dist; sellipse_circle(&tc, se); if (scircle_eq(&tc, sc)) @@ -897,8 +901,8 @@ sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc) /* ellipse is line */ if (FPzero(se->rad[1])) { - SLine l; - int8 res; + SLine l; + int8 res; sellipse_line(&l, se); res = sphereline_circle_pos(&l, sc); @@ -919,12 +923,11 @@ sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc) else { /* - * now ellipse is a real ellipse and - * circle is a real circle + * now ellipse is a real ellipse and circle is a real circle */ - float8 dist; - SPoint c; + float8 dist; + SPoint c; sellipse_center(&c, se); dist = spoint_dist(&sc->center, &c); @@ -948,9 +951,10 @@ sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc) else { - SEuler et; - SPoint p; - float8 a, e; + SEuler et; + SPoint p; + float8 a, + e; sellipse_trans(&et, se); spheretrans_inv(&et); diff --git a/src/ellipse.h b/src/ellipse.h index b27bc3b..6b3ff56 100644 --- a/src/ellipse.h +++ b/src/ellipse.h @@ -18,9 +18,9 @@ typedef struct */ float8 rad[2]; - float8 phi, /* the first rotation angle around z axis */ - theta, /* the second rotation angle around x axis */ - psi; /* the last rotation angle around z axis */ + float8 phi, /* the first rotation angle around z axis */ + theta, /* the second rotation angle around x axis */ + psi; /* the last rotation angle around z axis */ } SELLIPSE; /* @@ -47,258 +47,258 @@ typedef struct /* * Checks whether two ellipses are equal . */ -bool sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2); +bool sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2); /* * Returns the center of an ellipse. */ -void sellipse_center(SPoint *sp, const SELLIPSE *e); +void sellipse_center(SPoint *sp, const SELLIPSE *e); /* * Checks whether a ellipse contains point. */ -bool sellipse_cont_point(const SELLIPSE *se, const SPoint *sp); +bool sellipse_cont_point(const SELLIPSE *se, const SPoint *sp); /* * Returns the large axis of an ellipse as line. */ -bool sellipse_line(SLine *sl, const SELLIPSE *e); +bool sellipse_line(SLine *sl, const SELLIPSE *e); /* * Relationship between a line and an ellipse as PGS_ELLIPSE_LINE_REL int8 value. */ -int8 sellipse_line_pos(const SELLIPSE *se, const SLine *sl); +int8 sellipse_line_pos(const SELLIPSE *se, const SLine *sl); /* * Relationship between a circle and an ellipse as PGS_ELLIPSE_CIRCLE_REL int8 value. */ -int8 sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc); +int8 sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc); /* * Returns the Euler transformation of an ellipse. */ -void sellipse_trans(SEuler *se, const SELLIPSE *e); +void sellipse_trans(SEuler *se, const SELLIPSE *e); /* * Input of the spherical ellipse. */ -Datum sphereellipse_in(PG_FUNCTION_ARGS); +Datum sphereellipse_in(PG_FUNCTION_ARGS); /* * Input of the spherical ellipse from center, axes and inclination. */ -Datum sphereellipse_infunc(PG_FUNCTION_ARGS); +Datum sphereellipse_infunc(PG_FUNCTION_ARGS); /* * Returns the inclination of an ellipse. */ -Datum sphereellipse_incl(PG_FUNCTION_ARGS); +Datum sphereellipse_incl(PG_FUNCTION_ARGS); /* * Returns the length of the major axis of an ellipse. */ -Datum sphereellipse_rad1(PG_FUNCTION_ARGS); +Datum sphereellipse_rad1(PG_FUNCTION_ARGS); /* * Returns the length of the minor axis of an ellipse. */ -Datum sphereellipse_rad2(PG_FUNCTION_ARGS); +Datum sphereellipse_rad2(PG_FUNCTION_ARGS); /* * Returns the center of an ellipse. */ -Datum sphereellipse_center(PG_FUNCTION_ARGS); +Datum sphereellipse_center(PG_FUNCTION_ARGS); /* * Returns the Euler transformation of an ellipse. */ -Datum sphereellipse_trans(PG_FUNCTION_ARGS); +Datum sphereellipse_trans(PG_FUNCTION_ARGS); /* * Casts a spherical ellipse as circle. The created circle is the boundary * circle of ellipse. The diameter of returned circle is equal to length of * major axis of ellipse. */ -Datum sphereellipse_circle(PG_FUNCTION_ARGS); +Datum sphereellipse_circle(PG_FUNCTION_ARGS); /* * Casts a spherical point to an ellipse. */ -Datum spherepoint_ellipse(PG_FUNCTION_ARGS); +Datum spherepoint_ellipse(PG_FUNCTION_ARGS); /* * Casts a spherical circle to an ellipse. */ -Datum spherecircle_ellipse(PG_FUNCTION_ARGS); +Datum spherecircle_ellipse(PG_FUNCTION_ARGS); /* * Checks whether two ellipses are equal. */ -Datum sphereellipse_equal(PG_FUNCTION_ARGS); +Datum sphereellipse_equal(PG_FUNCTION_ARGS); /* * Checks whether two ellipses are not equal. */ -Datum sphereellipse_equal_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_equal_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a point. */ -Datum sphereellipse_cont_point(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_point(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a point. */ -Datum sphereellipse_cont_point_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a point. */ -Datum sphereellipse_cont_point_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a point. */ -Datum sphereellipse_cont_point_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a line. */ -Datum sphereellipse_cont_line(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_line(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a line. */ -Datum sphereellipse_cont_line_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a line. */ -Datum sphereellipse_cont_line_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a line. */ -Datum sphereellipse_cont_line_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line overlap. */ -Datum sphereellipse_overlap_line(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line don't overlap. */ -Datum sphereellipse_overlap_line_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line overlap. */ -Datum sphereellipse_overlap_line_com(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line don't overlap. */ -Datum sphereellipse_overlap_line_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a circle. */ -Datum sphereellipse_cont_circle(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_circle(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a circle. */ -Datum sphereellipse_cont_circle_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a circle. */ -Datum sphereellipse_cont_circle_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_circle_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a circle. */ -Datum sphereellipse_cont_circle_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains an ellipse. */ -Datum spherecircle_cont_ellipse(PG_FUNCTION_ARGS); +Datum spherecircle_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain an ellipse. */ -Datum spherecircle_cont_ellipse_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains an ellipse. */ -Datum spherecircle_cont_ellipse_com(PG_FUNCTION_ARGS); +Datum spherecircle_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain an ellipse. */ -Datum spherecircle_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse overlap. */ -Datum sphereellipse_overlap_circle(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse don't overlap. */ -Datum sphereellipse_overlap_circle_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse overlap. */ -Datum sphereellipse_overlap_circle_com(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse don't overlap. */ -Datum sphereellipse_overlap_circle_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains other ellipse. */ -Datum sphereellipse_cont_ellipse(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain other ellipse. */ -Datum sphereellipse_cont_ellipse_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse is contained by other ellipse. */ -Datum sphereellipse_cont_ellipse_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse isn't contained by other ellipse. */ -Datum sphereellipse_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two ellipses overlap. */ -Datum sphereellipse_overlap_ellipse(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_ellipse(PG_FUNCTION_ARGS); /* * Checks whether two ellipses don't overlap. */ -Datum sphereellipse_overlap_ellipse_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_ellipse_neg(PG_FUNCTION_ARGS); /* * Transforms an ellipse using an Euler transformation. */ -Datum spheretrans_ellipse(PG_FUNCTION_ARGS); +Datum spheretrans_ellipse(PG_FUNCTION_ARGS); /* * Transforms an ellipse using an Euler transformation. */ -Datum spheretrans_ellipse_inv(PG_FUNCTION_ARGS); +Datum spheretrans_ellipse_inv(PG_FUNCTION_ARGS); #endif diff --git a/src/epochprop.c b/src/epochprop.c index ab9abc8..3409ad2 100644 --- a/src/epochprop.c +++ b/src/epochprop.c @@ -35,27 +35,44 @@ stuffing an updated phase vector in result. This does not propagate errors. */ -static void propagate_phasevec( - const phasevec *pv, - const double delta_t, - phasevec *result) { - - double distance_factor, mu0abs, zeta0, parallax; - - Vector3D p0, r0, q0; - Vector3D mu0, pprime, qprime, mu, muprime, u, uprime; - - /* for very small or null parallaxes, our algorithm breaks; avoid that - and, if we did emergency measures, do not talk about parallax and - radial velocity in the output */ - if (pv->parallax_valid) { +static void +propagate_phasevec(const phasevec *pv, + const double delta_t, + phasevec *result) +{ + + double distance_factor, + mu0abs, + zeta0, + parallax; + + Vector3D p0, + r0, + q0; + Vector3D mu0, + pprime, + qprime, + mu, + muprime, + u, + uprime; + + /* + * for very small or null parallaxes, our algorithm breaks; avoid that + * and, if we did emergency measures, do not talk about parallax and + * radial velocity in the output + */ + if (pv->parallax_valid) + { parallax = pv->parallax; - } else { + } + else + { parallax = PX_MIN; } result->parallax_valid = pv->parallax_valid; - /* compute the normal triad as Vector3D-s, eq. (1.2.15)*/ + /* compute the normal triad as Vector3D-s, eq. (1.2.15) */ spoint_vector3d(&r0, &(pv->pos)); p0.x = -sin(pv->pos.lng); @@ -72,13 +89,15 @@ static void propagate_phasevec( vector3d_addwithscalar(&mu0, pv->pm[1], &q0); mu0abs = vector3d_length(&mu0); - /* radial velocity in mas/yr ("change of parallax per year"). eq. (1.5.24) - We're transforming this to rad/yr so the units work out below */ + /* + * radial velocity in mas/yr ("change of parallax per year"). eq. + * (1.5.24) We're transforming this to rad/yr so the units work out below + */ zeta0 = (pv->rv * parallax / A_NU) / 3.6e6 / RADIANS; /* distance factor eq. (1.5.25) */ - distance_factor = 1/sqrt(1 - + 2 * zeta0 * delta_t - + (mu0abs * mu0abs + zeta0 * zeta0) * delta_t * delta_t); + distance_factor = 1 / sqrt(1 + + 2 * zeta0 * delta_t + + (mu0abs * mu0abs + zeta0 * zeta0) * delta_t * delta_t); /* the propagated proper motion vector, eq. (1.5.28) */ muprime.x = muprime.y = muprime.z = 0; @@ -88,7 +107,7 @@ static void propagate_phasevec( vector3d_addwithscalar(&mu, pow(distance_factor, 3), &muprime); /* parallax, eq. (1.5.27) */ - result->parallax = distance_factor*parallax; + result->parallax = distance_factor * parallax; /* zeta/rv, eq. (1.5.29); go back from rad to mas, too */ result->rv = (zeta0 + (mu0abs * mu0abs + zeta0 * zeta0) * delta_t) * distance_factor * distance_factor @@ -128,46 +147,64 @@ static void propagate_phasevec( pmlat, pmlong (in rad/yr), rv (in km/s). */ Datum -epoch_prop(PG_FUNCTION_ARGS) { - double delta_t; - phasevec input, output; - ArrayType *result; - Datum retvals[6]; - - if (PG_ARGISNULL(0)) { +epoch_prop(PG_FUNCTION_ARGS) +{ + double delta_t; + phasevec input, + output; + ArrayType *result; + Datum retvals[6]; + + if (PG_ARGISNULL(0)) + { ereport(ERROR, - (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("NULL position not supported in epoch propagation"))); } - memcpy(&(input.pos), (void*)PG_GETARG_POINTER(0), sizeof(SPoint)); - if (PG_ARGISNULL(1)) { + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("NULL position not supported in epoch propagation"))); + } + memcpy(&(input.pos), (void *) PG_GETARG_POINTER(0), sizeof(SPoint)); + if (PG_ARGISNULL(1)) + { input.parallax = 0; - } else { + } + else + { input.parallax = PG_GETARG_FLOAT8(1); } input.parallax_valid = fabs(input.parallax) > PX_MIN; - - if (PG_ARGISNULL(2)) { + + if (PG_ARGISNULL(2)) + { input.pm[0] = 0; - } else { + } + else + { input.pm[0] = PG_GETARG_FLOAT8(2); } - if (PG_ARGISNULL(3)) { + if (PG_ARGISNULL(3)) + { input.pm[1] = 0; - } else { + } + else + { input.pm[1] = PG_GETARG_FLOAT8(3); } - if (PG_ARGISNULL(4)) { + if (PG_ARGISNULL(4)) + { input.rv = 0; - } else { + } + else + { input.rv = PG_GETARG_FLOAT8(4); } - if (PG_ARGISNULL(5)) { + if (PG_ARGISNULL(5)) + { ereport(ERROR, - (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("NULL delta t not supported in epoch propagation"))); } + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("NULL delta t not supported in epoch propagation"))); + } delta_t = PG_GETARG_FLOAT8(5); propagate_phasevec(&input, delta_t, &output); @@ -181,23 +218,24 @@ epoch_prop(PG_FUNCTION_ARGS) { retvals[5] = Float8GetDatum(output.rv); { - bool isnull[6] = {0, 0, 0, 0, 0, 0}; - int lower_bounds[1] = {1}; - int dims[1] = {6}; + bool isnull[6] = {0, 0, 0, 0, 0, 0}; + int lower_bounds[1] = {1}; + int dims[1] = {6}; #ifdef USE_FLOAT8_BYVAL - bool embyval = true; + bool embyval = true; #else - bool embyval = false; + bool embyval = false; #endif - if (! output.parallax_valid) { + if (!output.parallax_valid) + { /* invalidate parallax and rv */ isnull[2] = 1; isnull[5] = 1; } result = construct_md_array(retvals, isnull, 1, dims, lower_bounds, - FLOAT8OID, sizeof(float8), embyval, 'd'); + FLOAT8OID, sizeof(float8), embyval, 'd'); } PG_RETURN_ARRAYTYPE_P(result); } diff --git a/src/epochprop.h b/src/epochprop.h index 9e1b87e..7f0bc39 100644 --- a/src/epochprop.h +++ b/src/epochprop.h @@ -3,24 +3,26 @@ #include -Datum epoch_prop(PG_FUNCTION_ARGS); - - -/* a cartesian point; this is like geo_decl's point, but you can't -have both geo_decls and pg_sphere right now (both define a type Point, -not to mention they have different ideas on EPSILON */ -typedef struct s_cpoint { - double x, y; +Datum epoch_prop(PG_FUNCTION_ARGS); + + +/* + * a cartesian point; this is like geo_decl's point, but you can't + * have both geo_decls and pg_sphere right now (both define a type Point, + * not to mention they have different ideas on EPSILON. + */ +typedef struct s_cpoint +{ + double x, + y; } CPoint; -typedef struct s_phasevec { - SPoint pos; /* Position as an SPoint */ - double pm[2]; /* Proper motion long/lat in rad/year, - PM in longitude has cos(lat) applied */ - double parallax; /* in rad */ - double rv; /* radial velocity in km/s */ - int parallax_valid; /* 1 if the parallax really is a NULL */ +typedef struct s_phasevec +{ + SPoint pos; /* Position as an SPoint */ + double pm[2]; /* Proper motion long/lat in rad/year, PM in + * longitude has cos(lat) applied */ + double parallax; /* in rad */ + double rv; /* radial velocity in km/s */ + int parallax_valid; /* 1 if the parallax really is a NULL */ } phasevec; - - - diff --git a/src/euler.c b/src/euler.c index a45f7b3..815d21d 100644 --- a/src/euler.c +++ b/src/euler.c @@ -108,9 +108,8 @@ spheretrans_from_float8_and_type(PG_FUNCTION_ARGS) d[0] = PG_GETARG_DATUM(0); d[1] = PG_GETARG_DATUM(1); d[2] = PG_GETARG_DATUM(2); - se = (SEuler *) DatumGetPointer( - DirectFunctionCall3(spheretrans_from_float8, - d[0], d[1], d[2])); + se = (SEuler *) DatumGetPointer(DirectFunctionCall3(spheretrans_from_float8, + d[0], d[1], d[2])); for (i = 0; i < 3; i++) { @@ -165,7 +164,8 @@ seuler_set_zxz(SEuler *se) bool strans_eq(const SEuler *e1, const SEuler *e2) { - SPoint in[2], p[4]; + SPoint in[2], + p[4]; in[0].lng = 0.0; in[0].lat = 0.0; @@ -210,6 +210,7 @@ Datum spheretrans_theta(PG_FUNCTION_ARGS) { SEuler *se = (SEuler *) PG_GETARG_POINTER(0); + PG_RETURN_FLOAT8(se->theta); } @@ -267,8 +268,8 @@ spheretrans_type(PG_FUNCTION_ARGS) void spheretrans_inv(SEuler *se) { - float8 lng[3]; - const unsigned char c = se->phi_a; + float8 lng[3]; + const unsigned char c = se->phi_a; lng[2] = -se->phi; lng[1] = -se->theta; @@ -298,7 +299,7 @@ strans_zxz(SEuler *ret, const SEuler *se) } else { - SEuler tmp; + SEuler tmp; tmp.psi = 0.0; tmp.theta = 0.0; @@ -339,7 +340,7 @@ spheretrans_invert(PG_FUNCTION_ARGS) void seuler_trans_zxz(SEuler *out, const SEuler *in, const SEuler *se) { - SPoint sp[4]; + SPoint sp[4]; sp[0].lng = 0.0; sp[0].lat = 0.0; @@ -380,7 +381,8 @@ spheretrans_trans_inv(PG_FUNCTION_ARGS) void euler_spoint_trans(SPoint *out, const SPoint *in, const SEuler *se) { - Vector3D v, o; + Vector3D v, + o; spoint_vector3d(&v, in); euler_vector_trans(&o, &v, se); @@ -425,7 +427,9 @@ spherevector_to_euler_inv(SEuler *se, const SPoint *spb, const SPoint *spe) } else { - Vector3D vbeg, vend, vtmp; + Vector3D vbeg, + vend, + vtmp; SPoint spt[2]; SEuler set; @@ -448,7 +452,7 @@ spherevector_to_euler_inv(SEuler *se, const SPoint *spb, const SPoint *spe) bool spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe) { - bool ret; + bool ret; ret = spherevector_to_euler_inv(se, spb, spe); if (ret) @@ -461,10 +465,13 @@ spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe) void euler_vector_trans(Vector3D *out, const Vector3D *in, const SEuler *se) { - int i; - unsigned char t; - const double *a; - double u[3], vr[3], sa, ca; + int i; + unsigned char t; + const double *a; + double u[3], + vr[3], + sa, + ca; t = 0; a = NULL; diff --git a/src/euler.h b/src/euler.h index 35e3a2c..21fa193 100644 --- a/src/euler.h +++ b/src/euler.h @@ -12,12 +12,12 @@ */ typedef struct { - unsigned char phi_a:2, /* first axis */ - theta_a:2, /* second axis */ - psi_a:2; /* third axis */ - float8 phi, /* first rotation angle */ - theta, /* second rotation angle */ - psi; /* third rotation angle */ + unsigned char phi_a:2, /* first axis */ + theta_a:2, /* second axis */ + psi_a:2; /* third axis */ + float8 phi, /* first rotation angle */ + theta, /* second rotation angle */ + psi; /* third rotation angle */ } SEuler; @@ -25,137 +25,137 @@ typedef struct * Transforms a spherical point and returns the pointer to a transformed spherical * point. */ -void euler_spoint_trans(SPoint *out, const SPoint *in, const SEuler *se); +void euler_spoint_trans(SPoint *out, const SPoint *in, const SEuler *se); /* * Transforms a spherical vector from 'spb' to 'spe' into an Euler transformation. * Returns true if the transformation was successful. */ -bool spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe); +bool spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe); /* * Sets the axes of transformation to ZXZ. */ -void seuler_set_zxz(SEuler *se); +void seuler_set_zxz(SEuler *se); /* * Checks equality of two transformations. */ -bool strans_eq(const SEuler *e1, const SEuler *e2); +bool strans_eq(const SEuler *e1, const SEuler *e2); /* * Transforms a vector using an Euler transformation. Returns the pointer to * the result vector. */ -void euler_vector_trans(Vector3D *out, const Vector3D *in, const SEuler *se); +void euler_vector_trans(Vector3D *out, const Vector3D *in, const SEuler *se); /* * Inverts an Euler transformation. Returns the pointer to the * inverted transformation. */ -void spheretrans_inverse(SEuler *se_out, const SEuler *se_in); +void spheretrans_inverse(SEuler *se_out, const SEuler *se_in); /* * Inverts an Euler transformation replacing the original Euler transformation. * Returns the pointer to the inverted transformation. */ -void spheretrans_inv(SEuler *se); +void spheretrans_inv(SEuler *se); /* * Converts an Euler transformation to a ZXZ-axis transformation. Returns * the pointer to the converted transformation. */ -void strans_zxz(SEuler *ret, const SEuler *se); +void strans_zxz(SEuler *ret, const SEuler *se); /* * Transforms an Euler transformation 'in' into 'out' using 'se'. The result * is always a ZXZ-axis transformation. Returns the pointer to the transformed * transformation. */ -void seuler_trans_zxz(SEuler *out, const SEuler *in, const SEuler *se); +void seuler_trans_zxz(SEuler *out, const SEuler *in, const SEuler *se); /* * Input of an Euler transformation. */ -Datum spheretrans_in(PG_FUNCTION_ARGS); +Datum spheretrans_in(PG_FUNCTION_ARGS); /* * Input of an Euler transformation with axis Z,X,Z from three angles * (phi, theta, psi) in radians. */ -Datum spheretrans_from_float8(PG_FUNCTION_ARGS); +Datum spheretrans_from_float8(PG_FUNCTION_ARGS); /* * Returns the first angle of an Euler transformation in radians. */ -Datum spheretrans_phi(PG_FUNCTION_ARGS); +Datum spheretrans_phi(PG_FUNCTION_ARGS); /* * Returns the second angle of an Euler transformation in radians. */ -Datum spheretrans_theta(PG_FUNCTION_ARGS); +Datum spheretrans_theta(PG_FUNCTION_ARGS); /* * Returns the third angle of an Euler transformation in radians. */ -Datum spheretrans_psi(PG_FUNCTION_ARGS); +Datum spheretrans_psi(PG_FUNCTION_ARGS); /* * Returns the axis of an Euler transformation as three letter code. */ -Datum spheretrans_type(PG_FUNCTION_ARGS); +Datum spheretrans_type(PG_FUNCTION_ARGS); /* * Returns the Euler transformation (does nothing). This function is needed * for +strans operator. */ -Datum spheretrans(PG_FUNCTION_ARGS); +Datum spheretrans(PG_FUNCTION_ARGS); /* * Returns the inverse Euler transformation. */ -Datum spheretrans_invert(PG_FUNCTION_ARGS); +Datum spheretrans_invert(PG_FUNCTION_ARGS); /* * Convert an Euler transformation to a ZXZ-axis transformation. */ -Datum spheretrans_zxz(PG_FUNCTION_ARGS); +Datum spheretrans_zxz(PG_FUNCTION_ARGS); /* * This function creates an Euler transformation from 3 angle values in * radians and three letter code used for axes. A letter can be X, Y or Z * (case-insensitive). */ -Datum spheretrans_from_float8_and_type(PG_FUNCTION_ARGS); +Datum spheretrans_from_float8_and_type(PG_FUNCTION_ARGS); /* * Checks equality of two Euler transformations. */ -Datum spheretrans_equal(PG_FUNCTION_ARGS); +Datum spheretrans_equal(PG_FUNCTION_ARGS); /* * Checks inequality of two Euler transformations. */ -Datum spheretrans_not_equal(PG_FUNCTION_ARGS); +Datum spheretrans_not_equal(PG_FUNCTION_ARGS); /* * Transforms an Euler transformation. */ -Datum spheretrans_trans(PG_FUNCTION_ARGS); +Datum spheretrans_trans(PG_FUNCTION_ARGS); /* * Transforms inverse an Euler transformations. */ -Datum spheretrans_trans_inv(PG_FUNCTION_ARGS); +Datum spheretrans_trans_inv(PG_FUNCTION_ARGS); /* * Transforms a spherical point. */ -Datum spheretrans_point(PG_FUNCTION_ARGS); +Datum spheretrans_point(PG_FUNCTION_ARGS); /* * Perform inverse transformation of a spherical point. */ -Datum spheretrans_point_inverse(PG_FUNCTION_ARGS); +Datum spheretrans_point_inverse(PG_FUNCTION_ARGS); #endif diff --git a/src/gist.c b/src/gist.c index b3223a5..8525e9b 100644 --- a/src/gist.c +++ b/src/gist.c @@ -96,9 +96,9 @@ spherekey_in(PG_FUNCTION_ARGS) Datum spherekey_out(PG_FUNCTION_ARGS) { - const float8 ks = (float8) MAXCVALUE; - int32 *k = (int32 *) PG_GETARG_POINTER(0); - char *buffer = (char *) palloc(1024); + const float8 ks = (float8) MAXCVALUE; + int32 *k = (int32 *) PG_GETARG_POINTER(0); + char *buffer = (char *) palloc(1024); sprintf(buffer, "(%.9f,%.9f,%.9f),(%.9f,%.9f,%.9f)", k[0] / ks, k[1] / ks, k[2] / ks, @@ -111,8 +111,8 @@ spherekey_out(PG_FUNCTION_ARGS) static bool get_sizes(GiSTSPointKey *k, float8 sizes[3]) { - int i; - const float8 ks = (float8) MAXCVALUE; + int i; + const float8 ks = (float8) MAXCVALUE; if (IS_LEAF(k)) return false; @@ -172,9 +172,9 @@ pointkey_in(PG_FUNCTION_ARGS) Datum pointkey_out(PG_FUNCTION_ARGS) { - const float8 ks = (float8) MAXCVALUE; - GiSTSPointKey *k = (GiSTSPointKey *) PG_GETARG_POINTER(0); - char *buffer = (char *) palloc(1024); + const float8 ks = (float8) MAXCVALUE; + GiSTSPointKey *k = (GiSTSPointKey *) PG_GETARG_POINTER(0); + char *buffer = (char *) palloc(1024); if (IS_LEAF(k)) { @@ -182,9 +182,9 @@ pointkey_out(PG_FUNCTION_ARGS) } else { - sprintf(buffer, "(%.9f,%.9f,%.9f),(%.9f,%.9f,%.9f)", + sprintf(buffer, "(%.9f,%.9f,%.9f),(%.9f,%.9f,%.9f)", k->k[0] / ks, k->k[1] / ks, k->k[2] / ks, - k->k[3] / ks, k->k[4] / ks, k->k[5] / ks); + k->k[3] / ks, k->k[4] / ks, k->k[5] / ks); } PG_RETURN_CSTRING(buffer); @@ -294,12 +294,12 @@ g_spoint3_compress(PG_FUNCTION_ARGS) key->lat = p->lat; key->lng = p->lng; gistentryinit(*retval, PointerGetDatum(key), entry->rel, - entry->page, entry->offset, false); + entry->page, entry->offset, false); } else { gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, - entry->offset, false); + entry->offset, false); } } else @@ -312,10 +312,11 @@ g_spoint3_compress(PG_FUNCTION_ARGS) Datum g_spherekey_union(PG_FUNCTION_ARGS) { - GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); - int *sizep = (int *) PG_GETARG_POINTER(1); - int numranges, i; - int32 *ret = (int32 *) palloc(KEYSIZE); + GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); + int *sizep = (int *) PG_GETARG_POINTER(1); + int numranges, + i; + int32 *ret = (int32 *) palloc(KEYSIZE); numranges = entryvec->n; memcpy((void *) ret, @@ -334,10 +335,11 @@ g_spherekey_union(PG_FUNCTION_ARGS) Datum g_spoint3_union(PG_FUNCTION_ARGS) { - GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); - int *sizep = (int *) PG_GETARG_POINTER(1); - int numranges, i; - GiSTSPointKey *ret; + GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); + int *sizep = (int *) PG_GETARG_POINTER(1); + int numranges, + i; + GiSTSPointKey *ret; ALLOC_INTERNAL_KEY(ret); numranges = entryvec->n; @@ -402,9 +404,9 @@ g_spherekey_same(PG_FUNCTION_ARGS) Datum g_spoint3_same(PG_FUNCTION_ARGS) { - GiSTSPointKey *key1 = (GiSTSPointKey *) PG_GETARG_POINTER(0); - GiSTSPointKey *key2 = (GiSTSPointKey *) PG_GETARG_POINTER(1); - bool *result = (bool *) PG_GETARG_POINTER(2); + GiSTSPointKey *key1 = (GiSTSPointKey *) PG_GETARG_POINTER(0); + GiSTSPointKey *key2 = (GiSTSPointKey *) PG_GETARG_POINTER(1); + bool *result = (bool *) PG_GETARG_POINTER(2); *result = true; if (key1 && key2) @@ -510,7 +512,7 @@ g_spoint_consistent(PG_FUNCTION_ARGS) SCK_INTERLEAVE(SELLIPSE, sphereellipse_gen_key, 0); break; case 42: - SCK_INTERLEAVE(SBOX, spherebox_gen_key , 0); + SCK_INTERLEAVE(SBOX, spherebox_gen_key, 0); break; } @@ -702,9 +704,12 @@ g_spoint3_distance(PG_FUNCTION_ARGS) { Vector3D v; float8 sum = 0.0, - x_min, x_max, - y_min, y_max, - z_min, z_max; + x_min, + x_max, + y_min, + y_max, + z_min, + z_max; spoint_vector3d(&v, query); @@ -736,10 +741,10 @@ g_spoint3_distance(PG_FUNCTION_ARGS) Datum g_spoint3_fetch(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GiSTSPointKey *key = (GiSTSPointKey *) DatumGetPointer(entry->key); - GISTENTRY *retval; - SPoint *p; + GISTENTRY *retval; + SPoint *p; retval = palloc(sizeof(GISTENTRY)); p = palloc(sizeof(SPoint)); @@ -747,7 +752,7 @@ g_spoint3_fetch(PG_FUNCTION_ARGS) p->lat = key->lat; p->lng = key->lng; gistentryinit(*retval, PointerGetDatum(p), entry->rel, - entry->page, entry->offset, false); + entry->page, entry->offset, false); PG_RETURN_POINTER(retval); } @@ -1562,18 +1567,19 @@ typedef struct static void checkBox3D(Box3D *box) { - int i; - for (i = 0; i < 3; i++) - { - if (box->low.coord[i] < -MAXCVALUE || box->low.coord[i] > MAXCVALUE) - { - elog(ERROR, "Invalid key!"); - } - if (box->high.coord[i] < -MAXCVALUE || box->high.coord[i] > MAXCVALUE) - { - elog(ERROR, "Invalid key!"); - } - } + int i; + + for (i = 0; i < 3; i++) + { + if (box->low.coord[i] < -MAXCVALUE || box->low.coord[i] > MAXCVALUE) + { + elog(ERROR, "Invalid key!"); + } + if (box->high.coord[i] < -MAXCVALUE || box->high.coord[i] > MAXCVALUE) + { + elog(ERROR, "Invalid key!"); + } + } } #endif @@ -1595,21 +1601,21 @@ static inline double sizeBox3D(Box3D *b) { return (double) ((int64) b->high.coord[0] - (int64) b->low.coord[0]) / MAXCVALUE - * (double) ((int64) b->high.coord[1] - (int64) b->low.coord[1]) / MAXCVALUE - * (double) ((int64) b->high.coord[2] - (int64) b->low.coord[2]) / MAXCVALUE; + * (double) ((int64) b->high.coord[1] - (int64) b->low.coord[1]) / MAXCVALUE + * (double) ((int64) b->high.coord[2] - (int64) b->low.coord[2]) / MAXCVALUE; } static inline double unionSizeBox3D(Box3D *a, Box3D *b) { return (double) ((int64) Max(a->high.coord[0], b->high.coord[0]) - - (int64) Min(a->low.coord[0], b->low.coord[0])) / MAXCVALUE + (int64) Min(a->low.coord[0], b->low.coord[0])) / MAXCVALUE - * (double) ((int64) Max(a->high.coord[1], b->high.coord[1]) - - (int64) Min(a->low.coord[1], b->low.coord[1])) / MAXCVALUE + * (double) ((int64) Max(a->high.coord[1], b->high.coord[1]) - + (int64) Min(a->low.coord[1], b->low.coord[1])) / MAXCVALUE - * (double) ((int64) Max(a->high.coord[2], b->high.coord[2]) - - (int64) Min(a->low.coord[2], b->low.coord[2])) / MAXCVALUE; + * (double) ((int64) Max(a->high.coord[2], b->high.coord[2]) - + (int64) Min(a->low.coord[2], b->low.coord[2])) / MAXCVALUE; } /* @@ -1619,10 +1625,10 @@ unionSizeBox3D(Box3D *a, Box3D *b) static void fallbackSplit(Box3D *boxes, OffsetNumber maxoff, GIST_SPLITVEC *v) { - OffsetNumber i; - Box3D *unionL = NULL, - *unionR = NULL; - int nbytes; + OffsetNumber i; + Box3D *unionL = NULL, + *unionR = NULL; + int nbytes; nbytes = (maxoff + 2) * sizeof(OffsetNumber); v->spl_left = (OffsetNumber *) palloc(nbytes); @@ -1631,7 +1637,7 @@ fallbackSplit(Box3D *boxes, OffsetNumber maxoff, GIST_SPLITVEC *v) for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { - Box3D *cur = &boxes[i]; + Box3D *cur = &boxes[i]; if (i <= (maxoff - FirstOffsetNumber + 1) / 2) { @@ -1815,7 +1821,7 @@ g_box_consider_split(ConsiderSplitContext *context, int dimNum, * or less range with same overlap. */ range = (float8) context->boundingBox.high.coord[dimNum] - - (float8) context->boundingBox.low.coord[dimNum]; + (float8) context->boundingBox.low.coord[dimNum]; overlap = ((float8) leftUpper - (float8) rightLower) / range; /* If there is no previous selection, select this */ @@ -2203,7 +2209,7 @@ do_picksplit(Box3D *boxes, OffsetNumber maxoff, GIST_SPLITVEC *v) { box = &boxes[i]; commonEntries[i].delta = fabs((unionSizeBox3D(leftBox, box) - leftBoxSize) - - (unionSizeBox3D(rightBox, box) - rightBoxSize)); + (unionSizeBox3D(rightBox, box) - rightBoxSize)); } /* @@ -2240,7 +2246,7 @@ do_picksplit(Box3D *boxes, OffsetNumber maxoff, GIST_SPLITVEC *v) { /* Otherwise select the group by minimal penalty */ if (unionSizeBox3D(leftBox, box) - leftBoxSize < - unionSizeBox3D(rightBox, box) - rightBoxSize) + unionSizeBox3D(rightBox, box) - rightBoxSize) { PLACE_LEFT(box, commonEntries[i].index); /* checkBox3D(leftBox); */ @@ -2346,17 +2352,17 @@ g_spherekey_penalty(PG_FUNCTION_ARGS) Box3D *n = (Box3D *) DatumGetPointer(newentry->key); *result = (float) (((uint64) (Max(o->high.coord[0], n->high.coord[0]) - - Min(o->low.coord[0], n->low.coord[0])) >> 10) + Min(o->low.coord[0], n->low.coord[0])) >> 10) * ((uint64) (Max(o->high.coord[1], n->high.coord[1]) - - Min(o->low.coord[1], n->low.coord[1])) >> 10) + Min(o->low.coord[1], n->low.coord[1])) >> 10) * ((uint64) (Max(o->high.coord[2], n->high.coord[2]) - - Min(o->low.coord[2], n->low.coord[2])) >> 10) + Min(o->low.coord[2], n->low.coord[2])) >> 10) - - ((uint64) (o->high.coord[0] - o->low.coord[0]) >> 10) - * ((uint64) (o->high.coord[1] - o->low.coord[1]) >> 10) - * ((uint64) (o->high.coord[2] - o->low.coord[2]) >> 10)); + - ((uint64) (o->high.coord[0] - o->low.coord[0]) >> 10) + * ((uint64) (o->high.coord[1] - o->low.coord[1]) >> 10) + * ((uint64) (o->high.coord[2] - o->low.coord[2]) >> 10)); PG_RETURN_POINTER(result); } else @@ -2377,8 +2383,10 @@ g_spoint3_penalty(PG_FUNCTION_ARGS) float *result = (float *) PG_GETARG_POINTER(2); GiSTSPointKey *origkey = (GiSTSPointKey *) DatumGetPointer(origentry->key); GiSTSPointKey *newkey = (GiSTSPointKey *) DatumGetPointer(newentry->key); - Box3D *o, *n; - int32 k[6], ok[6]; + Box3D *o, + *n; + int32 k[6], + ok[6]; if (IS_LEAF(origkey)) { @@ -2421,13 +2429,13 @@ g_spoint3_penalty(PG_FUNCTION_ARGS) } *result = ((float) ((int64) Max(o->high.coord[0], n->high.coord[0]) - - (int64) Min(o->low.coord[0], n->low.coord[0]))) - * ((float) ((int64) Max(o->high.coord[1], n->high.coord[1]) - - (int64) Min(o->low.coord[1], n->low.coord[1]))) - * ((float) ((int64) Max(o->high.coord[2], n->high.coord[2]) - - (int64) Min(o->low.coord[2], n->low.coord[2]))) - - ((float) ((int64) o->high.coord[0] - (int64) o->low.coord[0])) - * ((float) ((int64) o->high.coord[1] - (int64) o->low.coord[1])) - * ((float) ((int64) o->high.coord[2] - (int64) o->low.coord[2])); + - (int64) Min(o->low.coord[0], n->low.coord[0]))) + * ((float) ((int64) Max(o->high.coord[1], n->high.coord[1]) + - (int64) Min(o->low.coord[1], n->low.coord[1]))) + * ((float) ((int64) Max(o->high.coord[2], n->high.coord[2]) + - (int64) Min(o->low.coord[2], n->low.coord[2]))) + - ((float) ((int64) o->high.coord[0] - (int64) o->low.coord[0])) + * ((float) ((int64) o->high.coord[1] - (int64) o->low.coord[1])) + * ((float) ((int64) o->high.coord[2] - (int64) o->low.coord[2])); PG_RETURN_POINTER(result); } diff --git a/src/gist.h b/src/gist.h index 6dac2a4..29e2beb 100644 --- a/src/gist.h +++ b/src/gist.h @@ -11,150 +11,150 @@ typedef unsigned char uchar; /* PGS_KEY_REL Key relationships */ -#define SCKEY_DISJ 0 /* two keys are disjunct */ -#define SCKEY_OVERLAP 1 /* two keys are overlapping */ -#define SCKEY_IN 2 /* first key contains second key */ -#define SCKEY_SAME 3 /* keys are equal */ +#define SCKEY_DISJ 0 /* two keys are disjunct */ +#define SCKEY_OVERLAP 1 /* two keys are overlapping */ +#define SCKEY_IN 2 /* first key contains second key */ +#define SCKEY_SAME 3 /* keys are equal */ -uchar spherekey_interleave(const int32 *k1, const int32 *k2); +uchar spherekey_interleave(const int32 *k1, const int32 *k2); /* * For given "query" of "pgstype" of PGS_DATA_TYPES type, puts key of cached * query into "key" pointer. Returns true when given query is equal to * current query. */ -bool gq_cache_get_value(unsigned pgstype, const void *query, int32 **key); +bool gq_cache_get_value(unsigned pgstype, const void *query, int32 **key); /* * Copy current query, type and its key value to cache. */ -void gq_cache_set_value(unsigned pgstype, const void *query, const int32 *key); +void gq_cache_set_value(unsigned pgstype, const void *query, const int32 *key); /* * Input function of key value. Just a dummy. But PostgreSQL need this * function to create a data type. */ -Datum spherekey_in(PG_FUNCTION_ARGS); +Datum spherekey_in(PG_FUNCTION_ARGS); /* * Output function of key value. Just a dummy. But PostgreSQL need this * function to create a data type. */ -Datum spherekey_out(PG_FUNCTION_ARGS); +Datum spherekey_out(PG_FUNCTION_ARGS); /* * GIST's decompress method. This function does nothing. */ -Datum g_spherekey_decompress(PG_FUNCTION_ARGS); +Datum g_spherekey_decompress(PG_FUNCTION_ARGS); /* * GIST's compress method for circle. Creates the key value from a spherical * circle. */ -Datum g_scircle_compress(PG_FUNCTION_ARGS); +Datum g_scircle_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for point. Creates the key value from a spherical point. */ -Datum g_spoint_compress(PG_FUNCTION_ARGS); +Datum g_spoint_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for line. Creates the key value from a spherical line. */ -Datum g_sline_compress(PG_FUNCTION_ARGS); +Datum g_sline_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for path. Creates the key value from a spherical path. */ -Datum g_spath_compress(PG_FUNCTION_ARGS); +Datum g_spath_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for polygon. Creates the key value from a spherical * polygon. */ -Datum g_spoly_compress(PG_FUNCTION_ARGS); +Datum g_spoly_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for ellipse. Creates the key value from a spherical * ellipse. */ -Datum g_sellipse_compress(PG_FUNCTION_ARGS); +Datum g_sellipse_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for box. Creates the key value from a spherical box. */ -Datum g_sbox_compress(PG_FUNCTION_ARGS); +Datum g_sbox_compress(PG_FUNCTION_ARGS); /* * The GiST Union method for boxes. Returns the minimal bounding box that * encloses all the entries in entryvec. */ -Datum g_spherekey_union(PG_FUNCTION_ARGS); +Datum g_spherekey_union(PG_FUNCTION_ARGS); /* * GIST's equality method. */ -Datum g_spherekey_same(PG_FUNCTION_ARGS); +Datum g_spherekey_same(PG_FUNCTION_ARGS); /* * GIST's consistent method for a point. */ -Datum g_spoint_consistent(PG_FUNCTION_ARGS); +Datum g_spoint_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a circle. */ -Datum g_scircle_consistent(PG_FUNCTION_ARGS); +Datum g_scircle_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a line. */ -Datum g_sline_consistent(PG_FUNCTION_ARGS); +Datum g_sline_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a path. */ -Datum g_spath_consistent(PG_FUNCTION_ARGS); +Datum g_spath_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a polygon. */ -Datum g_spoly_consistent(PG_FUNCTION_ARGS); +Datum g_spoly_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for an ellipse. */ -Datum g_sellipse_consistent(PG_FUNCTION_ARGS); +Datum g_sellipse_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a box. */ -Datum g_sbox_consistent(PG_FUNCTION_ARGS); +Datum g_sbox_consistent(PG_FUNCTION_ARGS); /* * GIST's penalty method. */ -Datum g_spherekey_penalty(PG_FUNCTION_ARGS); +Datum g_spherekey_penalty(PG_FUNCTION_ARGS); /* * GIST's picksplit method. This method is using the double sorting node * splitting algorithm for R-Trees. See "A new double sorting-based node * splitting algorithm for R-tree", A. Korotkov. */ -Datum g_spherekey_picksplit(PG_FUNCTION_ARGS); - -Datum pointkey_in(PG_FUNCTION_ARGS); -Datum pointkey_out(PG_FUNCTION_ARGS); -Datum pointkey_volume(PG_FUNCTION_ARGS); -Datum pointkey_area(PG_FUNCTION_ARGS); -Datum pointkey_perimeter(PG_FUNCTION_ARGS); -Datum g_spoint3_compress(PG_FUNCTION_ARGS); -Datum g_spoint3_union(PG_FUNCTION_ARGS); -Datum g_spoint3_same(PG_FUNCTION_ARGS); -Datum g_spoint3_consistent(PG_FUNCTION_ARGS); -Datum g_spoint3_penalty(PG_FUNCTION_ARGS); -Datum g_spoint3_picksplit(PG_FUNCTION_ARGS); -Datum g_spoint3_distance(PG_FUNCTION_ARGS); -Datum g_spoint3_fetch(PG_FUNCTION_ARGS); +Datum g_spherekey_picksplit(PG_FUNCTION_ARGS); + +Datum pointkey_in(PG_FUNCTION_ARGS); +Datum pointkey_out(PG_FUNCTION_ARGS); +Datum pointkey_volume(PG_FUNCTION_ARGS); +Datum pointkey_area(PG_FUNCTION_ARGS); +Datum pointkey_perimeter(PG_FUNCTION_ARGS); +Datum g_spoint3_compress(PG_FUNCTION_ARGS); +Datum g_spoint3_union(PG_FUNCTION_ARGS); +Datum g_spoint3_same(PG_FUNCTION_ARGS); +Datum g_spoint3_consistent(PG_FUNCTION_ARGS); +Datum g_spoint3_penalty(PG_FUNCTION_ARGS); +Datum g_spoint3_picksplit(PG_FUNCTION_ARGS); +Datum g_spoint3_distance(PG_FUNCTION_ARGS); +Datum g_spoint3_fetch(PG_FUNCTION_ARGS); #endif diff --git a/src/gnomo.c b/src/gnomo.c index a13c8dc..83b7fa1 100644 --- a/src/gnomo.c +++ b/src/gnomo.c @@ -2,7 +2,7 @@ #include #include "gnomo.h" -#include "point.h" /* SPoint from pgsphere */ +#include "point.h" /* SPoint from pgsphere */ #include @@ -14,22 +14,23 @@ PG_FUNCTION_INFO_V1(gnomonic_inv); * * point gnomonic_proj(spoint spherical_point, spoint tangential_point) */ -Datum gnomonic_proj(PG_FUNCTION_ARGS) +Datum +gnomonic_proj(PG_FUNCTION_ARGS) { - Point* g = (Point*) palloc(sizeof(Point)); - SPoint* p = (SPoint*) PG_GETARG_POINTER(0); - SPoint* t = (SPoint*) PG_GETARG_POINTER(1); + Point *g = (Point *) palloc(sizeof(Point)); + SPoint *p = (SPoint *) PG_GETARG_POINTER(0); + SPoint *t = (SPoint *) PG_GETARG_POINTER(1); - double delta_lng = p->lng - t->lng; - double sin_lat = sin(p->lat); - double cos_lat = cos(p->lat); - double sin_lat_t = sin(t->lat); - double cos_lat_t = cos(t->lat); - double sin_delta = sin(delta_lng); - double cos_delta = cos(delta_lng); + double delta_lng = p->lng - t->lng; + double sin_lat = sin(p->lat); + double cos_lat = cos(p->lat); + double sin_lat_t = sin(t->lat); + double cos_lat_t = cos(t->lat); + double sin_delta = sin(delta_lng); + double cos_delta = cos(delta_lng); - double cos_lat__cos_delta = cos_lat * cos_delta; - double cos_dist = sin_lat_t * sin_lat + cos_lat_t * cos_lat__cos_delta; + double cos_lat__cos_delta = cos_lat * cos_delta; + double cos_dist = sin_lat_t * sin_lat + cos_lat_t * cos_lat__cos_delta; g->x = cos_lat * sin_delta / cos_dist; g->y = (cos_lat_t * sin_lat - sin_lat_t * cos_lat__cos_delta) / cos_dist; @@ -47,22 +48,23 @@ Datum gnomonic_proj(PG_FUNCTION_ARGS) * * spoint gnomonic_inv(point plane_point, spoint tangential_point) */ -Datum gnomonic_inv(PG_FUNCTION_ARGS) +Datum +gnomonic_inv(PG_FUNCTION_ARGS) { - SPoint* p = (SPoint*) palloc(sizeof(SPoint)); - Point* g = (Point*) PG_GETARG_POINTER(0); - SPoint* t = (SPoint*) PG_GETARG_POINTER(1); + SPoint *p = (SPoint *) palloc(sizeof(SPoint)); + Point *g = (Point *) PG_GETARG_POINTER(0); + SPoint *t = (SPoint *) PG_GETARG_POINTER(1); - double rho_sq = g->x * g->x + g->y * g->y; - double rho = sqrt(rho_sq); - double cos_c = 1 / sqrt(1 + rho_sq); - double sin_c = 1 / sqrt(1 + 1 / rho_sq); - double cos_lat_t = cos(t->lat); - double sin_lat_t = sin(t->lat); + double rho_sq = g->x * g->x + g->y * g->y; + double rho = sqrt(rho_sq); + double cos_c = 1 / sqrt(1 + rho_sq); + double sin_c = 1 / sqrt(1 + 1 / rho_sq); + double cos_lat_t = cos(t->lat); + double sin_lat_t = sin(t->lat); p->lng = t->lng + atan2(g->x * sin_c, rho * cos_lat_t * cos_c - g->y * sin_lat_t * sin_c); - p->lat = asin(cos_c * sin_lat_t + g->y *sin_c * cos_lat_t / rho); + p->lat = asin(cos_c * sin_lat_t + g->y * sin_c * cos_lat_t / rho); PG_RETURN_POINTER(p); } diff --git a/src/gnomo.h b/src/gnomo.h index bae1d11..2e5799f 100644 --- a/src/gnomo.h +++ b/src/gnomo.h @@ -3,7 +3,7 @@ /* function prototypes for the direct and inverse gnomonic projections */ -Datum gnomonic_proj(PG_FUNCTION_ARGS); -Datum gnomonic_inv(PG_FUNCTION_ARGS); +Datum gnomonic_proj(PG_FUNCTION_ARGS); +Datum gnomonic_inv(PG_FUNCTION_ARGS); #endif diff --git a/src/healpix.c b/src/healpix.c index 0737d6f..5feeada 100644 --- a/src/healpix.c +++ b/src/healpix.c @@ -4,7 +4,7 @@ #include #include #include -#include "point.h" /* SPoint */ +#include "point.h" /* SPoint */ #include #include "pgs_util.h" @@ -21,13 +21,16 @@ PG_FUNCTION_INFO_V1(healpix_ring); PG_FUNCTION_INFO_V1(inv_healpix_nest); PG_FUNCTION_INFO_V1(inv_healpix_ring); -static int ilog2(hpint64 x) +static int +ilog2(hpint64 x) { - int log = 0; - unsigned w; + int log = 0; + unsigned w; + for (w = 32; w; w >>= 1) { - hpint64 y = x >> w; + hpint64 y = x >> w; + if (y) { log += w; @@ -43,23 +46,28 @@ order_invalid(int order) return (order < 0 || order > 29); } -static int nside_invalid(hpint64 nside) +static int +nside_invalid(hpint64 nside) { return (nside <= 0 || (nside - 1) & nside || order_invalid(ilog2(nside))); } -static hpint64 c_nside(int order) +static hpint64 +c_nside(int order) { - hpint64 one_bit = 1; + hpint64 one_bit = 1; + return one_bit << order; } -hpint64 c_npix(int order) +hpint64 +c_npix(int order) { return nside2npix(c_nside(order)); } -void check_order(int order) +void +check_order(int order) { if (order_invalid(order)) ereport(ERROR, @@ -67,7 +75,8 @@ void check_order(int order) errmsg("Healpix level out of valid range [0..29]"))); } -static void check_index(int order, hpint64 i) +static void +check_index(int order, hpint64 i) { check_order(order); if (i < 0 || i >= c_npix(order)) @@ -75,41 +84,46 @@ static void check_index(int order, hpint64 i) (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("Healpix index out of range"), errhint("Use nside2npix(order2nside(level)) to calculate" - " the respective limit\nfor Healpix indices.\n" - "Use healpix_convert(idx, from_level, to_level)" - " to move indices to another level."))); + " the respective limit\nfor Healpix indices.\n" + "Use healpix_convert(idx, from_level, to_level)" + " to move indices to another level."))); } -static void check_nside(hpint64 nside) +static void +check_nside(hpint64 nside) { if (nside_invalid(nside)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("nside value invalid"), errhint("Valid nside values are only" - " order2nside(level)," - " for level in [0..29]."))); + " order2nside(level)," + " for level in [0..29]."))); } -Datum pg_nest2ring(PG_FUNCTION_ARGS) +Datum +pg_nest2ring(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); - hpint64 nest = PG_GETARG_INT64(1); + int32 order = PG_GETARG_INT32(0); + hpint64 nest = PG_GETARG_INT64(1); + check_index(order, nest); PG_RETURN_INT64(nest2ring(c_nside(order), nest)); } -Datum pg_ring2nest(PG_FUNCTION_ARGS) +Datum +pg_ring2nest(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); - hpint64 ring = PG_GETARG_INT64(1); + int32 order = PG_GETARG_INT32(0); + hpint64 ring = PG_GETARG_INT64(1); + check_index(order, ring); PG_RETURN_INT64(ring2nest(c_nside(order), ring)); } hpint64 c_healpix_convert_nest(hpint64 idx, int32 from_order, - int32 to_order) + int32 to_order) { check_order(to_order); if (from_order > to_order) @@ -119,53 +133,65 @@ c_healpix_convert_nest(hpint64 idx, int32 from_order, return idx; } -Datum healpix_convert_nest(PG_FUNCTION_ARGS) +Datum +healpix_convert_nest(PG_FUNCTION_ARGS) { - int32 to_order = PG_GETARG_INT32(0); - int32 from_order = PG_GETARG_INT32(1); - hpint64 nest = PG_GETARG_INT64(2); + int32 to_order = PG_GETARG_INT32(0); + int32 from_order = PG_GETARG_INT32(1); + hpint64 nest = PG_GETARG_INT64(2); + check_index(from_order, nest); PG_RETURN_INT64(c_healpix_convert_nest(nest, from_order, to_order)); } -Datum healpix_convert_ring(PG_FUNCTION_ARGS) +Datum +healpix_convert_ring(PG_FUNCTION_ARGS) { - int32 to_order = PG_GETARG_INT32(0); - int32 from_order = PG_GETARG_INT32(1); - hpint64 ring = PG_GETARG_INT64(2); - hpint64 nest; + int32 to_order = PG_GETARG_INT32(0); + int32 from_order = PG_GETARG_INT32(1); + hpint64 ring = PG_GETARG_INT64(2); + hpint64 nest; + check_index(from_order, ring); - //nest = ring2nest(c_nside(from_order), ring); - //nest = c_healpix_convert_nest(nest, from_order, to_order); + /* nest = ring2nest(c_nside(from_order), ring); */ + /* nest = c_healpix_convert_nest(nest, from_order, to_order); */ nest = c_healpix_convert_nest(ring2nest(c_nside(from_order), ring), from_order, to_order); PG_RETURN_INT64(nest2ring(c_nside(to_order), nest)); } -Datum pg_nside2order(PG_FUNCTION_ARGS) +Datum +pg_nside2order(PG_FUNCTION_ARGS) { - hpint64 nside = PG_GETARG_INT64(0); + hpint64 nside = PG_GETARG_INT64(0); + check_nside(nside); PG_RETURN_INT32(ilog2(nside)); } -Datum pg_order2nside(PG_FUNCTION_ARGS) +Datum +pg_order2nside(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); + int32 order = PG_GETARG_INT32(0); + check_order(order); PG_RETURN_INT64(c_nside(order)); } -Datum pg_nside2npix(PG_FUNCTION_ARGS) +Datum +pg_nside2npix(PG_FUNCTION_ARGS) { - hpint64 nside = PG_GETARG_INT64(0); + hpint64 nside = PG_GETARG_INT64(0); + check_nside(nside); PG_RETURN_INT64(nside2npix(nside)); } -Datum pg_npix2nside(PG_FUNCTION_ARGS) +Datum +pg_npix2nside(PG_FUNCTION_ARGS) { - hpint64 npix = PG_GETARG_INT64(0); - hpint64 nside; + hpint64 npix = PG_GETARG_INT64(0); + hpint64 nside; + if (npix < 12) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), @@ -176,42 +202,50 @@ Datum pg_npix2nside(PG_FUNCTION_ARGS) (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("npix value invalid"), errhint("Valid npix values are only" - " nside2npix(order2nside(level))," - " for level in [0..29]."))); + " nside2npix(order2nside(level))," + " for level in [0..29]."))); PG_RETURN_INT64(nside); } -hpint64 healpix_nest_c(int32 order, SPoint* p) +hpint64 +healpix_nest_c(int32 order, SPoint *p) { - hpint64 i; - t_ang angle = { conv_theta(p->lat), p->lng }; + hpint64 i; + t_ang angle = {conv_theta(p->lat), p->lng}; + i = ang2nest(c_nside(order), angle); return i; } -Datum healpix_nest(PG_FUNCTION_ARGS) +Datum +healpix_nest(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); - SPoint* p = (SPoint*) PG_GETARG_POINTER(1); + int32 order = PG_GETARG_INT32(0); + SPoint *p = (SPoint *) PG_GETARG_POINTER(1); + check_order(order); PG_RETURN_INT64(healpix_nest_c(order, p)); } -Datum healpix_ring(PG_FUNCTION_ARGS) +Datum +healpix_ring(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); - SPoint* p = (SPoint*) PG_GETARG_POINTER(1); - t_ang angle = { conv_theta(p->lat), p->lng }; + int32 order = PG_GETARG_INT32(0); + SPoint *p = (SPoint *) PG_GETARG_POINTER(1); + t_ang angle = {conv_theta(p->lat), p->lng}; + check_order(order); PG_RETURN_INT64(ang2ring(c_nside(order), angle)); } -Datum inv_healpix_nest(PG_FUNCTION_ARGS) +Datum +inv_healpix_nest(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); - hpint64 i = PG_GETARG_INT64(1); - SPoint* p = (SPoint*) palloc(sizeof(SPoint)); - t_ang angle; + int32 order = PG_GETARG_INT32(0); + hpint64 i = PG_GETARG_INT64(1); + SPoint *p = (SPoint *) palloc(sizeof(SPoint)); + t_ang angle; + check_index(order, i); angle = nest2ang(c_nside(order), i); p->lat = conv_theta(angle.theta); @@ -219,12 +253,14 @@ Datum inv_healpix_nest(PG_FUNCTION_ARGS) PG_RETURN_POINTER(p); } -Datum inv_healpix_ring(PG_FUNCTION_ARGS) +Datum +inv_healpix_ring(PG_FUNCTION_ARGS) { - int32 order = PG_GETARG_INT32(0); - hpint64 i = PG_GETARG_INT64(1); - SPoint* p = (SPoint*) palloc(sizeof(SPoint)); - t_ang angle; + int32 order = PG_GETARG_INT32(0); + hpint64 i = PG_GETARG_INT64(1); + SPoint *p = (SPoint *) palloc(sizeof(SPoint)); + t_ang angle; + check_index(order, i); angle = ring2ang(c_nside(order), i); p->lat = conv_theta(angle.theta); diff --git a/src/key.c b/src/key.c index ad1ebf6..4c76f00 100644 --- a/src/key.c +++ b/src/key.c @@ -12,7 +12,7 @@ PG_MODULE_MAGIC; static void key_add_point(int32 *key, const SPoint *p) { - int32 k[6]; + int32 k[6]; spherepoint_gen_key(&k[0], p); spherekey_union_two(key, &k[0]); @@ -51,7 +51,7 @@ void spherepoint_gen_key(int32 *k, const SPoint *sp) { Vector3D v; - const int32 ks = MAXCVALUE; + const int32 ks = MAXCVALUE; spoint_vector3d(&v, sp); @@ -81,7 +81,7 @@ spherecircle_gen_key(int32 *k, const SCIRCLE *c) { double r, d; - const int32 ks = MAXCVALUE; + const int32 ks = MAXCVALUE; int i; Vector3D v[8]; Vector3D tv; @@ -186,7 +186,7 @@ sphereellipse_gen_key(int32 *k, const SELLIPSE *e) { double r[2], d; - const int32 ks = MAXCVALUE; + const int32 ks = MAXCVALUE; int i; Vector3D v[8]; Vector3D tv; @@ -286,7 +286,7 @@ sphereellipse_gen_key(int32 *k, const SELLIPSE *e) void sphereline_gen_key(int32 *k, const SLine *sl) { - const int32 ks = MAXCVALUE; + const int32 ks = MAXCVALUE; SPoint p[3]; sline_begin(&p[0], sl); @@ -294,7 +294,8 @@ sphereline_gen_key(int32 *k, const SLine *sl) if (FPzero(sl->length)) { - Vector3D vbeg, vend; + Vector3D vbeg, + vend; spoint_vector3d(&vbeg, &p[0]); spoint_vector3d(&vend, &p[1]); @@ -386,11 +387,11 @@ sphereline_gen_key(int32 *k, const SLine *sl) void spherepoly_gen_key(int32 *key, const SPOLY *sp) { - int32 i; - SLine l; - SPoint p; - int32 tk[6]; - bool start = true; + int32 i; + SLine l; + SPoint p; + int32 tk[6]; + bool start = true; for (i = 0; i < sp->npts; i++) { @@ -452,7 +453,7 @@ spherepath_gen_key(int32 *key, const SPATH *sp) int32 tk[6]; bool start = true; - for (i=0; i < sp->npts - 1; i++) + for (i = 0; i < sp->npts - 1; i++) { sline_from_points(&l, &sp->p[i], &sp->p[i + 1]); sphereline_gen_key(&tk[0], &l); @@ -476,8 +477,8 @@ spherepath_gen_key(int32 *key, const SPATH *sp) void spherebox_gen_key(int32 *key, const SBOX *box) { - SPoint p; - float8 d; + SPoint p; + float8 d; key[0] = key[1] = key[2] = MAXCVALUE; key[3] = key[4] = key[5] = -MAXCVALUE; diff --git a/src/key.h b/src/key.h index aa77ca9..7b946dd 100644 --- a/src/key.h +++ b/src/key.h @@ -20,30 +20,32 @@ typedef struct { - char vl_len_[4]; + char vl_len_[4]; union { - struct /* the compiler will probably insert 4 bytes of padding here */ + struct /* the compiler will probably insert 4 bytes + * of padding here */ { - float8 lat, - lng; + float8 lat, + lng; }; }; -} GiSTSPointKey_Leaf; +} GiSTSPointKey_Leaf; typedef struct { - char vl_len_[4]; + char vl_len_[4]; union { - struct /* the compiler will probably insert 4 bytes of padding here */ + struct /* the compiler will probably insert 4 bytes + * of padding here */ { - float8 lat, - lng; + float8 lat, + lng; }; struct { - int32 k[6]; + int32 k[6]; }; }; } GiSTSPointKey; @@ -63,128 +65,128 @@ typedef struct /* * Returns the union of two keys. Result is placed into 'kunion'. */ -void spherekey_union_two(int32 *kunion, const int32 *key); +void spherekey_union_two(int32 *kunion, const int32 *key); /* * Returns the intersection of two keys. Returns NULL if there is * no intersection. Result is placed into 'kinter'. */ -bool spherekey_inter_two(int32 *kinter, const int32 *key); +bool spherekey_inter_two(int32 *kinter, const int32 *key); /* * Generates the key of a spherical point and returns it. Result is placed * into 'k'. */ -void spherepoint_gen_key(int32 *k, const SPoint *sp); +void spherepoint_gen_key(int32 *k, const SPoint *sp); /* * Generates the circle's key and returns it. Result is placed into 'k'. */ -void spherecircle_gen_key(int32 *k, const SCIRCLE *c); +void spherecircle_gen_key(int32 *k, const SCIRCLE *c); /* * Generates the key of a spherical ellipse and returns it. Result is placed * into 'k'. */ -void sphereellipse_gen_key(int32 *k, const SELLIPSE *e); +void sphereellipse_gen_key(int32 *k, const SELLIPSE *e); /* * Generates the key of a spherical line and returns it. Result is placed * into 'k'. */ -void sphereline_gen_key(int32 *k, const SLine *sl); +void sphereline_gen_key(int32 *k, const SLine *sl); /* * Generates the key of a polygon and returns it. Result is placed into 'k'. */ -void spherepoly_gen_key(int32 *k, const SPOLY *sp); +void spherepoly_gen_key(int32 *k, const SPOLY *sp); /* * Generates the key of a path and returns it. Result is placed into 'k'. */ -void spherepath_gen_key(int32 *k, const SPATH *sp); +void spherepath_gen_key(int32 *k, const SPATH *sp); /* * Generates the key of a box and returns it. Result is placed into 'k'. */ -void spherebox_gen_key(int32 *key, const SBOX *box); +void spherebox_gen_key(int32 *key, const SBOX *box); /* * Returns true if the first key is less than the second key. */ -Datum spherekey_lt(PG_FUNCTION_ARGS); +Datum spherekey_lt(PG_FUNCTION_ARGS); /* * Returns true if the first key is less or equal than the second key. */ -Datum spherekey_le(PG_FUNCTION_ARGS); +Datum spherekey_le(PG_FUNCTION_ARGS); /* * Returns true if two keys are equal. */ -Datum spherekey_eq(PG_FUNCTION_ARGS); +Datum spherekey_eq(PG_FUNCTION_ARGS); /* * Returns true if two keys are not equal. */ -Datum spherekey_eq_neg(PG_FUNCTION_ARGS); +Datum spherekey_eq_neg(PG_FUNCTION_ARGS); /* * Returns true if the first key is greater or equal than the second key. */ -Datum spherekey_ge(PG_FUNCTION_ARGS); +Datum spherekey_ge(PG_FUNCTION_ARGS); /* * Returns true if the first key is greater than the second key. */ -Datum spherekey_gt(PG_FUNCTION_ARGS); +Datum spherekey_gt(PG_FUNCTION_ARGS); /* * Returns relationship between the two keys. * Calls skey_cmp(const int32 *, const int32 *) for two keys. */ -Datum spherekey_cmp(PG_FUNCTION_ARGS); +Datum spherekey_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical points. * Calls skey_cmp(const int32 *, const int32 *) for two points. */ -Datum spherepoint_cmp(PG_FUNCTION_ARGS); +Datum spherepoint_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical circles. * Calls skey_cmp(const int32 *, const int32 *) for two circles. */ -Datum spherecircle_cmp(PG_FUNCTION_ARGS); +Datum spherecircle_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical ellipses. * Calls skey_cmp(const int32 *, const int32 *) for two ellipses. */ -Datum sphereellipse_cmp(PG_FUNCTION_ARGS); +Datum sphereellipse_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical lines. * Calls skey_cmp(const int32 *, const int32 *) for two lines. */ -Datum sphereline_cmp(PG_FUNCTION_ARGS); +Datum sphereline_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical paths. * Calls skey_cmp(const int32 *, const int32 *) for two paths. */ -Datum spherepath_cmp(PG_FUNCTION_ARGS); +Datum spherepath_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical polygons. * Calls skey_cmp(const int32 *, const int32 *) for two polygons. */ -Datum spherepoly_cmp(PG_FUNCTION_ARGS); +Datum spherepoly_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical boxes. * Calls skey_cmp(const int32 *, const int32 *) for two boxes. */ -Datum spherebox_cmp(PG_FUNCTION_ARGS); +Datum spherebox_cmp(PG_FUNCTION_ARGS); #endif diff --git a/src/line.c b/src/line.c index ad02575..815cf59 100644 --- a/src/line.c +++ b/src/line.c @@ -42,8 +42,8 @@ PG_FUNCTION_INFO_V1(sphereline_point_distance_com); static void sline_swap_beg_end(SLine *out, const SLine *in) { - SLine l; - SEuler se; + SLine l; + SEuler se; l.length = in->length; l.phi = -in->length; @@ -65,7 +65,8 @@ sline_eq(const SLine *l1, const SLine *l2) } else { - SEuler e1, e2; + SEuler e1, + e2; seuler_set_zxz(&e1); seuler_set_zxz(&e2); @@ -84,8 +85,8 @@ sline_eq(const SLine *l1, const SLine *l2) bool sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend) { - SEuler se; - float8 l; + SEuler se; + float8 l; l = spoint_dist(pbeg, pend); @@ -129,8 +130,8 @@ sline_meridian(SLine *sl, float8 lng) void sline_begin(SPoint *p, const SLine *l) { - const SPoint tmp = {0.0, 0.0}; - SEuler se; + const SPoint tmp = {0.0, 0.0}; + SEuler se; sphereline_to_euler(&se, l); euler_spoint_trans(p, &tmp, &se); @@ -139,8 +140,8 @@ sline_begin(SPoint *p, const SLine *l) void sline_end(SPoint *p, const SLine *l) { - SPoint tmp = {0.0, 0.0}; - SEuler se; + SPoint tmp = {0.0, 0.0}; + SEuler se; tmp.lng = l->length; sphereline_to_euler(&se, l); @@ -153,8 +154,8 @@ sline_end(SPoint *p, const SLine *l) static void sline_vector_begin(Vector3D *v, const SLine *l) { - const Vector3D tmp = {1.0, 0.0, 0.0}; - SEuler se; + const Vector3D tmp = {1.0, 0.0, 0.0}; + SEuler se; sphereline_to_euler(&se, l); euler_vector_trans(v, &tmp, &se); @@ -337,13 +338,15 @@ sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2) int8 sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc) { - float8 i, mi; - const float8 step = (PI - 0.01); - SPoint p[2] = {{0.0, 0.0}, {0.0, 0.0}}; - SCIRCLE c; - bool bbeg, bend; - SEuler se; - int contain; + float8 i, + mi; + const float8 step = (PI - 0.01); + SPoint p[2] = {{0.0, 0.0}, {0.0, 0.0}}; + SCIRCLE c; + bool bbeg, + bend; + SEuler se; + int contain; if (FPzero(sl->length)) { @@ -407,8 +410,8 @@ bool sline_circle_touch(const SLine *sl, const SCIRCLE *sc) { /* we assume here, line and circle overlap */ - SEuler se; - SCIRCLE tc; + SEuler se; + SCIRCLE tc; sphereline_to_euler_inv(&se, sl); euler_scircle_trans(&tc, sc, &se); @@ -441,14 +444,17 @@ sline_circle_touch(const SLine *sl, const SCIRCLE *sc) int8 sline_sline_pos(const SLine *l1, const SLine *l2) { - const SLine *il1, *il2; - Vector3D v[2][2], - vtmp; - SEuler se; - SLine sl1, sl2, lseg; - SPoint p[4]; - const float8 seg_length = (PI - 0.1); - float8 seg_begin; + const SLine *il1, + *il2; + Vector3D v[2][2], + vtmp; + SEuler se; + SLine sl1, + sl2, + lseg; + SPoint p[4]; + const float8 seg_length = (PI - 0.1); + float8 seg_begin; if (sline_eq(l1, l2)) { @@ -478,15 +484,15 @@ sline_sline_pos(const SLine *l1, const SLine *l2) return PGS_LINE_AVOID; } - sl1.phi = sl1.theta = sl1.psi = 0.0; - p[0].lat = p[0].lng = p[1].lat = 0.0; - sl1.length = p[1].lng = il1->length; - v[0][0].x = 1.0; - v[0][0].y = 0.0; - v[0][0].z = 0.0; - v[0][1].x = cos(il1->length); - v[0][1].y = sin(il1->length); - v[0][1].z = 0.0; + sl1.phi = sl1.theta = sl1.psi = 0.0; + p[0].lat = p[0].lng = p[1].lat = 0.0; + sl1.length = p[1].lng = il1->length; + v[0][0].x = 1.0; + v[0][0].y = 0.0; + v[0][0].z = 0.0; + v[0][1].x = cos(il1->length); + v[0][1].y = sin(il1->length); + v[0][1].z = 0.0; sphereline_to_euler_inv(&se, il1); sline_vector_begin(&vtmp, il2); @@ -499,8 +505,8 @@ sline_sline_pos(const SLine *l1, const SLine *l2) /* Check, sl2 is at equator */ if (FPzero(p[2].lat) && FPzero(p[3].lat)) { - bool a1 = spoint_at_sline(&p[2], &sl1); - bool a2 = spoint_at_sline(&p[3], &sl1); + bool a1 = spoint_at_sline(&p[2], &sl1); + bool a2 = spoint_at_sline(&p[3], &sl1); if (a1 && a2) { @@ -534,8 +540,10 @@ sline_sline_pos(const SLine *l1, const SLine *l2) if (FPle(il2->length, seg_length)) { bool a1 = (FPge(p[2].lat, 0.0) && FPle(p[3].lat, 0.0)); + /* sl2 crosses equator desc. */ bool a2 = (FPle(p[2].lat, 0.0) && FPge(p[3].lat, 0.0)); + /* sl2 crosses equator asc. */ if (a1 || a2) @@ -564,10 +572,10 @@ sline_sline_pos(const SLine *l1, const SLine *l2) { lseg.length = ((seg_begin + seg_length) > il2->length) ? - (il2->length - seg_begin) : seg_length; - lseg.phi = sl2.phi + seg_begin; - lseg.theta = sl2.theta; - lseg.psi = sl2.psi; + (il2->length - seg_begin) : seg_length; + lseg.phi = sl2.phi + seg_begin; + lseg.theta = sl2.theta; + lseg.psi = sl2.psi; if (sline_sline_pos(&sl1, &lseg) != PGS_LINE_AVOID) { @@ -596,7 +604,7 @@ sphereline_to_euler(SEuler *se, const SLine *sl) void euler_sline_trans(SLine *out, const SLine *in, const SEuler *se) { - SEuler stmp[2]; + SEuler stmp[2]; sphereline_to_euler(&stmp[0], in); seuler_trans_zxz(&stmp[1], &stmp[0], se); @@ -609,8 +617,8 @@ euler_sline_trans(SLine *out, const SLine *in, const SEuler *se) bool spoint_at_sline(const SPoint *p, const SLine *sl) { - SEuler se; - SPoint sp; + SEuler se; + SPoint sp; sphereline_to_euler_inv(&se, sl); euler_spoint_trans(&sp, p, &se); @@ -635,8 +643,8 @@ spoint_at_sline(const SPoint *p, const SLine *sl) void sline_center(SPoint *c, const SLine *sl) { - SEuler se; - SPoint p; + SEuler se; + SPoint p; p.lng = sl->length / 2.0; p.lat = 0.0; @@ -644,7 +652,8 @@ sline_center(SPoint *c, const SLine *sl) euler_spoint_trans(c, &p, &se); } -float8 sline_point_dist(const SLine *sl, const SPoint *p) +float8 +sline_point_dist(const SLine *sl, const SPoint *p) { Vector3D v_beg; Vector3D v_end; @@ -668,7 +677,10 @@ float8 sline_point_dist(const SLine *sl, const SPoint *p) sline_vector_end(&v_end, sl); spoint_vector3d(&v, p); - /* normal1 to the plane passing through the line and the center of the sphere */ + /* + * normal1 to the plane passing through the line and the center of the + * sphere + */ vector3d_cross(&normal1, &v_beg, &v_end); if (vector3d_eq(&normal1, &v)) { @@ -700,15 +712,15 @@ float8 sline_point_dist(const SLine *sl, const SPoint *p) Datum sphereline_in(PG_FUNCTION_ARGS) { - SLine *sl = (SLine *) palloc(sizeof(SLine)); - char *c = PG_GETARG_CSTRING(0); - unsigned char etype[3]; - float8 eang[3], - length; - SEuler se, - stmp, - so; - int i; + SLine *sl = (SLine *) palloc(sizeof(SLine)); + char *c = PG_GETARG_CSTRING(0); + unsigned char etype[3]; + float8 eang[3], + length; + SEuler se, + stmp, + so; + int i; void sphere_yyparse(void); @@ -824,7 +836,7 @@ sphereline_from_trans(PG_FUNCTION_ARGS) } else { - SEuler tmp; + SEuler tmp; if (FPgt(l, PID)) { @@ -1110,16 +1122,17 @@ spheretrans_from_line(PG_FUNCTION_ARGS) Datum sphereline_point_distance(PG_FUNCTION_ARGS) { - const SLine *s = (SLine *) PG_GETARG_POINTER(0); - const SPoint *p = (SPoint *) PG_GETARG_POINTER(1); + const SLine *s = (SLine *) PG_GETARG_POINTER(0); + const SPoint *p = (SPoint *) PG_GETARG_POINTER(1); + PG_RETURN_FLOAT8(sline_point_dist(s, p)); } Datum sphereline_point_distance_com(PG_FUNCTION_ARGS) { - const SPoint *p = (SPoint *) PG_GETARG_POINTER(0); - const SLine *s = (SLine *) PG_GETARG_POINTER(1); + const SPoint *p = (SPoint *) PG_GETARG_POINTER(0); + const SLine *s = (SLine *) PG_GETARG_POINTER(1); + PG_RETURN_FLOAT8(sline_point_dist(s, p)); } - diff --git a/src/line.h b/src/line.h index 002f371..7263500 100644 --- a/src/line.h +++ b/src/line.h @@ -10,10 +10,10 @@ */ typedef struct { - float8 phi, /* the first rotation angle around z axis */ - theta, /* the second rotation angle around x axis */ - psi; /* the last rotation angle around z axis */ - float8 length; /* the length of the line */ + float8 phi, /* the first rotation angle around z axis */ + theta, /* the second rotation angle around x axis */ + psi; /* the last rotation angle around z axis */ + float8 length; /* the length of the line */ } SLine; /* PGS_RELATIONSHIPS Object relationships */ @@ -37,47 +37,47 @@ typedef struct * * Returns false if the distance between the 'pbeg' and the 'pend' is 180deg. */ -bool sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend); +bool sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend); /* * Returns a meridian line of a given longitude in radians. The result is placed * into 'sl'. */ -void sline_meridian(SLine *sl, float8 lng); +void sline_meridian(SLine *sl, float8 lng); /* * Returns the starting point of a line 'l'. Result is placed into 'p'. */ -void sline_begin(SPoint *p, const SLine *l); +void sline_begin(SPoint *p, const SLine *l); /* * Returns the ending point of a line 'l'. Result is placed into 'p'. */ -void sline_end(SPoint *p, const SLine *l); +void sline_end(SPoint *p, const SLine *l); /* * Puts the minimum and the maximum latitudes of a spherical line 's1' into 'minlat' * and 'maxlat'. */ -void sline_min_max_lat(const SLine *sl, float8 *minlat, float8 *maxlat); +void sline_min_max_lat(const SLine *sl, float8 *minlat, float8 *maxlat); /* * Calculates spherical points with a latitude 'lat' on a spherical line. * * Returns the number of found points or <0 if undefined. */ -int32 sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2); +int32 sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2); /* * Returns true if two lines are equal. */ -bool sline_eq(const SLine *l1, const SLine *l2); +bool sline_eq(const SLine *l1, const SLine *l2); /* * Returns the relationship between a line and a circle as PGS_CIRCLE_LINE_REL * int8 value. */ -int8 sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc); +int8 sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc); /* * Assuming that a line and a circle overlap, this function returns true @@ -87,31 +87,31 @@ int8 sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc); * * See sphereline_circle_pos (const SLine *, const SCIRCLE *) */ -bool sline_circle_touch(const SLine *sl, const SCIRCLE *sc); +bool sline_circle_touch(const SLine *sl, const SCIRCLE *sc); /* * Returns the relationship between two lines as PGS_LINE_LINE_REL int8 value. */ -int8 sline_sline_pos(const SLine *l1, const SLine *l2); +int8 sline_sline_pos(const SLine *l1, const SLine *l2); /* * Checks whether a point is on a line. */ -bool spoint_at_sline(const SPoint *p, const SLine *sl); +bool spoint_at_sline(const SPoint *p, const SLine *sl); /* * Returns the Euler transformation of a line. * * See spheretrans_from_line(PG_FUNCTION_ARGS) */ -void sphereline_to_euler(SEuler *se, const SLine *sl); +void sphereline_to_euler(SEuler *se, const SLine *sl); /* * Returns the inverse Euler transformation of a line. * * See spheretrans_from_line(PG_FUNCTION_ARGS) */ -void sphereline_to_euler_inv(SEuler *se, const SLine *sl); +void sphereline_to_euler_inv(SEuler *se, const SLine *sl); /* * Transforms a line using an Euler transformation. @@ -122,187 +122,187 @@ void sphereline_to_euler_inv(SEuler *se, const SLine *sl); * * See spheretrans_line (PG_FUNCTION_ARGS) */ -void euler_sline_trans(SLine *out, const SLine *in, const SEuler *se); +void euler_sline_trans(SLine *out, const SLine *in, const SEuler *se); /* * Puts the center of a line 'sl' into point 'c'. */ -void sline_center(SPoint *c, const SLine *sl); +void sline_center(SPoint *c, const SLine *sl); /* * Calculates the distance between a line 'sl' and a point 'p' */ -float8 sline_point_dist(const SLine *sl, const SPoint *p); +float8 sline_point_dist(const SLine *sl, const SPoint *p); /* * The input function for spherical line. */ -Datum sphereline_in(PG_FUNCTION_ARGS); +Datum sphereline_in(PG_FUNCTION_ARGS); /* * Create a line from a spherical point. */ -Datum sphereline_from_point(PG_FUNCTION_ARGS); +Datum sphereline_from_point(PG_FUNCTION_ARGS); /* * This function creates a spherical line using a starting point * and an ending point. The distance between the points must not be * equal to 180deg. */ -Datum sphereline_from_points(PG_FUNCTION_ARGS); +Datum sphereline_from_points(PG_FUNCTION_ARGS); /* * This function creates a spherical line using a given Euler transformation * and the length of a line. If the length is less than zero, an error occurs. * If the length is larger than 360deg, it is set to 360deg. */ -Datum sphereline_from_trans(PG_FUNCTION_ARGS); +Datum sphereline_from_trans(PG_FUNCTION_ARGS); /* * This function creates a meridian running from south to north. * The float8 param provides the longitude in radians. */ -Datum sphereline_meridian(PG_FUNCTION_ARGS); +Datum sphereline_meridian(PG_FUNCTION_ARGS); /* * Swaps the starting point and the ending point of a line. */ -Datum sphereline_swap_beg_end(PG_FUNCTION_ARGS); +Datum sphereline_swap_beg_end(PG_FUNCTION_ARGS); /* * Turns the line while preserving the starting & ending points. */ -Datum sphereline_turn(PG_FUNCTION_ARGS); +Datum sphereline_turn(PG_FUNCTION_ARGS); /* * Returns the beginning of a line. */ -Datum sphereline_begin(PG_FUNCTION_ARGS); +Datum sphereline_begin(PG_FUNCTION_ARGS); /* * Returns the ending of a line. */ -Datum sphereline_end(PG_FUNCTION_ARGS); +Datum sphereline_end(PG_FUNCTION_ARGS); /* * Returns the length of a line in radians. */ -Datum sphereline_length(PG_FUNCTION_ARGS); +Datum sphereline_length(PG_FUNCTION_ARGS); /* * Checks whether a line contains a point. */ -Datum sphereline_cont_point(PG_FUNCTION_ARGS); +Datum sphereline_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a line doesn't contain a point. */ -Datum sphereline_cont_point_neg(PG_FUNCTION_ARGS); +Datum sphereline_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a line contains a point. */ -Datum sphereline_cont_point_com(PG_FUNCTION_ARGS); +Datum sphereline_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a line doesn't contain a point. */ -Datum sphereline_cont_point_com_neg(PG_FUNCTION_ARGS); +Datum sphereline_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a line. */ -Datum spherecircle_cont_line(PG_FUNCTION_ARGS); +Datum spherecircle_cont_line(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a line. */ -Datum spherecircle_cont_line_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a line. */ -Datum spherecircle_cont_line_com(PG_FUNCTION_ARGS); +Datum spherecircle_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a line. */ -Datum spherecircle_cont_line_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a line overlap. */ -Datum sphereline_overlap_circle(PG_FUNCTION_ARGS); +Datum sphereline_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether circle and a line don't overlap. */ -Datum sphereline_overlap_circle_neg(PG_FUNCTION_ARGS); +Datum sphereline_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a line overlap. */ -Datum sphereline_overlap_circle_com(PG_FUNCTION_ARGS); +Datum sphereline_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether circle and a line don't overlap. */ -Datum sphereline_overlap_circle_com_neg(PG_FUNCTION_ARGS); +Datum sphereline_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two lines are equal. */ -Datum sphereline_equal(PG_FUNCTION_ARGS); +Datum sphereline_equal(PG_FUNCTION_ARGS); /* * Checks whether two lines are not equal. */ -Datum sphereline_equal_neg(PG_FUNCTION_ARGS); +Datum sphereline_equal_neg(PG_FUNCTION_ARGS); /* * Checks whether two lines cross each other. */ -Datum sphereline_crosses(PG_FUNCTION_ARGS); +Datum sphereline_crosses(PG_FUNCTION_ARGS); /* * Checks whether two lines don't cross each other. */ -Datum sphereline_crosses_neg(PG_FUNCTION_ARGS); +Datum sphereline_crosses_neg(PG_FUNCTION_ARGS); /* * Checks whether two lines overlap. */ -Datum sphereline_overlap(PG_FUNCTION_ARGS); +Datum sphereline_overlap(PG_FUNCTION_ARGS); /* * Checks whether two lines are overlap. */ -Datum sphereline_overlap_neg(PG_FUNCTION_ARGS); +Datum sphereline_overlap_neg(PG_FUNCTION_ARGS); /* * Returns an Euler transformation. An inverse transformation with it puts * the line into equator beginning at (0,0) and ending at (0,length). */ -Datum spheretrans_from_line(PG_FUNCTION_ARGS); +Datum spheretrans_from_line(PG_FUNCTION_ARGS); /* * Transforms a line with an Euler transformation. */ -Datum spheretrans_line(PG_FUNCTION_ARGS); +Datum spheretrans_line(PG_FUNCTION_ARGS); /* * Transforms a line with an inverse Euler transformation. */ -Datum spheretrans_line_inverse(PG_FUNCTION_ARGS); +Datum spheretrans_line_inverse(PG_FUNCTION_ARGS); /* * Returns the distance between a line and a point. */ -Datum sphereline_point_distance(PG_FUNCTION_ARGS); +Datum sphereline_point_distance(PG_FUNCTION_ARGS); /* * Returns the distance between a point and a line. */ -Datum sphereline_point_distance_com(PG_FUNCTION_ARGS); +Datum sphereline_point_distance_com(PG_FUNCTION_ARGS); #endif diff --git a/src/moc.c b/src/moc.c index 6f1cbaf..3fab480 100644 --- a/src/moc.c +++ b/src/moc.c @@ -46,7 +46,7 @@ PG_FUNCTION_INFO_V1(smoc_gin_extract_query); PG_FUNCTION_INFO_V1(smoc_gin_extract_query_fine); PG_FUNCTION_INFO_V1(smoc_gin_consistent); -int32 smoc_output_type = 0; +int32 smoc_output_type = 0; #define LAYDEB 0 @@ -58,7 +58,7 @@ int32 smoc_output_type = 0; #name " = " fmt "; ", name)) #define DEBUG_INT(name) DEBUG_PRINT(name, "%d") #define DEBUG_64(name) DEBUG_PRINT(name, MOC_FORMAT_64) -// #define DEBUG_(name) DEBUG_PRINT(name, "%") +/* #define DEBUG_(name) DEBUG_PRINT(name, "%") */ #define DEBUG_ENTRY(name) DEBUG_(hpint64 x; \ memmove(&x, name->start, HP64_SIZE); \ @@ -91,7 +91,7 @@ static void moc_error_out(const char *message, int type) { ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("MOC processing error: %s", message))); + errmsg("MOC processing error: %s", message))); } static bool @@ -101,90 +101,92 @@ index_invalid(hpint64 npix, long index) } static int -dbg_to_moc(int pos, void* moc_in_context, long order, hpint64 first, hpint64 last, - pgs_error_handler error_out) +dbg_to_moc(int pos, void *moc_in_context, long order, hpint64 first, hpint64 last, + pgs_error_handler error_out) { add_to_moc(moc_in_context, order, first, last, error_out); return 0; } -// The release_moc_in_context() calls of smoc_in() should be eventually wrapped -// into the finalisation function of a proper PostgreSQL memory context. -// +/* + * The release_moc_in_context() calls of smoc_in() should be eventually wrapped + * into the finalisation function of a proper PostgreSQL memory context. + */ Datum smoc_in(PG_FUNCTION_ARGS) { - char* input_text = PG_GETARG_CSTRING(0); - char c; - Smoc* moc; - void* moc_in_context = create_moc_in_context(moc_error_out); - int32 moc_size; - - long order = -1; - hpint64 npix = 0; - hpint64 nb; - hpint64 nb2; - - int ind = 0; + char *input_text = PG_GETARG_CSTRING(0); + char c; + Smoc *moc; + void *moc_in_context = create_moc_in_context(moc_error_out); + int32 moc_size; + + long order = -1; + hpint64 npix = 0; + hpint64 nb; + hpint64 nb2; + + int ind = 0; + while (input_text[ind] != '\0') { nb = readNumber(input_text, &ind); c = readChar(input_text, &ind); - if (c == '/') /* nb is a Healpix order */ + if (c == '/') /* nb is a Healpix order */ { if (nb == -1) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("[c.%d] Incorrect MOC syntax: a Healpix level " - "is expected before a / character.", ind - 1), - errhint("Expected syntax: '{healpix_order}/" - "{healpix_index}[,...] ...', where " - "{healpix_order} is between 0 and 29. Example: " - "'1/0 2/3,5-10'."))); + errmsg("[c.%d] Incorrect MOC syntax: a Healpix level " + "is expected before a / character.", ind - 1), + errhint("Expected syntax: '{healpix_order}/" + "{healpix_index}[,...] ...', where " + "{healpix_order} is between 0 and 29. Example: " + "'1/0 2/3,5-10'."))); } else if (order_invalid((int) nb)) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix order " MOC_FORMAT_64 - ".", ind - 1, nb), - errhint("A valid Healpix order must be an integer " - "between 0 and 29."))); + errmsg("[c.%d] Incorrect Healpix order " MOC_FORMAT_64 + ".", ind - 1, nb), + errhint("A valid Healpix order must be an integer " + "between 0 and 29."))); } order = nb; npix = c_npix(order); moc_in_context_set_order(moc_in_context, order); } - else if (c == ',') /* nb is a Healpix index */ + else if (c == ',') /* nb is a Healpix index */ { if (index_invalid(npix, nb)) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", - ind - 1, nb), - errhint("At order %ld, a Healpix index must be " - "an integer between 0 and " MOC_FORMAT_64 ".", order, - npix - 1))); + errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", + ind - 1, nb), + errhint("At order %ld, a Healpix index must be " + "an integer between 0 and " MOC_FORMAT_64 ".", order, + npix - 1))); } dbg_to_moc(1, moc_in_context, order, nb, nb + 1, moc_error_out); } - else if (c == '-') /* next Healpix number must follow */ + else if (c == '-') /* next Healpix number must follow */ { nb2 = readNumber(input_text, &ind); if (nb2 == -1) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("[c.%d] Incorrect MOC syntax: a second Healpix " - "index is expected after a '-' character.", - (ind - 1)), - errhint("Expected syntax: '{healpix_order}/" - "{healpix_index}[,...] ...', where " - "{healpix_order} is between 0 and 29. Example: " - "'1/0 2/3,5-10'."))); + errmsg("[c.%d] Incorrect MOC syntax: a second Healpix " + "index is expected after a '-' character.", + (ind - 1)), + errhint("Expected syntax: '{healpix_order}/" + "{healpix_index}[,...] ...', where " + "{healpix_order} is between 0 and 29. Example: " + "'1/0 2/3,5-10'."))); } c = readChar(input_text, &ind); @@ -197,80 +199,80 @@ smoc_in(PG_FUNCTION_ARGS) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Healpix order must not be negative.", - ind - 1), - errhint("Expected syntax: '{healpix_order}/" - "{healpix_index}[,...] ...', where " - "{healpix_order} is between 0 and 29. Example: " - "'1/0 2/3,5-10'."))); + errmsg("[c.%d] Healpix order must not be negative.", + ind - 1), + errhint("Expected syntax: '{healpix_order}/" + "{healpix_index}[,...] ...', where " + "{healpix_order} is between 0 and 29. Example: " + "'1/0 2/3,5-10'."))); } if (index_invalid(npix, nb)) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", - ind - 1, nb), - errhint("At order %ld, a Healpix index must be " - "an integer between 0 and " MOC_FORMAT_64 ".", order, - npix - 1))); + errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", + ind - 1, nb), + errhint("At order %ld, a Healpix index must be " + "an integer between 0 and " MOC_FORMAT_64 ".", order, + npix - 1))); } if (index_invalid(npix, nb2)) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", - ind - 1, nb2), - errhint("At order %ld, a Healpix index must be " - "an integer between 0 and " MOC_FORMAT_64 ".", order, - npix - 1))); + errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", + ind - 1, nb2), + errhint("At order %ld, a Healpix index must be " + "an integer between 0 and " MOC_FORMAT_64 ".", order, + npix - 1))); } if (nb >= nb2) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix range " MOC_FORMAT_64 "-" MOC_FORMAT_64 ".", - ind - 1 , nb, nb2), - errhint("The first value of a range (here " MOC_FORMAT_64 ") must be" - " less than the second one (here " MOC_FORMAT_64 ").", - nb, nb2))); + errmsg("[c.%d] Incorrect Healpix range " MOC_FORMAT_64 "-" MOC_FORMAT_64 ".", + ind - 1, nb, nb2), + errhint("The first value of a range (here " MOC_FORMAT_64 ") must be" + " less than the second one (here " MOC_FORMAT_64 ").", + nb, nb2))); } dbg_to_moc(2, moc_in_context, order, nb, nb2 + 1, moc_error_out); } - else if (isdigit(c)) /* nb is the last Healpix index of this level */ + else if (isdigit(c)) /* nb is the last Healpix index of this level */ { if (index_invalid(npix, nb)) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", - ind - 1, nb), - errhint("At order %ld, a Healpix index must be " - "an integer between 0 and " MOC_FORMAT_64 ".", order, - npix - 1))); + errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", + ind - 1, nb), + errhint("At order %ld, a Healpix index must be " + "an integer between 0 and " MOC_FORMAT_64 ".", order, + npix - 1))); } - ind--; /* Nothing else to do in this function */ + ind--; /* Nothing else to do in this function */ dbg_to_moc(3, moc_in_context, order, nb, nb + 1, moc_error_out); } - else if (c == '\0') /* nb should be the last Healpix index */ + else if (c == '\0') /* nb should be the last Healpix index */ { if (order == -1) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("Incorrect MOC syntax: empty string found."), - errhint("The minimal expected syntax is: '{healpix_order}/', " - "where {healpix_order} must be an integer between 0 and" - " 29. This will create an empty MOC. Example: '1/'."))); + errmsg("Incorrect MOC syntax: empty string found."), + errhint("The minimal expected syntax is: '{healpix_order}/', " + "where {healpix_order} must be an integer between 0 and" + " 29. This will create an empty MOC. Example: '1/'."))); } else if (nb != -1 && index_invalid(npix, nb)) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", - ind - 1, nb), - errhint("At order %ld, a Healpix index must be " - "an integer between 0 and " MOC_FORMAT_64 ".", order, - npix - 1))); + errmsg("[c.%d] Incorrect Healpix index " MOC_FORMAT_64 ".", + ind - 1, nb), + errhint("At order %ld, a Healpix index must be " + "an integer between 0 and " MOC_FORMAT_64 ".", order, + npix - 1))); } else { @@ -281,17 +283,17 @@ smoc_in(PG_FUNCTION_ARGS) { release_moc_in_context(moc_in_context, moc_error_out); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("[c.%d] Incorrect MOC syntax: unsupported character " - "'%c'.", ind - 1, c), - errhint("Expected syntax: '{healpix_order}/" - "{healpix_index}[,...] ...', where {healpix_order} " - "is between 0 and 29. Example: '1/0 2/3,5-10'."))); + errmsg("[c.%d] Incorrect MOC syntax: unsupported character " + "'%c'.", ind - 1, c), + errhint("Expected syntax: '{healpix_order}/" + "{healpix_index}[,...] ...', where {healpix_order} " + "is between 0 and 29. Example: '1/0 2/3,5-10'."))); } } moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); /* palloc() will leak the moc_in_context if it fails :-/ */ - moc = (Smoc*) palloc0(moc_size); + moc = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc, moc_size); create_moc_release_context(moc_in_context, moc, moc_error_out); PG_RETURN_POINTER(moc); @@ -299,87 +301,94 @@ smoc_in(PG_FUNCTION_ARGS) /** * [readNumber(char*, int*) --> long] - * + * * Read the next character as a number. - * + * * All whitespaces from the given position to the first digit are silently * skiped. - * + * * If the first non-whitespace character is not a digit, this function returns * immediately -1. Otherwise, all successive digits are read and gather to build * the corresponding number. - * + * * The given index is incremented each time a character (whatever it is) is * skiped. - * + * * @param mocAscii The string in which the number must be read. * @param start Index from which the number must be read. * This value is incremented at each read character. - * + * * @return The read number, * or -1 if no digit has been found. */ -hpint64 readNumber(const char* mocAscii, int* start) +hpint64 +readNumber(const char *mocAscii, int *start) { - hpint64 nb = -1; - - // Skip all space characters: - while(mocAscii[*start] != '\0' && isspace(mocAscii[*start])) - (*start)++; - - /* If the current character is a digit, - * read all other possible successive digits: */ - if (mocAscii[*start] != '\0' && isdigit(mocAscii[*start])){ - nb = 0; - do{ - nb = nb*10 + (long)(mocAscii[*start]-48); - (*start)++; - }while(isdigit(mocAscii[*start]) && mocAscii[*start] != '\0'); - } - - // Return the read number: - return nb; + hpint64 nb = -1; + + /* Skip all space characters: */ + while (mocAscii[*start] != '\0' && isspace(mocAscii[*start])) + (*start)++; + + /* + * If the current character is a digit, read all other possible successive + * digits: + */ + if (mocAscii[*start] != '\0' && isdigit(mocAscii[*start])) + { + nb = 0; + do + { + nb = nb * 10 + (long) (mocAscii[*start] - 48); + (*start)++; + } while (isdigit(mocAscii[*start]) && mocAscii[*start] != '\0'); + } + + /* Return the read number: */ + return nb; } /** * [readChar(char*, int*) --> char] - * + * * Read the next non-whitespace character. - * + * * All whitespaces from the given position are silently skipped. - * + * * The given index is incremented each time a character (whatever it is) is * skipped. - * + * * When the end of the given string is reached, this function stops immediately * and returns '\0'. The given index is then set to the corresponding position. - * + * * @param mocAscii The string in which the next non-whitespace character must * be read. * @param start Index from which the character must be read. * This value is incremented at each read character. - * + * * @return The read non-whitespace character, * or '\0' if the end has been reached. */ -char readChar(const char* mocAscii, int* start) +char +readChar(const char *mocAscii, int *start) { - // Skip all space characters: - while(mocAscii[*start] != '\0' && isspace(mocAscii[*start])) - (*start)++; - - // Return the read character: - if (mocAscii[*start] == '\0') - return '\0'; - else - return mocAscii[(*start)++]; + /* Skip all space characters: */ + while (mocAscii[*start] != '\0' && isspace(mocAscii[*start])) + (*start)++; + + /* Return the read character: */ + if (mocAscii[*start] == '\0') + return '\0'; + else + return mocAscii[(*start)++]; } Datum set_smoc_output_type(PG_FUNCTION_ARGS) { - int32 out_type = PG_GETARG_INT32(0); - char *buffer = (char *) palloc(80); + int32 out_type = PG_GETARG_INT32(0); + char *buffer = (char *) palloc(80); + if (out_type < 0) out_type = 0; if (out_type > 1) @@ -403,12 +412,13 @@ Datum smoc_info(PG_FUNCTION_ARGS) { /* get just the MOC header: */ - Smoc *moc = (Smoc *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, - MOC_HEADER_VARSIZE); - char *p = psprintf("version: %u, order: %u, depth: %u, first: " MOC_FORMAT_64U - ", last: " MOC_FORMAT_64U ", area: " MOC_FORMAT_64U ", tree_begin: %d, data_begin: %d", - moc->version, moc->order, moc-> depth, moc->first, moc->last, moc->area, - moc->tree_begin, moc->data_begin); + Smoc *moc = (Smoc *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, + MOC_HEADER_VARSIZE); + char *p = psprintf("version: %u, order: %u, depth: %u, first: " MOC_FORMAT_64U + ", last: " MOC_FORMAT_64U ", area: " MOC_FORMAT_64U ", tree_begin: %d, data_begin: %d", + moc->version, moc->order, moc->depth, moc->first, moc->last, moc->area, + moc->tree_begin, moc->data_begin); + PG_RETURN_TEXT_P(cstring_to_text(p)); } @@ -416,8 +426,9 @@ Datum smoc_area(PG_FUNCTION_ARGS) { /* get just the MOC header: */ - Smoc *moc = (Smoc *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, - MOC_HEADER_VARSIZE); + Smoc *moc = (Smoc *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, + MOC_HEADER_VARSIZE); + PG_RETURN_FLOAT8(moc->area * 4.0 * M_PI / MOC_AREA_ALL_SKY); } @@ -425,19 +436,22 @@ Datum smoc_order(PG_FUNCTION_ARGS) { /* get just the MOC header: */ - Smoc *moc = (Smoc *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, - MOC_HEADER_VARSIZE); + Smoc *moc = (Smoc *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, + MOC_HEADER_VARSIZE); + PG_RETURN_INT32(moc->order); } Datum smoc_out(PG_FUNCTION_ARGS) { - Smoc *moc = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + Smoc *moc = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); moc_out_data out_context - = create_moc_out_context(moc, VARSIZE(moc) - VARHDRSZ, moc_error_out); + = create_moc_out_context(moc, VARSIZE(moc) - VARHDRSZ, moc_error_out); + /* palloc() will leak the out_context if it fails :-/ */ - char *buf = (char *) palloc(out_context.out_size); + char *buf = (char *) palloc(out_context.out_size); + print_moc_release_context(out_context, buf, moc_error_out); PG_RETURN_CSTRING(buf); } @@ -446,46 +460,53 @@ Datum moc_debug(PG_FUNCTION_ARGS) { const char *c_str; - size_t x_size = get_moc_debug(&c_str, moc_error_out); - const char *x = (const char*) palloc(x_size); - memmove((void*) x, (void*) c_str, x_size); + size_t x_size = get_moc_debug(&c_str, moc_error_out); + const char *x = (const char *) palloc(x_size); + + memmove((void *) x, (void *) c_str, x_size); PG_RETURN_TEXT_P(cstring_to_text(x)); } static bool smoc_eq_impl(Datum a, Datum b) { - Smoc* moc_a = (Smoc *)PG_DETOAST_DATUM_SLICE(a, 0, MOC_HEADER_PAGE); - Smoc* moc_b = (Smoc *)PG_DETOAST_DATUM_SLICE(b, 0, MOC_HEADER_PAGE); - int32 moc_a_end; - int32 moc_b_end; - char* moc_a_base; - char* moc_b_base; + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM_SLICE(a, 0, MOC_HEADER_PAGE); + Smoc *moc_b = (Smoc *) PG_DETOAST_DATUM_SLICE(b, 0, MOC_HEADER_PAGE); + int32 moc_a_end; + int32 moc_b_end; + char *moc_a_base; + char *moc_b_base; /* quick exit if header values don't agree */ if (moc_a->order != moc_b->order || moc_a->first != moc_b->first || moc_a->last != moc_b->last || moc_a->area != moc_b->area) return false; - if (moc_a->data_begin != moc_b->data_begin) /* this needs to be reconsidered if the MOC version is updated */ + if (moc_a->data_begin != moc_b->data_begin) /* this needs to be + * reconsidered if the MOC + * version is updated */ return false; /* get full moc */ - moc_a = (Smoc *)PG_DETOAST_DATUM(a); - moc_b = (Smoc *)PG_DETOAST_DATUM(b); + moc_a = (Smoc *) PG_DETOAST_DATUM(a); + moc_b = (Smoc *) PG_DETOAST_DATUM(b); moc_a_end = VARSIZE(moc_a) - VARHDRSZ; moc_b_end = VARSIZE(moc_b) - VARHDRSZ; moc_a_base = MOC_BASE(moc_a); moc_b_base = MOC_BASE(moc_b); - if (moc_a_end != moc_b_end) /* this needs to be reconsidered if the MOC version is updated */ + if (moc_a_end != moc_b_end) /* this needs to be reconsidered if the MOC + * version is updated */ return false; - for (int j = moc_a->data_begin; j < moc_a_end; j += MOC_INTERVAL_SIZE) // iterate over both in parallel + for (int j = moc_a->data_begin; j < moc_a_end; j += MOC_INTERVAL_SIZE) + /* iterate over both in parallel */ { moc_interval *x; moc_interval *y; - // page bumps - int32 mod = (j + MOC_INTERVAL_SIZE) % PG_TOAST_PAGE_FRAGMENT; + + /* page bumps */ + int32 mod = (j + MOC_INTERVAL_SIZE) % PG_TOAST_PAGE_FRAGMENT; + if (mod > 0 && mod < MOC_INTERVAL_SIZE) j += MOC_INTERVAL_SIZE - mod; x = MOC_INTERVAL(moc_a_base, j); @@ -501,57 +522,61 @@ smoc_eq_impl(Datum a, Datum b) Datum smoc_eq(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + PG_RETURN_BOOL(smoc_eq_impl(a, b)); } Datum smoc_neq(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); - PG_RETURN_BOOL(! smoc_eq_impl(a, b)); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + + PG_RETURN_BOOL(!smoc_eq_impl(a, b)); } static bool smoc_overlap_impl(Datum a, Datum b) { - Smoc* moc_a = (Smoc *)PG_DETOAST_DATUM_SLICE(a, 0, MOC_HEADER_PAGE); - Smoc* moc_b = (Smoc *)PG_DETOAST_DATUM_SLICE(b, 0, MOC_HEADER_PAGE); - int32 i = moc_a->data_begin; - int32 j = moc_b->data_begin; - int32 moc_a_end; - int32 moc_b_end; - char* moc_a_base; - char* moc_b_base; - - // empty mocs do not overlap + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM_SLICE(a, 0, MOC_HEADER_PAGE); + Smoc *moc_b = (Smoc *) PG_DETOAST_DATUM_SLICE(b, 0, MOC_HEADER_PAGE); + int32 i = moc_a->data_begin; + int32 j = moc_b->data_begin; + int32 moc_a_end; + int32 moc_b_end; + char *moc_a_base; + char *moc_b_base; + + /* empty mocs do not overlap */ if (moc_a->area == 0 || moc_b->area == 0) return false; - // quick exit if the mocs do not overlap at all + /* quick exit if the mocs do not overlap at all */ if (moc_a->first >= moc_b->last || moc_a->last <= moc_b->first) return false; - // all-sky mocs overlap everything + /* all-sky mocs overlap everything */ if (moc_a->area == MOC_AREA_ALL_SKY || moc_b->area == MOC_AREA_ALL_SKY) return true; - // get full moc - moc_a = (Smoc *)PG_DETOAST_DATUM(a); - moc_b = (Smoc *)PG_DETOAST_DATUM(b); + /* get full moc */ + moc_a = (Smoc *) PG_DETOAST_DATUM(a); + moc_b = (Smoc *) PG_DETOAST_DATUM(b); moc_a_end = VARSIZE(moc_a) - VARHDRSZ; moc_b_end = VARSIZE(moc_b) - VARHDRSZ; moc_a_base = MOC_BASE(moc_a); moc_b_base = MOC_BASE(moc_b); - while (i < moc_a_end && j < moc_b_end) // iterate over both in parallel + while (i < moc_a_end && j < moc_b_end) + /* iterate over both in parallel */ { moc_interval *x; moc_interval *y; - // page bumps - int32 mod = (i + MOC_INTERVAL_SIZE) % PG_TOAST_PAGE_FRAGMENT; + /* page bumps */ + int32 mod = (i + MOC_INTERVAL_SIZE) % PG_TOAST_PAGE_FRAGMENT; + if (mod > 0 && mod < MOC_INTERVAL_SIZE) i += MOC_INTERVAL_SIZE - mod; x = MOC_INTERVAL(moc_a_base, i); @@ -561,18 +586,21 @@ smoc_overlap_impl(Datum a, Datum b) j += MOC_INTERVAL_SIZE - mod; y = MOC_INTERVAL(moc_b_base, j); - if (x->second <= y->first) // a entirely left of b, advance a + if (x->second <= y->first) + /* a entirely left of b, advance a */ { i += MOC_INTERVAL_SIZE; continue; } - if (y->second <= x->first) // b entirely left of a, advance b + if (y->second <= x->first) + /* b entirely left of a, advance b */ { j += MOC_INTERVAL_SIZE; continue; } - return true; // entries overlap + return true; + /* entries overlap */ } return false; @@ -581,66 +609,69 @@ smoc_overlap_impl(Datum a, Datum b) Datum smoc_overlap(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + PG_RETURN_BOOL(smoc_overlap_impl(a, b)); } Datum smoc_overlap_neg(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); - PG_RETURN_BOOL(! smoc_overlap_impl(a, b)); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + + PG_RETURN_BOOL(!smoc_overlap_impl(a, b)); } /* check if moc_a is a subset of moc_b */ static bool smoc_subset_impl(Datum a, Datum b) { - Smoc* moc_a = (Smoc *)PG_DETOAST_DATUM_SLICE(a, 0, MOC_HEADER_PAGE); - Smoc* moc_b = (Smoc *)PG_DETOAST_DATUM_SLICE(b, 0, MOC_HEADER_PAGE); - int32 i = moc_a->data_begin; - int32 j = moc_b->data_begin; - int32 moc_a_end; - int32 moc_b_end; - char* moc_a_base; - char* moc_b_base; - - // an empty moc is subset of all mocs + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM_SLICE(a, 0, MOC_HEADER_PAGE); + Smoc *moc_b = (Smoc *) PG_DETOAST_DATUM_SLICE(b, 0, MOC_HEADER_PAGE); + int32 i = moc_a->data_begin; + int32 j = moc_b->data_begin; + int32 moc_a_end; + int32 moc_b_end; + char *moc_a_base; + char *moc_b_base; + + /* an empty moc is subset of all mocs */ if (moc_a->area == 0) return true; - // b is the whole sky + /* b is the whole sky */ if (moc_b->area == MOC_AREA_ALL_SKY) return true; - // a cannot be larger than b + /* a cannot be larger than b */ if (moc_a->area > moc_b->area) return false; - // quick exit if the mocs do not overlap at all + /* quick exit if the mocs do not overlap at all */ if (moc_a->first >= moc_b->last || moc_a->last <= moc_b->first) return false; - // get full moc - moc_a = (Smoc *)PG_DETOAST_DATUM(a); - moc_b = (Smoc *)PG_DETOAST_DATUM(b); + /* get full moc */ + moc_a = (Smoc *) PG_DETOAST_DATUM(a); + moc_b = (Smoc *) PG_DETOAST_DATUM(b); moc_a_end = VARSIZE(moc_a) - VARHDRSZ; moc_b_end = VARSIZE(moc_b) - VARHDRSZ; moc_a_base = MOC_BASE(moc_a); moc_b_base = MOC_BASE(moc_b); - while (i < moc_a_end) // iterate over a + while (i < moc_a_end) + /* iterate over a */ { - int32 mod; + int32 mod; moc_interval *x; moc_interval *y; - // end of b reached while there's still 'a' intervals + /* end of b reached while there's still 'a' intervals */ if (j >= moc_b_end) return false; - // page bumps + /* page bumps */ mod = (i + MOC_INTERVAL_SIZE) % PG_TOAST_PAGE_FRAGMENT; if (mod > 0 && mod < MOC_INTERVAL_SIZE) i += MOC_INTERVAL_SIZE - mod; @@ -651,20 +682,22 @@ smoc_subset_impl(Datum a, Datum b) j += MOC_INTERVAL_SIZE - mod; y = MOC_INTERVAL(moc_b_base, j); - // advance b until as long as we are before the 'a' interval + /* advance b until as long as we are before the 'a' interval */ if (y->second <= x->first) { j += MOC_INTERVAL_SIZE; continue; } - // we can check for a match now - if (x->first < y->first) // a starts left of b + /* we can check for a match now */ + if (x->first < y->first) + /* a starts left of b */ return false; - if (x->second > y->second) // b ends right of a + if (x->second > y->second) + /* b ends right of a */ return false; - // advance interval that has the lowest end + /* advance interval that has the lowest end */ if (x->second == y->second) { i += MOC_INTERVAL_SIZE; @@ -674,7 +707,11 @@ smoc_subset_impl(Datum a, Datum b) i += MOC_INTERVAL_SIZE; else j += MOC_INTERVAL_SIZE; - // TODO: we could walk the tree structure to find the next interesting interval + + /* + * TODO: we could walk the tree structure to find the next interesting + * interval + */ } return true; @@ -683,39 +720,44 @@ smoc_subset_impl(Datum a, Datum b) Datum smoc_subset_smoc(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + PG_RETURN_BOOL(smoc_subset_impl(a, b)); } Datum smoc_subset_smoc_neg(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); - PG_RETURN_BOOL(! smoc_subset_impl(a, b)); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + + PG_RETURN_BOOL(!smoc_subset_impl(a, b)); } Datum smoc_superset_smoc(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + PG_RETURN_BOOL(smoc_subset_impl(b, a)); } Datum smoc_superset_smoc_neg(PG_FUNCTION_ARGS) { - Datum a = PG_GETARG_DATUM(0); - Datum b = PG_GETARG_DATUM(1); - PG_RETURN_BOOL(! smoc_subset_impl(b, a)); + Datum a = PG_GETARG_DATUM(0); + Datum b = PG_GETARG_DATUM(1); + + PG_RETURN_BOOL(!smoc_subset_impl(b, a)); } static bool entry_equal(moc_tree_entry *a, hpint64 y) { - hpint64 x; + hpint64 x; + memmove(&x, a->start, HP64_SIZE); return x == y; } @@ -730,30 +772,31 @@ fit_level_end_to(int32 d_end, int32 *level_end, int32 level_begin, int32 mod) bool healpix_subset_smoc_impl(hpint64 x, Datum y) { - int32 end = toast_raw_datum_size(y) - VARHDRSZ; - Smoc *moc; - char *moc_base; - int32 tree_begin; - int32 depth; - int32 *level_ends; - int32 k; - int32 d_begin = 0; - int32 d_end; - int32 level_begin; - int32 level_end; + int32 end = toast_raw_datum_size(y) - VARHDRSZ; + Smoc *moc; + char *moc_base; + int32 tree_begin; + int32 depth; + int32 *level_ends; + int32 k; + int32 d_begin = 0; + int32 d_end; + int32 level_begin; + int32 level_end; moc_tree_entry *first; moc_tree_entry *last; moc_tree_entry *w; moc_interval *first_i; moc_interval *last_i; moc_interval *v; - int32 count; + int32 count; - if (end == MIN_MOC_SIZE) /* should include empty root node... */ + if (end == MIN_MOC_SIZE) /* should include empty root node... */ return false; /* get the first page -- it contains at least the full root node */ moc = (Smoc *) PG_DETOAST_DATUM_SLICE(y, 0, MOC_HEADER_PAGE); - d_end = VARSIZE(moc) - VARHDRSZ; /* the end of the actually detoasted part */ + d_end = VARSIZE(moc) - VARHDRSZ; /* the end of the actually detoasted + * part */ if (moc->first == moc->last || x < moc->first || x >= moc->last) return false; @@ -761,15 +804,15 @@ healpix_subset_smoc_impl(hpint64 x, Datum y) tree_begin = moc->tree_begin; depth = moc->depth; - level_ends = (int32 *)(moc_base + tree_begin); - level_begin = tree_begin + 4 * depth; + level_ends = (int32 *) (moc_base + tree_begin); + level_begin = tree_begin + 4 * depth; for (k = 0; k < depth; ++k) { level_end = level_ends[k]; fit_level_end_to(d_end, &level_end, level_begin, MOC_TREE_ENTRY_SIZE); - first = MOC_ENTRY(moc_base, level_begin - d_begin); - last = MOC_ENTRY(moc_base, level_end - d_begin); + first = MOC_ENTRY(moc_base, level_begin - d_begin); + last = MOC_ENTRY(moc_base, level_end - d_begin); w = entry_lower_bound(first, last, x); @@ -786,15 +829,15 @@ healpix_subset_smoc_impl(hpint64 x, Datum y) d_end = d_begin + VARSIZE(moc_base) - VARHDRSZ; moc_base += VARHDRSZ; } - // search in interval page defined by (moc_base, level_begin, d_end) + /* search in interval page defined by (moc_base, level_begin, d_end) */ fit_level_end_to(d_end, &end, level_begin, MOC_INTERVAL_SIZE); - first_i = MOC_INTERVAL(moc_base, level_begin - d_begin); - last_i = MOC_INTERVAL(moc_base, end - d_begin); + first_i = MOC_INTERVAL(moc_base, level_begin - d_begin); + last_i = MOC_INTERVAL(moc_base, end - d_begin); -//debug: print out the whole of [*first_i, *last_i) -- also for nodes!!! + /* debug: print out the whole of [*first_i, *last_i) -- also for nodes!!! */ v = interval_lower_bound(first_i, last_i, x); - + if (v != last_i && v->first == x) return true; --v; @@ -802,13 +845,13 @@ healpix_subset_smoc_impl(hpint64 x, Datum y) } Datum -healpix_subset_smoc_c(hpint64 x, Datum y) +healpix_subset_smoc_c(hpint64 x, Datum y) { PG_RETURN_BOOL(healpix_subset_smoc_impl(x, y)); } Datum -healpix_not_subset_smoc_c(hpint64 x, Datum y) +healpix_not_subset_smoc_c(hpint64 x, Datum y) { PG_RETURN_BOOL(!healpix_subset_smoc_impl(x, y)); } @@ -826,7 +869,7 @@ spoint_subset_smoc_c(SPoint *x, Datum y) } Datum -spoint_not_subset_smoc_c(SPoint *x, Datum y) +spoint_not_subset_smoc_c(SPoint *x, Datum y) { PG_RETURN_BOOL(!spoint_subset_smoc_impl(x, y)); } @@ -834,81 +877,89 @@ spoint_not_subset_smoc_c(SPoint *x, Datum y) Datum healpix_subset_smoc(PG_FUNCTION_ARGS) { - hpint64 x = PG_GETARG_INT64(0); - Datum y = PG_GETARG_DATUM(1); + hpint64 x = PG_GETARG_INT64(0); + Datum y = PG_GETARG_DATUM(1); + return healpix_subset_smoc_c(x, y); } Datum healpix_not_subset_smoc(PG_FUNCTION_ARGS) { - hpint64 x = PG_GETARG_INT64(0); - Datum y = PG_GETARG_DATUM(1); + hpint64 x = PG_GETARG_INT64(0); + Datum y = PG_GETARG_DATUM(1); + return healpix_not_subset_smoc_c(x, y); } Datum smoc_superset_healpix(PG_FUNCTION_ARGS) { - Datum x = PG_GETARG_DATUM(0); - hpint64 y = PG_GETARG_INT64(1); + Datum x = PG_GETARG_DATUM(0); + hpint64 y = PG_GETARG_INT64(1); + return healpix_subset_smoc_c(y, x); } Datum smoc_not_superset_healpix(PG_FUNCTION_ARGS) { - Datum x = PG_GETARG_DATUM(0); - hpint64 y = PG_GETARG_INT64(1); + Datum x = PG_GETARG_DATUM(0); + hpint64 y = PG_GETARG_INT64(1); + return healpix_not_subset_smoc_c(y, x); } Datum spoint_subset_smoc(PG_FUNCTION_ARGS) { - SPoint *x = (SPoint *) PG_GETARG_POINTER(0); - Datum y = PG_GETARG_DATUM(1); + SPoint *x = (SPoint *) PG_GETARG_POINTER(0); + Datum y = PG_GETARG_DATUM(1); + return spoint_subset_smoc_c(x, y); } Datum spoint_not_subset_smoc(PG_FUNCTION_ARGS) { - SPoint *x = (SPoint *) PG_GETARG_POINTER(0); - Datum y = PG_GETARG_DATUM(1); + SPoint *x = (SPoint *) PG_GETARG_POINTER(0); + Datum y = PG_GETARG_DATUM(1); + return spoint_not_subset_smoc_c(x, y); } Datum smoc_superset_spoint(PG_FUNCTION_ARGS) { - Datum x = PG_GETARG_DATUM(0); - SPoint *y = (SPoint *) PG_GETARG_POINTER(1); + Datum x = PG_GETARG_DATUM(0); + SPoint *y = (SPoint *) PG_GETARG_POINTER(1); + return spoint_subset_smoc_c(y, x); } Datum smoc_not_superset_spoint(PG_FUNCTION_ARGS) { - Datum x = PG_GETARG_DATUM(0); - SPoint *y = (SPoint *) PG_GETARG_POINTER(1); + Datum x = PG_GETARG_DATUM(0); + SPoint *y = (SPoint *) PG_GETARG_POINTER(1); + return spoint_not_subset_smoc_c(y, x); } Datum smoc_union(PG_FUNCTION_ARGS) { - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - Smoc* moc_b = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); - Smoc* moc_ret; - void* moc_in_context = create_moc_in_context(moc_error_out); - int32 moc_size; + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + Smoc *moc_b = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + Smoc *moc_ret; + void *moc_in_context = create_moc_in_context(moc_error_out); + int32 moc_size; moc_union(moc_in_context, moc_a, VARSIZE(moc_a) - VARHDRSZ, moc_b, VARSIZE(moc_b) - VARHDRSZ, moc_error_out); moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); /* palloc() will leak the moc_in_context if it fails :-/ */ - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); PG_RETURN_POINTER(moc_ret); @@ -917,17 +968,17 @@ smoc_union(PG_FUNCTION_ARGS) Datum smoc_intersection(PG_FUNCTION_ARGS) { - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - Smoc* moc_b = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); - Smoc* moc_ret; - void* moc_in_context = create_moc_in_context(moc_error_out); - int32 moc_size; + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + Smoc *moc_b = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + Smoc *moc_ret; + void *moc_in_context = create_moc_in_context(moc_error_out); + int32 moc_size; moc_intersection(moc_in_context, moc_a, VARSIZE(moc_a) - VARHDRSZ, moc_b, VARSIZE(moc_b) - VARHDRSZ, moc_error_out); moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); /* palloc() will leak the moc_in_context if it fails :-/ */ - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); PG_RETURN_POINTER(moc_ret); @@ -936,11 +987,11 @@ smoc_intersection(PG_FUNCTION_ARGS) Datum smoc_degrade(PG_FUNCTION_ARGS) { - int order = PG_GETARG_INT32(0); - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); - Smoc* moc_ret; - void* moc_in_context = create_moc_in_context(moc_error_out); - int32 moc_size; + int order = PG_GETARG_INT32(0); + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + Smoc *moc_ret; + void *moc_in_context = create_moc_in_context(moc_error_out); + int32 moc_size; check_order(order); @@ -948,7 +999,7 @@ smoc_degrade(PG_FUNCTION_ARGS) moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); /* palloc() will leak the moc_in_context if it fails :-/ */ - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); PG_RETURN_POINTER(moc_ret); @@ -957,12 +1008,14 @@ smoc_degrade(PG_FUNCTION_ARGS) Datum smoc_spoint(PG_FUNCTION_ARGS) { - int order = PG_GETARG_INT32(0); - SPoint* p = (SPoint*) PG_GETARG_POINTER(1); - hpint64 pixel, first, last; - void* moc_in_context; - int32 moc_size; - Smoc* moc_ret; + int order = PG_GETARG_INT32(0); + SPoint *p = (SPoint *) PG_GETARG_POINTER(1); + hpint64 pixel, + first, + last; + void *moc_in_context; + int32 moc_size; + Smoc *moc_ret; check_order(order); @@ -974,7 +1027,7 @@ smoc_spoint(PG_FUNCTION_ARGS) moc_healpix(moc_in_context, order, first, last, moc_error_out); moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); @@ -984,13 +1037,13 @@ smoc_spoint(PG_FUNCTION_ARGS) Datum smoc_disc(PG_FUNCTION_ARGS) { - int order = PG_GETARG_INT32(0); - double lng = PG_GETARG_FLOAT8(1); - double lat = PG_GETARG_FLOAT8(2); - double radius = PG_GETARG_FLOAT8(3); - void* moc_in_context; - int32 moc_size; - Smoc* moc_ret; + int order = PG_GETARG_INT32(0); + double lng = PG_GETARG_FLOAT8(1); + double lat = PG_GETARG_FLOAT8(2); + double radius = PG_GETARG_FLOAT8(3); + void *moc_in_context; + int32 moc_size; + Smoc *moc_ret; check_order(order); @@ -998,7 +1051,7 @@ smoc_disc(PG_FUNCTION_ARGS) moc_disc(moc_in_context, order, lng, lat, radius, moc_error_out); moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); @@ -1008,11 +1061,11 @@ smoc_disc(PG_FUNCTION_ARGS) Datum smoc_scircle(PG_FUNCTION_ARGS) { - int order = PG_GETARG_INT32(0); - SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(1); - void* moc_in_context; - int32 moc_size; - Smoc* moc_ret; + int order = PG_GETARG_INT32(0); + SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(1); + void *moc_in_context; + int32 moc_size; + Smoc *moc_ret; check_order(order); @@ -1020,7 +1073,7 @@ smoc_scircle(PG_FUNCTION_ARGS) moc_disc(moc_in_context, order, c->center.lat, c->center.lng, c->radius, moc_error_out); moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); @@ -1030,19 +1083,19 @@ smoc_scircle(PG_FUNCTION_ARGS) Datum smoc_spoly(PG_FUNCTION_ARGS) { - int order = PG_GETARG_INT32(0); - SPOLY* polygon = (SPOLY *) PG_GETARG_SPOLY(1); - void* moc_in_context; - int32 moc_size; - Smoc* moc_ret; + int order = PG_GETARG_INT32(0); + SPOLY *polygon = (SPOLY *) PG_GETARG_SPOLY(1); + void *moc_in_context; + int32 moc_size; + Smoc *moc_ret; check_order(order); moc_in_context = create_moc_in_context(moc_error_out); - moc_polygon(moc_in_context, order, polygon->npts, (float8 *)polygon->p, moc_error_out); + moc_polygon(moc_in_context, order, polygon->npts, (float8 *) polygon->p, moc_error_out); moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out); - moc_ret = (Smoc*) palloc0(moc_size); + moc_ret = (Smoc *) palloc0(moc_size); SET_VARSIZE(moc_ret, moc_size); create_moc_release_context(moc_in_context, moc_ret, moc_error_out); @@ -1054,27 +1107,29 @@ smoc_spoly(PG_FUNCTION_ARGS) static Datum smoc_gin_extract_internal(Smoc *moc_a, int32 *nkeys, int gin_order) { - char* moc_a_base = MOC_BASE(moc_a); - int32 moc_a_end = VARSIZE(moc_a) - VARHDRSZ; - int32 nalloc = 4; - Datum* keys = palloc(nalloc * sizeof(Datum)); + char *moc_a_base = MOC_BASE(moc_a); + int32 moc_a_end = VARSIZE(moc_a) - VARHDRSZ; + int32 nalloc = 4; + Datum *keys = palloc(nalloc * sizeof(Datum)); *nkeys = 0; for (int32 a = moc_a->data_begin; a < moc_a_end; a = next_interval(a)) { moc_interval *x = MOC_INTERVAL(moc_a_base, a); + int shift = 2 * (HEALPIX_MAX_ORDER - gin_order); /* degrade to + * MOC_GIN_ORDER */ + int32 first = (x->first >> shift); /* set low bits to zero */ + hpint64 low_bits_one = (1LL << shift) - 1; + int32 second = ((x->second + low_bits_one) >> shift); /* round low bits up */ - int shift = 2 * (HEALPIX_MAX_ORDER - gin_order); // degrade to MOC_GIN_ORDER - int32 first = (x->first >> shift); // set low bits to zero - hpint64 low_bits_one = (1LL << shift) - 1; - int32 second = ((x->second + low_bits_one) >> shift); // round low bits up - Assert(shift > 32); // internal GIN datatype isn't 64 bits + Assert(shift > 32); /* internal GIN datatype isn't 64 bits */ - // split interval into individual pixels of order MOC_GIN_ORDER + /* split interval into individual pixels of order MOC_GIN_ORDER */ for (int32 p = first; p < second; p++) { - if (*nkeys > 0 && keys[*nkeys - 1] == p) // has (larger) pixel already been added? + if (*nkeys > 0 && keys[*nkeys - 1] == p) + /* has(larger) pixel already been added ? */ continue; if (*nkeys >= nalloc) { @@ -1092,8 +1147,8 @@ smoc_gin_extract_internal(Smoc *moc_a, int32 *nkeys, int gin_order) Datum smoc_gin_extract_value(PG_FUNCTION_ARGS) { - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - int32* nkeys = (int32 *) PG_GETARG_POINTER(1); + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + int32 *nkeys = (int32 *) PG_GETARG_POINTER(1); PG_RETURN_DATUM(smoc_gin_extract_internal(moc_a, nkeys, MOC_GIN_ORDER)); } @@ -1101,8 +1156,8 @@ smoc_gin_extract_value(PG_FUNCTION_ARGS) Datum smoc_gin_extract_value_fine(PG_FUNCTION_ARGS) { - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - int32* nkeys = (int32 *) PG_GETARG_POINTER(1); + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + int32 *nkeys = (int32 *) PG_GETARG_POINTER(1); PG_RETURN_DATUM(smoc_gin_extract_internal(moc_a, nkeys, MOC_GIN_ORDER_FINE)); } @@ -1110,10 +1165,10 @@ smoc_gin_extract_value_fine(PG_FUNCTION_ARGS) Datum smoc_gin_extract_query(PG_FUNCTION_ARGS) { - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - int32* nkeys = (int32 *) PG_GETARG_POINTER(1); + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + int32 *nkeys = (int32 *) PG_GETARG_POINTER(1); StrategyNumber st = PG_GETARG_UINT16(2); - int32* searchmode = (int32 *) PG_GETARG_POINTER(6); + int32 *searchmode = (int32 *) PG_GETARG_POINTER(6); if (st == MOC_GIN_STRATEGY_SUBSET || (st == MOC_GIN_STRATEGY_EQUAL && moc_a->area == 0)) *searchmode = GIN_SEARCH_MODE_INCLUDE_EMPTY; @@ -1126,10 +1181,10 @@ smoc_gin_extract_query(PG_FUNCTION_ARGS) Datum smoc_gin_extract_query_fine(PG_FUNCTION_ARGS) { - Smoc* moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - int32* nkeys = (int32 *) PG_GETARG_POINTER(1); + Smoc *moc_a = (Smoc *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + int32 *nkeys = (int32 *) PG_GETARG_POINTER(1); StrategyNumber st = PG_GETARG_UINT16(2); - int32* searchmode = (int32 *) PG_GETARG_POINTER(6); + int32 *searchmode = (int32 *) PG_GETARG_POINTER(6); if (st == MOC_GIN_STRATEGY_SUBSET || (st == MOC_GIN_STRATEGY_EQUAL && moc_a->area == 0)) *searchmode = GIN_SEARCH_MODE_INCLUDE_EMPTY; @@ -1142,10 +1197,10 @@ smoc_gin_extract_query_fine(PG_FUNCTION_ARGS) Datum smoc_gin_consistent(PG_FUNCTION_ARGS) { - bool* check = (bool *) PG_GETARG_POINTER(0); + bool *check = (bool *) PG_GETARG_POINTER(0); StrategyNumber st = PG_GETARG_UINT16(1); - int32 nkeys = PG_GETARG_INT32(3); - bool* recheck = (bool *) PG_GETARG_POINTER(5); + int32 nkeys = PG_GETARG_INT32(3); + bool *recheck = (bool *) PG_GETARG_POINTER(5); switch (st) { @@ -1172,7 +1227,7 @@ smoc_gin_consistent(PG_FUNCTION_ARGS) /* return true when all pixels are contained in the indexed value */ for (int i = 0; i < nkeys; i++) { - if (! check[i]) + if (!check[i]) { PG_RETURN_BOOL(false); } @@ -1185,7 +1240,7 @@ smoc_gin_consistent(PG_FUNCTION_ARGS) /* return true when there is a difference */ for (int i = 0; i < nkeys; i++) { - if (! check[i]) + if (!check[i]) { PG_RETURN_BOOL(true); } diff --git a/src/output.c b/src/output.c index 7598d46..1eb6414 100644 --- a/src/output.c +++ b/src/output.c @@ -11,10 +11,10 @@ /* Output modes */ -#define OUTPUT_RAD 1 /* output in radians */ -#define OUTPUT_DEG 2 /* output in degrees */ -#define OUTPUT_DMS 3 /* output in degrees, minutes, seconds */ -#define OUTPUT_HMS 4 /* output in hour, minutes, seconds */ +#define OUTPUT_RAD 1 /* output in radians */ +#define OUTPUT_DEG 2 /* output in degrees */ +#define OUTPUT_DMS 3 /* output in degrees, minutes, seconds */ +#define OUTPUT_HMS 4 /* output in hour, minutes, seconds */ /*. * Holds the current output modus. @@ -25,7 +25,7 @@ static unsigned char sphere_output = OUTPUT_RAD; /* * Defines the precision of floating point values in output. */ -static int sphere_output_precision = DBL_DIG; +static int sphere_output_precision = DBL_DIG; PG_FUNCTION_INFO_V1(set_sphere_output); PG_FUNCTION_INFO_V1(spherepoint_out); @@ -42,72 +42,73 @@ PG_FUNCTION_INFO_V1(pg_sphere_version); /* * Sets the output modus. */ -Datum set_sphere_output(PG_FUNCTION_ARGS); +Datum set_sphere_output(PG_FUNCTION_ARGS); /* * Sets the output precision. */ -Datum set_sphere_output_precision(PG_FUNCTION_ARGS); +Datum set_sphere_output_precision(PG_FUNCTION_ARGS); /* * The output function of spherical point. */ -Datum spherepoint_out(PG_FUNCTION_ARGS); +Datum spherepoint_out(PG_FUNCTION_ARGS); /* * The output function of spherical circle. */ -Datum spherecircle_out(PG_FUNCTION_ARGS); +Datum spherecircle_out(PG_FUNCTION_ARGS); /* * The output function of spherical line. */ -Datum sphereline_out(PG_FUNCTION_ARGS); +Datum sphereline_out(PG_FUNCTION_ARGS); /* * The output function of Euler transformation. */ -Datum spheretrans_out(PG_FUNCTION_ARGS); +Datum spheretrans_out(PG_FUNCTION_ARGS); /* * The output function of spherical polygon. */ -Datum spherepoly_out(PG_FUNCTION_ARGS); +Datum spherepoly_out(PG_FUNCTION_ARGS); /* * The output function of spherical path. */ -Datum spherepath_out(PG_FUNCTION_ARGS); +Datum spherepath_out(PG_FUNCTION_ARGS); /* * The output function of spherical ellipse. */ -Datum sphereellipse_out(PG_FUNCTION_ARGS); +Datum sphereellipse_out(PG_FUNCTION_ARGS); /* * The output function of spherical box. */ -Datum spherebox_out(PG_FUNCTION_ARGS); +Datum spherebox_out(PG_FUNCTION_ARGS); /* * Returns pg_sphere version. */ -Datum pg_sphere_version(PG_FUNCTION_ARGS); +Datum pg_sphere_version(PG_FUNCTION_ARGS); - /* + /* -------- * Converts radians to DEG ( degrees, minutes, seconds ) * * rad - input in radians * deg - pointer to degrees * min - pointer to minutes * sec - pointer to seconds + * -------- */ static void rad_to_dms(double rad, unsigned int *deg, unsigned int *min, double *sec) { - double rsign = rad < 0 ? -1 : 1; - const double sec_dig = pow(10, FLT_DIG); + double rsign = rad < 0 ? -1 : 1; + const double sec_dig = pow(10, FLT_DIG); rad *= (rsign * RADIANS); @@ -179,14 +180,14 @@ set_sphere_output(PG_FUNCTION_ARGS) Datum spherepoint_out(PG_FUNCTION_ARGS) { - SPoint *sp = (SPoint *) PG_GETARG_POINTER(0); - char *buffer = (char *) palloc(255); - unsigned int latdeg, - latmin, - lngdeg, - lngmin; - double latsec, - lngsec; + SPoint *sp = (SPoint *) PG_GETARG_POINTER(0); + char *buffer = (char *) palloc(255); + unsigned int latdeg, + latmin, + lngdeg, + lngmin; + double latsec, + lngsec; latdeg = latmin = lngdeg = lngmin = 0; latsec = lngsec = 0.0; @@ -235,9 +236,8 @@ spherecircle_out(PG_FUNCTION_ARGS) { SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); - char *pointstr = DatumGetPointer( - DirectFunctionCall1(spherepoint_out, - PointerGetDatum(&c->center))); + char *pointstr = DatumGetPointer(DirectFunctionCall1(spherepoint_out, + PointerGetDatum(&c->center))); unsigned int rdeg, rmin; @@ -266,7 +266,7 @@ spherecircle_out(PG_FUNCTION_ARGS) break; default: - sprintf(buffer, "<%s , %.*g>", + sprintf(buffer, "<%s , %.*g>", pointstr, sphere_output_precision, c->radius); break; } @@ -320,12 +320,12 @@ sphereellipse_out(PG_FUNCTION_ARGS) default: sprintf( - buffer, - "<{ %.*g , %.*g }, %s , %.*g>", - sphere_output_precision, e->rad[0], - sphere_output_precision, e->rad[1], - pointstr, - sphere_output_precision, e->phi); + buffer, + "<{ %.*g , %.*g }, %s , %.*g>", + sphere_output_precision, e->rad[0], + sphere_output_precision, e->rad[1], + pointstr, + sphere_output_precision, e->phi); break; } @@ -336,14 +336,14 @@ sphereellipse_out(PG_FUNCTION_ARGS) Datum sphereline_out(PG_FUNCTION_ARGS) { - SLine *sl = (SLine *) PG_GETARG_POINTER(0); - char *out = (char *) palloc(255); - char *tstr = NULL; - SEuler se; + SLine *sl = (SLine *) PG_GETARG_POINTER(0); + char *out = (char *) palloc(255); + char *tstr = NULL; + SEuler se; - unsigned int rdeg, - rmin; - double rsec; + unsigned int rdeg, + rmin; + double rsec; rdeg = rmin = 0; rsec = 0.0; @@ -522,12 +522,10 @@ spherebox_out(PG_FUNCTION_ARGS) { SBOX *box = (SBOX *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); - char *str1 = DatumGetPointer( - DirectFunctionCall1(spherepoint_out, - PointerGetDatum(&box->sw))); - char *str2 = DatumGetPointer( - DirectFunctionCall1(spherepoint_out, - PointerGetDatum(&box->ne))); + char *str1 = DatumGetPointer(DirectFunctionCall1(spherepoint_out, + PointerGetDatum(&box->sw))); + char *str2 = DatumGetPointer(DirectFunctionCall1(spherepoint_out, + PointerGetDatum(&box->ne))); sprintf(buffer, "(%s, %s)", str1, str2); pfree(str1); @@ -538,8 +536,9 @@ spherebox_out(PG_FUNCTION_ARGS) Datum pg_sphere_version(PG_FUNCTION_ARGS) { - const char *s = PGSPHERE_STRINGIFY(PGSPHERE_VERSION); - char *p = (char *)palloc(strlen(s) + 1); + const char *s = PGSPHERE_STRINGIFY(PGSPHERE_VERSION); + char *p = (char *) palloc(strlen(s) + 1); + strcpy(p, s); PG_RETURN_CSTRING(p); } diff --git a/src/path.c b/src/path.c index f6d9495..a59f713 100644 --- a/src/path.c +++ b/src/path.c @@ -66,7 +66,7 @@ PG_FUNCTION_INFO_V1(spherepath_get_array); static SPATH * spherepath_from_array(SPoint *arr, int32 nelem) { - SPATH *path = NULL; + SPATH *path = NULL; if (nelem < 2) { @@ -76,9 +76,9 @@ spherepath_from_array(SPoint *arr, int32 nelem) else { - int32 i; - float8 scheck; - int32 size; + int32 i; + float8 scheck; + int32 size; for (i = 0; i < nelem; i++) { @@ -110,7 +110,7 @@ spherepath_from_array(SPoint *arr, int32 nelem) return NULL; } - size = offsetof(SPATH, p[0]) +sizeof(path->p[0]) * nelem; + size = offsetof(SPATH, p[0]) + sizeof(path->p[0]) * nelem; path = (SPATH *) palloc(size); SET_VARSIZE(path, size); path->npts = nelem; @@ -146,7 +146,7 @@ spherepath_from_array(SPoint *arr, int32 nelem) static void euler_spath_trans(SPATH *out, const SPATH *in, const SEuler *se) { - int32 i; + int32 i; SET_VARSIZE(out, VARSIZE(in)); out->npts = in->npts; @@ -220,9 +220,9 @@ path_circle_pos(const SPATH *path, const SCIRCLE *circ) static bool path_line_overlap(const SPATH *path, const SLine *line) { - int32 i; - SLine sl; - int32 n; + int32 i; + SLine sl; + int32 n; n = path->npts - 1; @@ -261,8 +261,8 @@ path_ellipse_pos(const SPATH *path, const SELLIPSE *ell) if (FPzero(ell->rad[0])) { - bool pcp; - SPoint cen; + bool pcp; + SPoint cen; sellipse_center(&cen, ell); pcp = spath_cont_point(path, &cen); @@ -278,7 +278,7 @@ path_ellipse_pos(const SPATH *path, const SELLIPSE *ell) if (FPzero(ell->rad[1])) { - SLine l; + SLine l; sellipse_line(&l, ell); /* TODO implement ellipse contains path if ellipse is a line */ @@ -326,8 +326,8 @@ path_ellipse_pos(const SPATH *path, const SELLIPSE *ell) static bool path_overlap(const SPATH *path1, const SPATH *path2) { - int32 i; - SLine sl; + int32 i; + SLine sl; for (i = 0; i < path1->npts; i++) { @@ -368,7 +368,7 @@ path_poly_pos(const SPATH *path, const SPOLY *poly) pos = (1 << poly_line_pos(poly, &sl)); if (pos == sp_ov) { - return PGS_POLY_PATH_OVER; /* overlap */ + return PGS_POLY_PATH_OVER; /* overlap */ } res |= pos; } @@ -385,7 +385,7 @@ path_poly_pos(const SPATH *path, const SPOLY *poly) } - /* + /* -------- * Returns the i-th point of a path. * * sp - pointer to the result point @@ -393,6 +393,7 @@ path_poly_pos(const SPATH *path, const SPOLY *poly) * i - number of the point * * See spath_point(SPoint * , SPATH *, float8) + * -------- */ static bool spath_get_point(SPoint *sp, const SPATH *path, int32 i) @@ -405,7 +406,7 @@ spath_get_point(SPoint *sp, const SPATH *path, int32 i) return false; } - /* + /* -------- * This function interpolates between points. Returns the f-th point * of a path. * @@ -414,6 +415,7 @@ spath_get_point(SPoint *sp, const SPATH *path, int32 i) * f - 'number' of the point * * See spherepath_point(PG_FUNCTION_ARGS) + * -------- */ static bool spath_point(SPoint *sp, const SPATH *path, float8 f) @@ -425,8 +427,8 @@ spath_point(SPoint *sp, const SPATH *path, float8 f) if (spath_segment(&sl, path, i)) { - SEuler se; - SPoint tp; + SEuler se; + SPoint tp; sphereline_to_euler(&se, &sl); @@ -449,8 +451,8 @@ spath_eq(const SPATH *p1, const SPATH *p2) { if (p1->npts == p2->npts) { - int32 i; - bool ret; + int32 i; + bool ret; ret = true; @@ -470,10 +472,10 @@ spath_eq(const SPATH *p1, const SPATH *p2) bool spath_cont_point(const SPATH *path, const SPoint *sp) { - int32 n; - bool ret; - SLine sl; - int32 i; + int32 n; + bool ret; + SLine sl; + int32 i; n = path->npts - 1; ret = false; @@ -507,7 +509,8 @@ spherepath_in(PG_FUNCTION_ARGS) { SPATH *path; char *c = PG_GETARG_CSTRING(0); - int32 i, nelem; + int32 i, + nelem; void sphere_yyparse(void); init_buffer(c); @@ -561,25 +564,25 @@ spherepath_get_point(PG_FUNCTION_ARGS) Datum spherepath_get_array(PG_FUNCTION_ARGS) { - SPATH *path = PG_GETARG_SPATH(0); - Datum *datum_arr = (Datum *) palloc(sizeof(Datum) * path->npts); - ArrayType *res; - SPoint *p = (SPoint *) palloc(sizeof(SPoint) * path->npts); - - for (size_t i = 0; i < path->npts; i++) - { - if (!spath_get_point(&p[i], path, i)) - { - pfree(p); - pfree(datum_arr); - PG_RETURN_NULL(); - } - datum_arr[i] = PointerGetDatum(&p[i]); - } - - res = construct_array(datum_arr, path->npts, get_spoint_type_oid(), sizeof(SPoint), false, 'd'); - - PG_RETURN_ARRAYTYPE_P(res); + SPATH *path = PG_GETARG_SPATH(0); + Datum *datum_arr = (Datum *) palloc(sizeof(Datum) * path->npts); + ArrayType *res; + SPoint *p = (SPoint *) palloc(sizeof(SPoint) * path->npts); + + for (size_t i = 0; i < path->npts; i++) + { + if (!spath_get_point(&p[i], path, i)) + { + pfree(p); + pfree(datum_arr); + PG_RETURN_NULL(); + } + datum_arr[i] = PointerGetDatum(&p[i]); + } + + res = construct_array(datum_arr, path->npts, get_spoint_type_oid(), sizeof(SPoint), false, 'd'); + + PG_RETURN_ARRAYTYPE_P(res); } Datum diff --git a/src/path.h b/src/path.h index 91e1662..150dbb0 100644 --- a/src/path.h +++ b/src/path.h @@ -12,22 +12,22 @@ */ typedef struct { - char vl_len_[4]; /* total size in bytes */ - int32 npts; /* count of points */ - SPoint p[1]; /* variable length array of SPoints */ + char vl_len_[4]; /* total size in bytes */ + int32 npts; /* count of points */ + SPoint p[1]; /* variable length array of SPoints */ } SPATH; /* Path and circle */ -#define PGS_CIRCLE_PATH_AVOID 0 /* circle avoids path */ -#define PGS_CIRCLE_CONT_PATH 1 /* circle contains path */ -#define PGS_CIRCLE_PATH_OVER 2 /* circle overlaps path */ +#define PGS_CIRCLE_PATH_AVOID 0 /* circle avoids path */ +#define PGS_CIRCLE_CONT_PATH 1 /* circle contains path */ +#define PGS_CIRCLE_PATH_OVER 2 /* circle overlaps path */ /* Path and polygon */ -#define PGS_POLY_PATH_AVOID 0 /* polygon avoids path */ -#define PGS_POLY_CONT_PATH 1 /* polygon contains path */ -#define PGS_POLY_PATH_OVER 2 /* polygon and path overlap */ +#define PGS_POLY_PATH_AVOID 0 /* polygon avoids path */ +#define PGS_POLY_CONT_PATH 1 /* polygon contains path */ +#define PGS_POLY_PATH_OVER 2 /* polygon and path overlap */ /* Path and ellipse */ #define PGS_ELLIPSE_PATH_AVOID 0 /* ellipse avoids path */ @@ -41,12 +41,12 @@ typedef struct /* * Checks whether two paths are equal. */ -bool spath_eq(const SPATH *p1, const SPATH *p2); +bool spath_eq(const SPATH *p1, const SPATH *p2); /* * Checks whether a path contains a point. */ -bool spath_cont_point(const SPATH *path, const SPoint *sp); +bool spath_cont_point(const SPATH *path, const SPoint *sp); /* * Returns the i-th line segment of a path. @@ -57,24 +57,24 @@ bool spath_cont_point(const SPATH *path, const SPoint *sp); * * Returns the pointer to the line segment or NULL if fails. */ -bool spath_segment(SLine *sl, const SPATH *path, int32 i); +bool spath_segment(SLine *sl, const SPATH *path, int32 i); /* * Input function of path. */ -Datum spherepath_in(PG_FUNCTION_ARGS); +Datum spherepath_in(PG_FUNCTION_ARGS); /* * Returns the n-th point of a path. * * See spherepath_get_point(PG_FUNCTION_ARGS) */ -Datum spherepath_get_point(PG_FUNCTION_ARGS); +Datum spherepath_get_point(PG_FUNCTION_ARGS); /* * Returns spath as array of points */ -Datum spherepath_get_array(PG_FUNCTION_ARGS); +Datum spherepath_get_array(PG_FUNCTION_ARGS); /* * This function interpolates between points of path. Returns the @@ -82,212 +82,212 @@ Datum spherepath_get_array(PG_FUNCTION_ARGS); * * See spherepath_point(PG_FUNCTION_ARGS) */ -Datum spherepath_point(PG_FUNCTION_ARGS); +Datum spherepath_point(PG_FUNCTION_ARGS); /* * Checks whether two paths are equal. */ -Datum spherepath_equal(PG_FUNCTION_ARGS); +Datum spherepath_equal(PG_FUNCTION_ARGS); /* * Checks whether two paths aren't equal. */ -Datum spherepath_equal_neg(PG_FUNCTION_ARGS); +Datum spherepath_equal_neg(PG_FUNCTION_ARGS); /* * Returns the length of a path. */ -Datum spherepath_length(PG_FUNCTION_ARGS); +Datum spherepath_length(PG_FUNCTION_ARGS); /* * Returns the number of points in a path. */ -Datum spherepath_npts(PG_FUNCTION_ARGS); +Datum spherepath_npts(PG_FUNCTION_ARGS); /* * Changes the direction of a path. */ -Datum spherepath_swap(PG_FUNCTION_ARGS); +Datum spherepath_swap(PG_FUNCTION_ARGS); /* * Checks whether a path contains a point. */ -Datum spherepath_cont_point(PG_FUNCTION_ARGS); +Datum spherepath_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a path doesn't contain a point. */ -Datum spherepath_cont_point_neg(PG_FUNCTION_ARGS); +Datum spherepath_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a path contains a point. */ -Datum spherepath_cont_point_com(PG_FUNCTION_ARGS); +Datum spherepath_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a path doesn't contain a point. */ -Datum spherepath_cont_point_com_neg(PG_FUNCTION_ARGS); +Datum spherepath_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a path and a line overlap. */ -Datum spherepath_overlap_line(PG_FUNCTION_ARGS); +Datum spherepath_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether a path and a line don't overlap. */ -Datum spherepath_overlap_line_neg(PG_FUNCTION_ARGS); +Datum spherepath_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether path and line overlap. */ -Datum spherepath_overlap_line_com(PG_FUNCTION_ARGS); +Datum spherepath_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether a path and a line don't overlap. */ -Datum spherepath_overlap_line_com_neg(PG_FUNCTION_ARGS); +Datum spherepath_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a path. */ -Datum spherecircle_cont_path(PG_FUNCTION_ARGS); +Datum spherecircle_cont_path(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a path. */ -Datum spherecircle_cont_path_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a path. */ -Datum spherecircle_cont_path_com(PG_FUNCTION_ARGS); +Datum spherecircle_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a path. */ -Datum spherecircle_cont_path_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path overlap. */ -Datum spherecircle_overlap_path(PG_FUNCTION_ARGS); +Datum spherecircle_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path don't overlap. */ -Datum spherecircle_overlap_path_neg(PG_FUNCTION_ARGS); +Datum spherecircle_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path overlap. */ -Datum spherecircle_overlap_path_com(PG_FUNCTION_ARGS); +Datum spherecircle_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path don't overlap. */ -Datum spherecircle_overlap_path_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a path. */ -Datum spherepoly_cont_path(PG_FUNCTION_ARGS); +Datum spherepoly_cont_path(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a path. */ -Datum spherepoly_cont_path_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains path. */ -Datum spherepoly_cont_path_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a path. */ -Datum spherepoly_cont_path_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path overlap. */ -Datum spherepoly_overlap_path(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path don't overlap. */ -Datum spherepoly_overlap_path_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path overlap. */ -Datum spherepoly_overlap_path_com(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path don't overlap. */ -Datum spherepoly_overlap_path_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two paths overlap. */ -Datum spherepath_overlap_path(PG_FUNCTION_ARGS); +Datum spherepath_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether two paths don't overlap. */ -Datum spherepath_overlap_path_neg(PG_FUNCTION_ARGS); +Datum spherepath_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains path. */ -Datum sphereellipse_cont_path(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_path(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a path. */ -Datum sphereellipse_cont_path_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a path. */ -Datum sphereellipse_cont_path_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a path. */ -Datum sphereellipse_cont_path_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path overlap. */ -Datum sphereellipse_overlap_path(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path don't overlap. */ -Datum sphereellipse_overlap_path_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path overlap. */ -Datum sphereellipse_overlap_path_com(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path don't overlap. */ -Datum sphereellipse_overlap_path_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Performs an Euler transformation on a path. */ -Datum spheretrans_path(PG_FUNCTION_ARGS); +Datum spheretrans_path(PG_FUNCTION_ARGS); /* * Performs an inverse Euler transformation on a path. */ -Datum spheretrans_path_inverse(PG_FUNCTION_ARGS); +Datum spheretrans_path_inverse(PG_FUNCTION_ARGS); /* * State transition function for aggregate function spath(spoint). Never @@ -295,11 +295,11 @@ Datum spheretrans_path_inverse(PG_FUNCTION_ARGS); * * Adds a point to a path. */ -Datum spherepath_add_point(PG_FUNCTION_ARGS); +Datum spherepath_add_point(PG_FUNCTION_ARGS); /* * Finalize function for adding spoints to a path. */ -Datum spherepath_add_points_finalize(PG_FUNCTION_ARGS); +Datum spherepath_add_points_finalize(PG_FUNCTION_ARGS); #endif diff --git a/src/pg_sphere.h b/src/pg_sphere.h index 24d950a..160612b 100644 --- a/src/pg_sphere.h +++ b/src/pg_sphere.h @@ -72,7 +72,7 @@ #else #define PGSPHERE_FLOAT_STORE 0 #endif -#endif // PGSPHERE_FLOAT_STORE +#endif /* PGSPHERE_FLOAT_STORE */ #define EPSILON 1.0E-09 @@ -84,6 +84,7 @@ static inline bool FPeq(double A, double B) { const volatile double AB = A - B; + return A == B || fabs(AB) <= EPSILON; } @@ -91,6 +92,7 @@ static inline bool FPne(double A, double B) { const volatile double AB = A - B; + return A != B && fabs(AB) > EPSILON; } @@ -98,6 +100,7 @@ static inline bool FPlt(double A, double B) { const volatile double AE = A + EPSILON; + return AE < B; } @@ -105,6 +108,7 @@ static inline bool FPle(double A, double B) { const volatile double BE = B + EPSILON; + return A <= BE; } @@ -112,6 +116,7 @@ static inline bool FPgt(double A, double B) { const volatile double BE = B + EPSILON; + return A > BE; } @@ -119,6 +124,7 @@ static inline bool FPge(double A, double B) { const volatile double AE = A + EPSILON; + return AE >= B; } @@ -160,7 +166,7 @@ FPge(double A, double B) return A + EPSILON >= B; } -#endif // PGSPHERE_FLOAT_STORE +#endif /* PGSPHERE_FLOAT_STORE */ /*--------------------------------------------------------------------- * Point - (x,y) @@ -171,7 +177,6 @@ typedef struct y; } Point; -void sphere_yyparse(void); +void sphere_yyparse(void); #endif - diff --git a/src/pgs_chealpix.h b/src/pgs_chealpix.h index c3233d1..f15b4fe 100644 --- a/src/pgs_chealpix.h +++ b/src/pgs_chealpix.h @@ -2,7 +2,7 @@ #define __PGS_CHEALPIX_H__ #include -#include /* PostgreSQL type definitions */ +#include /* PostgreSQL type definitions */ /* * Actually, chealpix changed its API: thus, this file must be included first, * directly or indirectly. diff --git a/src/pgs_healpix.h b/src/pgs_healpix.h index f6e4e65..a25b737 100644 --- a/src/pgs_healpix.h +++ b/src/pgs_healpix.h @@ -7,28 +7,28 @@ #include #include -#include "point.h" /* SPoint */ +#include "point.h" /* SPoint */ -int order_invalid(int); -hpint64 c_npix(int); -void check_order(int order); +int order_invalid(int); +hpint64 c_npix(int); +void check_order(int order); /* function prototypes for the Healpix support functions */ -Datum pg_nest2ring(PG_FUNCTION_ARGS); -Datum pg_ring2nest(PG_FUNCTION_ARGS); -hpint64 c_healpix_convert_nest(hpint64 idx, int32 from_order, int32 to_order); -Datum healpix_convert_nest(PG_FUNCTION_ARGS); -Datum healpix_convert_ring(PG_FUNCTION_ARGS); -Datum pg_nside2order(PG_FUNCTION_ARGS); -Datum pg_order2nside(PG_FUNCTION_ARGS); -Datum pg_nside2npix(PG_FUNCTION_ARGS); -Datum pg_npix2nside(PG_FUNCTION_ARGS); -Datum healpix_nest(PG_FUNCTION_ARGS); -Datum healpix_ring(PG_FUNCTION_ARGS); -Datum inv_healpix_nest(PG_FUNCTION_ARGS); -Datum inv_healpix_ring(PG_FUNCTION_ARGS); - -hpint64 healpix_nest_c(int32, SPoint*); +Datum pg_nest2ring(PG_FUNCTION_ARGS); +Datum pg_ring2nest(PG_FUNCTION_ARGS); +hpint64 c_healpix_convert_nest(hpint64 idx, int32 from_order, int32 to_order); +Datum healpix_convert_nest(PG_FUNCTION_ARGS); +Datum healpix_convert_ring(PG_FUNCTION_ARGS); +Datum pg_nside2order(PG_FUNCTION_ARGS); +Datum pg_order2nside(PG_FUNCTION_ARGS); +Datum pg_nside2npix(PG_FUNCTION_ARGS); +Datum pg_npix2nside(PG_FUNCTION_ARGS); +Datum healpix_nest(PG_FUNCTION_ARGS); +Datum healpix_ring(PG_FUNCTION_ARGS); +Datum inv_healpix_nest(PG_FUNCTION_ARGS); +Datum inv_healpix_ring(PG_FUNCTION_ARGS); + +hpint64 healpix_nest_c(int32, SPoint *); #endif diff --git a/src/pgs_moc.h b/src/pgs_moc.h index 6bad1ae..5871026 100644 --- a/src/pgs_moc.h +++ b/src/pgs_moc.h @@ -14,19 +14,19 @@ #include #endif -#include "point.h" /* SPoint */ +#include "point.h" /* SPoint */ /* * MOC data type(s) * ... - * - * - * - * - * - * - * - * + * + * + * + * + * + * + * + * */ /* das hier ist Mist: typedef moc_interval moc_leaf_page[MOC_PAGE_SIZE]; */ @@ -55,64 +55,64 @@ exactly PG_TOAST_PAGE_FRAGMENT... /* function prototypes for the MOC support functions */ -Datum smoc_in(PG_FUNCTION_ARGS); -Datum smoc_out(PG_FUNCTION_ARGS); -Datum moc_debug(PG_FUNCTION_ARGS); -Datum set_smoc_output_type(PG_FUNCTION_ARGS); -Datum smoc_info(PG_FUNCTION_ARGS); -Datum smoc_area(PG_FUNCTION_ARGS); -Datum smoc_order(PG_FUNCTION_ARGS); -Datum smoc_eq(PG_FUNCTION_ARGS); -Datum smoc_neq(PG_FUNCTION_ARGS); -Datum smoc_overlap(PG_FUNCTION_ARGS); -Datum smoc_overlap_neg(PG_FUNCTION_ARGS); -Datum smoc_subset_smoc(PG_FUNCTION_ARGS); -Datum smoc_subset_smoc_neg(PG_FUNCTION_ARGS); -Datum smoc_superset_smoc(PG_FUNCTION_ARGS); -Datum smoc_superset_smoc_neg(PG_FUNCTION_ARGS); - -Datum healpix_subset_smoc(PG_FUNCTION_ARGS); -Datum healpix_not_subset_smoc(PG_FUNCTION_ARGS); -Datum smoc_superset_healpix(PG_FUNCTION_ARGS); -Datum smoc_not_superset_healpix(PG_FUNCTION_ARGS); -Datum spoint_subset_smoc(PG_FUNCTION_ARGS); -Datum spoint_not_subset_smoc(PG_FUNCTION_ARGS); -Datum smoc_superset_spoint(PG_FUNCTION_ARGS); -Datum smoc_not_superset_spoint(PG_FUNCTION_ARGS); - -bool healpix_subset_smoc_impl(hpint64, Datum); -bool spoint_subset_smoc_impl(SPoint*, Datum); -Datum healpix_subset_smoc_c(hpint64, Datum); -Datum healpix_not_subset_smoc_c(hpint64, Datum); -Datum spoint_subset_smoc_c(SPoint*, Datum); -Datum spoint_not_subset_smoc_c(SPoint*, Datum); - -Datum smoc_union(PG_FUNCTION_ARGS); -Datum smoc_intersection(PG_FUNCTION_ARGS); -Datum smoc_degrade(PG_FUNCTION_ARGS); -Datum smoc_spoint(PG_FUNCTION_ARGS); -Datum smoc_disc(PG_FUNCTION_ARGS); -Datum smoc_scircle(PG_FUNCTION_ARGS); -Datum smoc_spoly(PG_FUNCTION_ARGS); - -Datum smoc_gin_extract_value(PG_FUNCTION_ARGS); -Datum smoc_gin_extract_value_fine(PG_FUNCTION_ARGS); -Datum smoc_gin_extract_query(PG_FUNCTION_ARGS); -Datum smoc_gin_extract_query_fine(PG_FUNCTION_ARGS); -Datum smoc_gin_consistent(PG_FUNCTION_ARGS); +Datum smoc_in(PG_FUNCTION_ARGS); +Datum smoc_out(PG_FUNCTION_ARGS); +Datum moc_debug(PG_FUNCTION_ARGS); +Datum set_smoc_output_type(PG_FUNCTION_ARGS); +Datum smoc_info(PG_FUNCTION_ARGS); +Datum smoc_area(PG_FUNCTION_ARGS); +Datum smoc_order(PG_FUNCTION_ARGS); +Datum smoc_eq(PG_FUNCTION_ARGS); +Datum smoc_neq(PG_FUNCTION_ARGS); +Datum smoc_overlap(PG_FUNCTION_ARGS); +Datum smoc_overlap_neg(PG_FUNCTION_ARGS); +Datum smoc_subset_smoc(PG_FUNCTION_ARGS); +Datum smoc_subset_smoc_neg(PG_FUNCTION_ARGS); +Datum smoc_superset_smoc(PG_FUNCTION_ARGS); +Datum smoc_superset_smoc_neg(PG_FUNCTION_ARGS); + +Datum healpix_subset_smoc(PG_FUNCTION_ARGS); +Datum healpix_not_subset_smoc(PG_FUNCTION_ARGS); +Datum smoc_superset_healpix(PG_FUNCTION_ARGS); +Datum smoc_not_superset_healpix(PG_FUNCTION_ARGS); +Datum spoint_subset_smoc(PG_FUNCTION_ARGS); +Datum spoint_not_subset_smoc(PG_FUNCTION_ARGS); +Datum smoc_superset_spoint(PG_FUNCTION_ARGS); +Datum smoc_not_superset_spoint(PG_FUNCTION_ARGS); + +bool healpix_subset_smoc_impl(hpint64, Datum); +bool spoint_subset_smoc_impl(SPoint *, Datum); +Datum healpix_subset_smoc_c(hpint64, Datum); +Datum healpix_not_subset_smoc_c(hpint64, Datum); +Datum spoint_subset_smoc_c(SPoint *, Datum); +Datum spoint_not_subset_smoc_c(SPoint *, Datum); + +Datum smoc_union(PG_FUNCTION_ARGS); +Datum smoc_intersection(PG_FUNCTION_ARGS); +Datum smoc_degrade(PG_FUNCTION_ARGS); +Datum smoc_spoint(PG_FUNCTION_ARGS); +Datum smoc_disc(PG_FUNCTION_ARGS); +Datum smoc_scircle(PG_FUNCTION_ARGS); +Datum smoc_spoly(PG_FUNCTION_ARGS); + +Datum smoc_gin_extract_value(PG_FUNCTION_ARGS); +Datum smoc_gin_extract_value_fine(PG_FUNCTION_ARGS); +Datum smoc_gin_extract_query(PG_FUNCTION_ARGS); +Datum smoc_gin_extract_query_fine(PG_FUNCTION_ARGS); +Datum smoc_gin_consistent(PG_FUNCTION_ARGS); /* parsing subroutines */ -hpint64 readNumber(const char*, int*); -char readChar(const char*, int*); +hpint64 readNumber(const char *, int *); +char readChar(const char *, int *); static inline int32 next_interval(int32 a) { - int32 mod; + int32 mod; a += MOC_INTERVAL_SIZE; - // page bumps + /* page bumps */ mod = (a + MOC_INTERVAL_SIZE) % PG_TOAST_PAGE_FRAGMENT; if (mod > 0 && mod < MOC_INTERVAL_SIZE) a += MOC_INTERVAL_SIZE - mod; @@ -122,8 +122,8 @@ next_interval(int32 a) #define MOC_AREA_ALL_SKY 3458764513820540928 -#define MOC_GIN_ORDER 5 /* order 5 has 12 * 4^5 = 12288 pixels */ -#define MOC_GIN_ORDER_FINE 8 /* order 8 has 12 * 4^8 = 786432 pixels */ +#define MOC_GIN_ORDER 5 /* order 5 has 12 * 4^5 = 12288 pixels */ +#define MOC_GIN_ORDER_FINE 8 /* order 8 has 12 * 4^8 = 786432 pixels */ #define MOC_GIN_STRATEGY_INTERSECTS 1 #define MOC_GIN_STRATEGY_SUBSET 2 #define MOC_GIN_STRATEGY_SUPERSET 3 diff --git a/src/pgs_util.h b/src/pgs_util.h index b79170b..919d9d9 100644 --- a/src/pgs_util.h +++ b/src/pgs_util.h @@ -1,24 +1,25 @@ #ifndef __PGS_UTIL_H__ #define __PGS_UTIL_H__ -#define PI 3.14159265358979323846 /* pi */ -#define PIH 1.57079632679489661923 /* pi/2 */ -#define PID 6.2831853071795864769 /* 2*pi */ -#define RADIANS 57.295779513082320877 /* 180/pi */ +#define PI 3.14159265358979323846 /* pi */ +#define PIH 1.57079632679489661923 /* pi/2 */ +#define PID 6.2831853071795864769 /* 2*pi */ +#define RADIANS 57.295779513082320877 /* 180/pi */ #define PI_EPS 4.4408920985006261617e-16 /* 2 ** -51 */ -#define Sqr(a) ( (a) * (a) ) /* square function as macro */ +#define Sqr(a) ( (a) * (a) ) /* square function as macro */ #ifdef EPSILON #undef EPSILON #endif -#define EPSILON 1.0E-09 /* precision of floating point values */ +#define EPSILON 1.0E-09 /* precision of floating point values */ /* convert pg_sphere theta [pi/2 .. -pi/2] to healpix theta [0 .. pi] ([north .. south pole]) */ static inline double conv_theta(double x) { - double y = PIH - x; + double y = PIH - x; + if (fabs(x) < PI_EPS / 2) return PIH; if (fabs(y) < PI_EPS / 2) @@ -26,7 +27,8 @@ conv_theta(double x) return y; } -static inline double deg_to_rad(double in) +static inline double +deg_to_rad(double in) { return in * PI / 180; } diff --git a/src/point.c b/src/point.c index 0cbfa00..5cf2495 100644 --- a/src/point.c +++ b/src/point.c @@ -16,9 +16,10 @@ PG_FUNCTION_INFO_V1(spherepoint_z); PG_FUNCTION_INFO_V1(spherepoint_xyz); PG_FUNCTION_INFO_V1(spherepoint_equal); -static Oid point_id = InvalidOid; +static Oid point_id = InvalidOid; -Oid get_spoint_type_oid(void) +Oid +get_spoint_type_oid(void) { if (point_id == InvalidOid) { @@ -41,7 +42,7 @@ spoint_eq(const SPoint *p1, const SPoint *p2) void spoint_check(SPoint *spoint) { - bool lat_is_neg = (spoint->lat < 0) ? true : false; + bool lat_is_neg = (spoint->lat < 0) ? true : false; if (spoint->lng < 0 || spoint->lng > PID) spoint->lng = spoint->lng - floor(spoint->lng / (PID)) * PID; @@ -85,7 +86,7 @@ spoint_check(SPoint *spoint) void vector3d_spoint(SPoint *p, const Vector3D *v) { - double rho = sqrt((v->x) * (v->x) + (v->y) * (v->y)); + double rho = sqrt((v->x) * (v->x) + (v->y) * (v->y)); if (0.0 == rho) { @@ -155,7 +156,8 @@ spherepoint_in(PG_FUNCTION_ARGS) PG_RETURN_POINTER(sp); } -void create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat) +void +create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat) { p->lat = lat; p->lng = lng; @@ -165,10 +167,11 @@ void create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat) Datum spherepoint_from_long_lat(PG_FUNCTION_ARGS) { - SPoint *p = (SPoint *) palloc(sizeof(SPoint)); + SPoint *p = (SPoint *) palloc(sizeof(SPoint)); const float8 lng = PG_GETARG_FLOAT8(0); const float8 lat = PG_GETARG_FLOAT8(1); + create_spherepoint_from_long_lat(p, lng, lat); PG_RETURN_POINTER(p); } @@ -176,14 +179,13 @@ spherepoint_from_long_lat(PG_FUNCTION_ARGS) Datum spherepoint_from_long_lat_deg(PG_FUNCTION_ARGS) { - Datum res; + Datum res; const float8 lng = deg_to_rad(PG_GETARG_FLOAT8(0)); const float8 lat = deg_to_rad(PG_GETARG_FLOAT8(1)); - res = DirectFunctionCall2( - spherepoint_from_long_lat, - Float8GetDatum(lng), - Float8GetDatum(lat) - ); + + res = DirectFunctionCall2(spherepoint_from_long_lat, + Float8GetDatum(lng), + Float8GetDatum(lat)); PG_RETURN_DATUM(res); } @@ -196,13 +198,15 @@ norm2(double a, double b) float8 spoint_dist(const SPoint *p1, const SPoint *p2) { - float8 dl = p1->lng - p2->lng; + float8 dl = p1->lng - p2->lng; + /* use Vincenty's formula for the inverse geodesic problem on the sphere */ - float8 f = atan2(norm2(cos(p2->lat) * sin(dl), - cos(p1->lat) * sin(p2->lat) + float8 f = atan2(norm2(cos(p2->lat) * sin(dl), + cos(p1->lat) * sin(p2->lat) - sin(p1->lat) * cos(p2->lat) * cos(dl)), - sin(p1->lat) * sin(p2->lat) - + cos(p1->lat) * cos(p2->lat) * cos(dl)); + sin(p1->lat) * sin(p2->lat) + + cos(p1->lat) * cos(p2->lat) * cos(dl)); + if (FPzero(f)) { return 0.0; diff --git a/src/point.h b/src/point.h index 9269cf7..79cbbdd 100644 --- a/src/point.h +++ b/src/point.h @@ -11,95 +11,95 @@ */ typedef struct { - float8 lng; /* longitude value in radians */ - float8 lat; /* latitude value in radians */ + float8 lng; /* longitude value in radians */ + float8 lat; /* latitude value in radians */ } SPoint; -Oid get_spoint_type_oid(void); +Oid get_spoint_type_oid(void); /* * Calculate the distance between two spherical points in radians. */ -float8 spoint_dist(const SPoint *p1, const SPoint *p2); +float8 spoint_dist(const SPoint *p1, const SPoint *p2); /* * Check whether two points are equal. */ -bool spoint_eq(const SPoint *p1, const SPoint *p2); +bool spoint_eq(const SPoint *p1, const SPoint *p2); /* * Check the longitude and latitude values of a spherical point. */ -void spoint_check(SPoint *spoint); +void spoint_check(SPoint *spoint); /* * Transforms a 3d vector into a spherical point. */ -void vector3d_spoint(SPoint *p, const Vector3D *v); +void vector3d_spoint(SPoint *p, const Vector3D *v); /* * Transforms a spherical point into a 3d vector. */ -void spoint_vector3d(Vector3D *v, const SPoint *p); +void spoint_vector3d(Vector3D *v, const SPoint *p); /* * Take the input and store it as a spherical point. */ -Datum spherepoint_in(PG_FUNCTION_ARGS); +Datum spherepoint_in(PG_FUNCTION_ARGS); /* * Create spherical point from lat, lng and store to first argument(pointer) */ -void create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat); +void create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat); /* * Create a spherical point from longitude and latitude both in radians. */ -Datum spherepoint_from_long_lat(PG_FUNCTION_ARGS); +Datum spherepoint_from_long_lat(PG_FUNCTION_ARGS); /* * Create a spherical point from longitude and latitude both in degrees. */ -Datum spherepoint_from_long_lat_deg(PG_FUNCTION_ARGS); +Datum spherepoint_from_long_lat_deg(PG_FUNCTION_ARGS); /* * Calculate the distance between two spherical points. */ -Datum spherepoint_distance(PG_FUNCTION_ARGS); +Datum spherepoint_distance(PG_FUNCTION_ARGS); /* * Longitude of a spherical point. */ -Datum spherepoint_long(PG_FUNCTION_ARGS); +Datum spherepoint_long(PG_FUNCTION_ARGS); /* * Latitude of a spherical point. */ -Datum spherepoint_lat(PG_FUNCTION_ARGS); +Datum spherepoint_lat(PG_FUNCTION_ARGS); /* * Cartesian x-value of a spherical point. */ -Datum spherepoint_x(PG_FUNCTION_ARGS); +Datum spherepoint_x(PG_FUNCTION_ARGS); /* * Cartesian y-value of a spherical point. */ -Datum spherepoint_y(PG_FUNCTION_ARGS); +Datum spherepoint_y(PG_FUNCTION_ARGS); /* * Cartesian z-value of a spherical point. */ -Datum spherepoint_z(PG_FUNCTION_ARGS); +Datum spherepoint_z(PG_FUNCTION_ARGS); /* * Cartesian values of a spherical point as an array. */ -Datum spherepoint_xyz(PG_FUNCTION_ARGS); +Datum spherepoint_xyz(PG_FUNCTION_ARGS); /* * Check whether two points are equal. */ -Datum spherepoint_equal(PG_FUNCTION_ARGS); +Datum spherepoint_equal(PG_FUNCTION_ARGS); #endif diff --git a/src/polygon.c b/src/polygon.c index 57786b8..c584481 100644 --- a/src/polygon.c +++ b/src/polygon.c @@ -62,11 +62,12 @@ PG_FUNCTION_INFO_V1(spherepoly_add_points_finalize); PG_FUNCTION_INFO_V1(spherepoly_is_convex); - /* + /* -------- * Writes "center" of a polygon into 'v'. * * v - pointer to the center of a polygon * poly - pointer to the polygon + * -------- */ static void spherepoly_center(Vector3D *v, const SPOLY *poly) @@ -169,7 +170,7 @@ spherepoly_check(const SPOLY *poly) static SPOLY * spherepoly_from_array(SPoint *arr, int32 nelem) { - SPOLY *poly = NULL; + SPOLY *poly = NULL; if (nelem < 3) { @@ -178,9 +179,9 @@ spherepoly_from_array(SPoint *arr, int32 nelem) } else { - int32 i; - float8 scheck; - int32 size; + int32 i; + float8 scheck; + int32 size; for (i = 0; i < nelem; i++) { @@ -216,7 +217,7 @@ spherepoly_from_array(SPoint *arr, int32 nelem) return NULL; } - size = offsetof(SPOLY, p[0]) +sizeof(SPoint) * nelem; + size = offsetof(SPOLY, p[0]) + sizeof(SPoint) * nelem; poly = (SPOLY *) palloc(size); SET_VARSIZE(poly, size); poly->npts = nelem; @@ -494,15 +495,15 @@ poly_poly_pos(const SPOLY *p1, const SPOLY *p2, bool recheck) bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir) { - bool ret = false; + bool ret = false; if (p1->npts == p2->npts) { - int32 i, - k, - cntr, - shift; + int32 i, + k, + cntr, + shift; for (shift = 0; shift < p1->npts; shift++) { @@ -574,8 +575,8 @@ Datum spherepoly_get_point(PG_FUNCTION_ARGS) { int32 i; - SPOLY *poly = PG_GETARG_SPOLY(0); - SPoint *sp = (SPoint *) palloc(sizeof(SPoint)); + SPOLY *poly = PG_GETARG_SPOLY(0); + SPoint *sp = (SPoint *) palloc(sizeof(SPoint)); i = PG_GETARG_INT32(1); if (spoly_get_point(sp, poly, i - 1)) @@ -825,8 +826,8 @@ poly_line_pos(const SPOLY *poly, const SLine *line) /* Recheck line crossing */ if (pos == sl_cr) { - bool bal, - eal; + bool bal, + eal; bal = spoint_at_sline(&slbeg, &sl); eal = spoint_at_sline(&slend, &sl); @@ -1465,7 +1466,7 @@ spherepoly_add_point(PG_FUNCTION_ARGS) } if (poly == NULL) { - size = offsetof(SPOLY, p[0]) +sizeof(SPoint); + size = offsetof(SPOLY, p[0]) + sizeof(SPoint); poly = (SPOLY *) palloc(size); memcpy((void *) &poly->p[0], (void *) p, sizeof(SPoint)); SET_VARSIZE(poly, size); @@ -1487,7 +1488,7 @@ spherepoly_add_point(PG_FUNCTION_ARGS) elog(NOTICE, "spoly(spoint): Skip point, distance of previous point is 180deg"); } - size = offsetof(SPOLY, p[0]) +sizeof(SPoint) * (poly->npts + 1); + size = offsetof(SPOLY, p[0]) + sizeof(SPoint) * (poly->npts + 1); poly_new = palloc(size); memcpy((void *) poly_new, (void *) poly, VARSIZE(poly)); poly_new->npts++; @@ -1501,7 +1502,7 @@ spherepoly_add_point(PG_FUNCTION_ARGS) Datum spherepoly_add_points_finalize(PG_FUNCTION_ARGS) { - SPOLY *poly = (SPOLY *) PG_GETARG_POINTER(0); + SPOLY *poly = (SPOLY *) PG_GETARG_POINTER(0); if (poly == NULL) { @@ -1542,10 +1543,10 @@ spherepoly_is_convex(PG_FUNCTION_ARGS) vsu, wsv, crs; - int32 i; + int32 i; float8 cur = 0.0, prev = 0.0; - SPOLY *poly = (SPOLY *) PG_GETARG_POINTER(0); + SPOLY *poly = (SPOLY *) PG_GETARG_POINTER(0); if (poly == NULL) { @@ -1560,8 +1561,8 @@ spherepoly_is_convex(PG_FUNCTION_ARGS) for (i = 0; i < poly->npts; i++) { - const int j = (i - 1 + poly->npts) % poly->npts; - const int k = (i + 1) % poly->npts; + const int j = (i - 1 + poly->npts) % poly->npts; + const int k = (i + 1) % poly->npts; spoint_vector3d(&u, &poly->p[i]); spoint_vector3d(&v, &poly->p[j]); diff --git a/src/polygon.h b/src/polygon.h index d52a9c6..438d15b 100644 --- a/src/polygon.h +++ b/src/polygon.h @@ -12,9 +12,9 @@ */ typedef struct { - char vl_len_[4]; /* total size in bytes */ - int32 npts; /* count of points */ - SPoint p[1]; /* variable length array of SPoints */ + char vl_len_[4]; /* total size in bytes */ + int32 npts; /* count of points */ + SPoint p[1]; /* variable length array of SPoints */ } SPOLY; #define MAX_POINTS 1024 @@ -26,20 +26,20 @@ typedef struct #define PGS_ELLIPSE_POLY_OVER 3 /* ellipse overlaps polygon */ /* Polygon and circle */ -#define PGS_CIRCLE_POLY_AVOID 0 /* circle avoids polygon */ -#define PGS_POLY_CONT_CIRCLE 1 /* polygon contains circle */ -#define PGS_CIRCLE_CONT_POLY 2 /* circle contains polygon */ -#define PGS_CIRCLE_POLY_OVER 3 /* circle overlap polygon */ +#define PGS_CIRCLE_POLY_AVOID 0 /* circle avoids polygon */ +#define PGS_POLY_CONT_CIRCLE 1 /* polygon contains circle */ +#define PGS_CIRCLE_CONT_POLY 2 /* circle contains polygon */ +#define PGS_CIRCLE_POLY_OVER 3 /* circle overlap polygon */ /* Polygon and line */ -#define PGS_LINE_POLY_AVOID 0 /* line avoids polygon */ -#define PGS_POLY_CONT_LINE 1 /* polygon contains line */ -#define PGS_LINE_POLY_OVER 2 /* line overlap polygon */ +#define PGS_LINE_POLY_AVOID 0 /* line avoids polygon */ +#define PGS_POLY_CONT_LINE 1 /* polygon contains line */ +#define PGS_LINE_POLY_OVER 2 /* line overlap polygon */ /* Polygon and polygon */ -#define PGS_POLY_AVOID 0 /* polygon avoids other polygon */ -#define PGS_POLY_CONT 1 /* polygon contains other polygon */ -#define PGS_POLY_OVER 2 /* polygons overlap */ +#define PGS_POLY_AVOID 0 /* polygon avoids other polygon */ +#define PGS_POLY_CONT 1 /* polygon contains other polygon */ +#define PGS_POLY_OVER 2 /* polygons overlap */ #define PG_GETARG_SPOLY( arg ) \ @@ -53,7 +53,7 @@ typedef struct * * If 'dir' is true, check with reverse polygon of 'p2'. */ -bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir); +bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir); /* * Returns the i-th line segment of a polygon. @@ -62,7 +62,7 @@ bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir); * poly - pointer to the polygon * i - number of the segment */ -bool spoly_segment(SLine *sl, const SPOLY *poly, int32 i); +bool spoly_segment(SLine *sl, const SPOLY *poly, int32 i); /* * Checks whether a polygon contains a point. @@ -70,12 +70,12 @@ bool spoly_segment(SLine *sl, const SPOLY *poly, int32 i); * pg - pointer to the polygon * sp - pointer to the point */ -bool spoly_contains_point(const SPOLY *pg, const SPoint *sp); +bool spoly_contains_point(const SPOLY *pg, const SPoint *sp); /* * Returns the n-th point of a spoly. */ -Datum spherepoly_get_point(PG_FUNCTION_ARGS); +Datum spherepoly_get_point(PG_FUNCTION_ARGS); /* * Returns the relationship between a polygon and a line as @@ -84,283 +84,283 @@ Datum spherepoly_get_point(PG_FUNCTION_ARGS); * poly - pointer to the polygon * line - pointer to the line */ -int8 poly_line_pos(const SPOLY *poly, const SLine *line); +int8 poly_line_pos(const SPOLY *poly, const SLine *line); /* * Input of a spherical from sequence of pairconsecutive numbers(lng, lat). */ -Datum spherepoly_deg(PG_FUNCTION_ARGS); +Datum spherepoly_deg(PG_FUNCTION_ARGS); /* * Input of a spherical polygon. */ -Datum spherepoly_in(PG_FUNCTION_ARGS); +Datum spherepoly_in(PG_FUNCTION_ARGS); /* * Checks whether two polygons are equal. */ -Datum spherepoly_equal(PG_FUNCTION_ARGS); +Datum spherepoly_equal(PG_FUNCTION_ARGS); /* * Checks whether two polygons are not equal. */ -Datum spherepoly_equal_neg(PG_FUNCTION_ARGS); +Datum spherepoly_equal_neg(PG_FUNCTION_ARGS); /* * Circumstance of a polygon. Returns circumference in radians * (float8 datum). */ -Datum spherepoly_circ(PG_FUNCTION_ARGS); +Datum spherepoly_circ(PG_FUNCTION_ARGS); /* * Count points (edges) of a polygon. */ -Datum spherepoly_npts(PG_FUNCTION_ARGS); +Datum spherepoly_npts(PG_FUNCTION_ARGS); /* * Returns area of a polygon. */ -Datum spherepoly_area(PG_FUNCTION_ARGS); +Datum spherepoly_area(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a point. */ -Datum spherepoly_cont_point(PG_FUNCTION_ARGS); +Datum spherepoly_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a point. */ -Datum spherepoly_cont_point_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a point. */ -Datum spherepoly_cont_point_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a point. */ -Datum spherepoly_cont_point_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a circle. */ -Datum spherepoly_cont_circle(PG_FUNCTION_ARGS); +Datum spherepoly_cont_circle(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a circle. */ -Datum spherepoly_cont_circle_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a circle. */ -Datum spherepoly_cont_circle_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a circle. */ -Datum spherepoly_cont_circle_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a polygon. */ -Datum spherecircle_cont_poly(PG_FUNCTION_ARGS); +Datum spherecircle_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a polygon. */ -Datum spherecircle_cont_poly_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a polygon. */ -Datum spherecircle_cont_poly_com(PG_FUNCTION_ARGS); +Datum spherecircle_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a polygon. */ -Datum spherecircle_cont_poly_com_neg(PG_FUNCTION_ARGS); +Datum spherecircle_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle overlap. */ -Datum spherepoly_overlap_circle(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle don't overlap. */ -Datum spherepoly_overlap_circle_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle overlap. */ -Datum spherepoly_overlap_circle_com(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle don't overlap. */ -Datum spherepoly_overlap_circle_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a line. */ -Datum spherepoly_cont_line(PG_FUNCTION_ARGS); +Datum spherepoly_cont_line(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a line. */ -Datum spherepoly_cont_line_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a line. */ -Datum spherepoly_cont_line_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a line. */ -Datum spherepoly_cont_line_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line overlap. */ -Datum spherepoly_overlap_line(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line don't overlap. */ -Datum spherepoly_overlap_line_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line overlap. */ -Datum spherepoly_overlap_line_com(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line don't overlap. */ -Datum spherepoly_overlap_line_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains other polygon. */ -Datum spherepoly_cont_poly(PG_FUNCTION_ARGS); +Datum spherepoly_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain other polygon. */ -Datum spherepoly_cont_poly_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains other polygon. */ -Datum spherepoly_cont_poly_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain other polygon. */ -Datum spherepoly_cont_poly_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two polygons overlap. */ -Datum spherepoly_overlap_poly(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_poly(PG_FUNCTION_ARGS); /* * Checks whether two polygons don't overlap. */ -Datum spherepoly_overlap_poly_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains an ellipse. */ -Datum spherepoly_cont_ellipse(PG_FUNCTION_ARGS); +Datum spherepoly_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain an ellipse. */ -Datum spherepoly_cont_ellipse_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains an ellipse. */ -Datum spherepoly_cont_ellipse_com(PG_FUNCTION_ARGS); +Datum spherepoly_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain an ellipse. */ -Datum spherepoly_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a polygon. */ -Datum sphereellipse_cont_poly(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a polygon. */ -Datum sphereellipse_cont_poly_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a polygon. */ -Datum sphereellipse_cont_poly_com(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a polygon. */ -Datum sphereellipse_cont_poly_com_neg(PG_FUNCTION_ARGS); +Datum sphereellipse_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse overlap. */ -Datum spherepoly_overlap_ellipse(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse don't overlap. */ -Datum spherepoly_overlap_ellipse_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse overlap. */ -Datum spherepoly_overlap_ellipse_com(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse don't overlap. */ -Datum spherepoly_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); +Datum spherepoly_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Performs inverse transform on a polygon using an Euler transformation. */ -Datum spheretrans_poly(PG_FUNCTION_ARGS); +Datum spheretrans_poly(PG_FUNCTION_ARGS); /* * Performs inverse transform on a polygon using an Euler transformation. */ -Datum spheretrans_poly_inverse(PG_FUNCTION_ARGS); +Datum spheretrans_poly_inverse(PG_FUNCTION_ARGS); /* * State transition function for the aggregate function spoly(spoint). Never * call this function outside an aggregate function! Adds a point to a polygon. */ -Datum spherepoly_add_point(PG_FUNCTION_ARGS); +Datum spherepoly_add_point(PG_FUNCTION_ARGS); /* * Finalize function for adding spoints to a polygon. */ -Datum spherepoly_add_points_finalize(PG_FUNCTION_ARGS); +Datum spherepoly_add_points_finalize(PG_FUNCTION_ARGS); /* * Returns spoly as array of points */ -Datum spherepoly_get_array(PG_FUNCTION_ARGS); +Datum spherepoly_get_array(PG_FUNCTION_ARGS); /* * Checks whether a polygon is convex */ -Datum spherepoly_is_convex(PG_FUNCTION_ARGS); +Datum spherepoly_is_convex(PG_FUNCTION_ARGS); #endif diff --git a/src/sbuffer.c b/src/sbuffer.c index 7a62281..41fbfbf 100644 --- a/src/sbuffer.c +++ b/src/sbuffer.c @@ -10,53 +10,53 @@ unsigned char spheretype; /* The angle buffer. */ -float8 bufangle[MAX_BUF_ANGLE]; +float8 bufangle[MAX_BUF_ANGLE]; /* A simple spherical point. */ typedef struct { - double lng; /* longitude */ - double lat; /* latitude */ + 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; + int m; /* count of buffered points */ + bpoint *p; /* pointer to array of points */ +} bufpoints; /* ID of line's length angle. */ -int bufline; +int bufline; /* * First element is the ID of spherical point ( center ). * Second element is the ID of radius angle. */ -int bufcircle[2]; +int bufcircle[2]; /* Buffer of ellipse. */ -int bufellipse[5]; +int bufellipse[5]; /* Buffer of IDs of Euler transformation values. */ -int bufeuler[3]; +int bufeuler[3]; /* Structure to buffer the axes of Euler transformation. */ struct { - unsigned char phi, /* first axis */ - theta, /* second axis */ - psi; /* third axis */ -} bufeulertype; + unsigned char phi, /* first axis */ + theta, /* second axis */ + psi; /* third axis */ +} bufeulertype; /* Current angle ID. */ -int bufapos; +int bufapos; /* Current point ID. */ -int bufspos; +int bufspos; /* Pointer to input buffer. */ -char *parse_buffer; +char *parse_buffer; void @@ -172,7 +172,7 @@ set_line(int length) void set_euler(int phi, int theta, int psi, char *etype) { - int i; + int i; unsigned char t = 0; bufeuler[0] = phi; @@ -229,7 +229,7 @@ int get_line(double *phi, double *theta, double *psi, unsigned char *etype, double *length) { - int i; + int i; if (spheretype != STYPE_LINE) { @@ -263,7 +263,7 @@ int get_euler(double *phi, double *theta, double *psi, unsigned char *etype) { - int i; + int i; if (spheretype != STYPE_EULER) { @@ -367,7 +367,7 @@ get_box(double *lng1, double *lat1, double *lng2, double *lat2) int get_buffer(char *buf, int offset) { - int slen = strlen(parse_buffer); + int slen = strlen(parse_buffer); if (!parse_buffer || !(slen > 0)) { diff --git a/src/sbuffer.h b/src/sbuffer.h index 57599ee..3b264d0 100644 --- a/src/sbuffer.h +++ b/src/sbuffer.h @@ -3,89 +3,89 @@ /* Parser buffer declarations */ -#define STYPE_UNKNOWN 0 /* unknown type */ -#define STYPE_POINT 1 /* input is spherical type */ -#define STYPE_CIRCLE 2 /* input is spherical circle */ -#define STYPE_LINE 3 /* input is spherical line */ -#define STYPE_EULER 4 /* input is Euler transformation */ -#define STYPE_PATH 5 /* input is spherical path or polygon */ -#define STYPE_ELLIPSE 6 /* input is spherical ellipse */ -#define STYPE_BOX 7 /* input is spherical box */ +#define STYPE_UNKNOWN 0 /* unknown type */ +#define STYPE_POINT 1 /* input is spherical type */ +#define STYPE_CIRCLE 2 /* input is spherical circle */ +#define STYPE_LINE 3 /* input is spherical line */ +#define STYPE_EULER 4 /* input is Euler transformation */ +#define STYPE_PATH 5 /* input is spherical path or polygon */ +#define STYPE_ELLIPSE 6 /* input is spherical ellipse */ +#define STYPE_BOX 7 /* input is spherical box */ /* PGS_EULER_AXIS Euler axis */ -#define EULER_AXIS_X 1 /* x - axis for Euler transformation */ -#define EULER_AXIS_Y 2 /* y - axis for Euler transformation */ -#define EULER_AXIS_Z 3 /* z - axis for Euler transformation */ +#define EULER_AXIS_X 1 /* x - axis for Euler transformation */ +#define EULER_AXIS_Y 2 /* y - axis for Euler transformation */ +#define EULER_AXIS_Z 3 /* z - axis for Euler transformation */ -int sphere_yylex(); -void sphere_yyerror(const char *str); -void sphere_flush_scanner_buffer(void); +int sphere_yylex(); +void sphere_yyerror(const char *str); +void sphere_flush_scanner_buffer(void); /* Sets the data type */ -void set_spheretype(unsigned char st); +void set_spheretype(unsigned char st); /* Initialize the input buffer */ -void init_buffer(char *buffer); +void init_buffer(char *buffer); /* Resets the input buffer */ -void reset_buffer(void); +void reset_buffer(void); /* * Read the "offset" number of bytes from "buf" buffer. * Returns the number of read bytes. */ -int get_buffer(char *buf, int offset); +int get_buffer(char *buf, int offset); /* * Input of an angle. When is_deg > 0 then "a" is in degrees, * otherwise it's in radians. Returns the unique ID (position) of the angle. */ -int set_angle(unsigned char is_deg, double a); +int set_angle(unsigned char is_deg, double a); /* * Set the sign of an angle. "apos" is the angle. "s" is a sign of the angle * ( < 0 .. - , > 0 .. + ). Returns the unique ID (position) of the angle. */ -int set_angle_sign(int apos, int s); +int set_angle_sign(int apos, int s); /* * Creates a spherical point. "lngpos" is the ID of a longitude angle, "latpos" * is the ID of a latitude angle. Returns the unique ID (position) of the spherical * point. */ -int set_point(int lngpos, int latpos); +int set_point(int lngpos, int latpos); /* * Creates a spherical circle. "spos" is the ID of a spherical point, "rpos" * is the ID of a radius angle. */ -void set_circle(int spos, int rpos); +void set_circle(int spos, int rpos); /* * Sets the length of a spherical line. "length" is the ID of a length angle. */ -void set_line(int length); +void set_line(int length); /* * Creates an Euler transformation. "phi" is the ID of a first angle, * "theta" is the ID of a second angle, "psi" is the ID of a third angle, * "etype" is the three letter code of Euler transformation axes. */ -void set_euler(int phi, int theta, int psi, char *etype); +void set_euler(int phi, int theta, int psi, char *etype); /* * Creates a spherical ellipse. "r1" is the ID of a first radius angle, * "r2" is the ID of a second radius angle, "sp" is the ID of a spherical * point ( center ), "inc" is the ID of an inclination angle. */ -void set_ellipse(int r1, int r2, int sp, int inc); +void set_ellipse(int r1, int r2, int sp, int inc); /* * Returns the point parameters. "lng" is the pointer to a longitude * value, "lat" is the pointer to a latitude value. Returns 0 if user * input is a spherical point. */ -int get_point(double *lng, double *lat); +int get_point(double *lng, double *lat); /* * Returns the circle parameters. "lng" is pointer to a longitude @@ -93,7 +93,7 @@ int get_point(double *lng, double *lat); * "radius" is the pointer to the radius value. Returns 0 if user input * is a spherical circle. */ -int get_circle(double *lng, double *lat, double *radius); +int get_circle(double *lng, double *lat, double *radius); /* * Returns the ellipse parameters. "lng" is the pointer to a longitude value @@ -102,8 +102,8 @@ int get_circle(double *lng, double *lat, double *radius); * radius value, "inc" is the pointer to an inclination angle. Returns 0 if user * input is a spherical ellipse. */ -int get_ellipse(double *lng, double *lat, double *r1, - double *r2, double *inc); +int get_ellipse(double *lng, double *lat, double *r1, + double *r2, double *inc); /* * Returns the line parameters. "phi" is the pointer to the first angle @@ -112,8 +112,8 @@ int get_ellipse(double *lng, double *lat, double *r1, * "etype" is the pointer to the axes value of Euler transformation, "length" is * the pointer to the length value. Returns 0 if user input is a spherical line. */ -int get_line(double *phi, double *theta, double *psi, - unsigned char *etype, double *length); +int get_line(double *phi, double *theta, double *psi, + unsigned char *etype, double *length); /* * Returns the Euler transformation parameters. "phi" is the pointer to the @@ -122,20 +122,20 @@ int get_line(double *phi, double *theta, double *psi, * transformation, "etype" is the pointer to the axes value of Euler transformation. * Returns 0 if user input is an Euler transformation. */ -int get_euler(double *phi, double *theta, - double *psi, unsigned char *etype); +int get_euler(double *phi, double *theta, + double *psi, unsigned char *etype); /* * Returns the number of path elements. */ -int get_path_count(void); +int get_path_count(void); /* * Returns the elements of a path. "spos" is the number of element, "lng" is * the ID of longitude angle, "lat" is the ID of a latitude angle. Returns 0 * if user input is a path or a polygon and "spos" is valid. */ -int get_path_elem(int spos, double *lng, double *lat); +int get_path_elem(int spos, double *lng, double *lat); /* * Returns the elements of a box. "lng1" is the ID of the first longitude @@ -143,6 +143,6 @@ int get_path_elem(int spos, double *lng, double *lat); * the second longitude angle, "lat2" is the ID of the second latitude angle. * Returns 0 if user input is a box. */ -int get_box(double *lng1, double *lat1, double *lng2, double *lat2); +int get_box(double *lng1, double *lat1, double *lng2, double *lat2); #endif diff --git a/src/vector3d.c b/src/vector3d.c index 27b7d8f..e5b3416 100644 --- a/src/vector3d.c +++ b/src/vector3d.c @@ -19,7 +19,7 @@ vector3d_cross(Vector3D *out, const Vector3D *v1, const Vector3D *v2) } void -vector3d_addwithscalar(Vector3D *result, double scalar, const Vector3D *delta) +vector3d_addwithscalar(Vector3D *result, double scalar, const Vector3D *delta) { result->x = result->x + delta->x * scalar; result->y = result->y + delta->y * scalar; @@ -29,7 +29,7 @@ vector3d_addwithscalar(Vector3D *result, double scalar, const Vector3D *delta) float8 vector3d_scalar(Vector3D *v1, Vector3D *v2) { - float8 out = 0; + float8 out = 0; out += v1->x * v2->x; out += v1->y * v2->y; diff --git a/src/vector3d.h b/src/vector3d.h index 23ba9b9..ad35519 100644 --- a/src/vector3d.h +++ b/src/vector3d.h @@ -10,9 +10,9 @@ */ typedef struct { - float8 x; /* x (-1.0 .. 1.0) */ - float8 y; /* y (-1.0 .. 1.0) */ - float8 z; /* z (-1.0 .. 1.0) */ + float8 x; /* x (-1.0 .. 1.0) */ + float8 y; /* y (-1.0 .. 1.0) */ + float8 z; /* z (-1.0 .. 1.0) */ } Vector3D; @@ -20,27 +20,27 @@ typedef struct * Calculate the cross product of two vectors. Puts * cross product of v1 and v2 into out and returns it. */ -void vector3d_cross(Vector3D *out, const Vector3D *v1, const Vector3D *v2); +void vector3d_cross(Vector3D *out, const Vector3D *v1, const Vector3D *v2); /* * Checks equality of two vectors. */ -bool vector3d_eq(const Vector3D *a, const Vector3D *b); +bool vector3d_eq(const Vector3D *a, const Vector3D *b); /* * Calculate the scalar product of two vectors. */ -float8 vector3d_scalar(Vector3D *v1, Vector3D *v2); +float8 vector3d_scalar(Vector3D *v1, Vector3D *v2); /* * Calculate the length of a vector. */ -float8 vector3d_length(const Vector3D *v); +float8 vector3d_length(const Vector3D *v); -/* - * Calculate result + scalar*delta +/* + * Calculate result + scalar*delta */ -void vector3d_addwithscalar( - Vector3D *result, double scalar, const Vector3D *delta); +void vector3d_addwithscalar(Vector3D *result, double scalar, + const Vector3D *delta); #endif