+ if (! pair_decode( s, &x1, &x2, &s))
+ elog (WARN, "Bad polygon external representation '%s'",str);
+
+ if (*s == DELIM) s++;
+ poly->p[i*2+oddcount].y = x1;
+ poly->p[i*2+1+oddcount].y = x2;
+ };
+
+ if (*s == RDELIM) {
+ s++;
+ while (isspace( *s)) s++;
+ if (*s != '\0')
+ elog(WARN, "Bad polygon external representation '%s'", str);
+
+ } else {
+ elog(WARN, "Bad polygon external representation '%s'", str);
+ };
+
+ } else {
+#endif
+ if ((! path_decode(FALSE, npts, str, &isopen, &s, &(poly->p[0])))
+ || (*s != '\0'))
+ elog (WARN, "Bad polygon external representation '%s'",str);
+
+#if OLD_FORMAT_IN
+ };
+#endif;
+
make_bound_box(poly);
- return (poly);
-}
-/*-------------------------------------------------------------
- * poly_pt_count - count the number of points specified in the
- * polygon.
- *-------------------------------------------------------------*/
-long poly_pt_count(char *s, char delim)
-{
- long total = 0;
-
- if (*s++ != LDELIM) /* no left delimeter */
- return (long) -1;
-
- while (*s && (*s != RDELIM))
- {
- while (*s && (*s != delim))
- s++;
- total++; /* found one */
- if (*s)
- s++; /* bump s past the delimiter */
- }
-
- /* if there was no right delimiter OR an odd number of points */
-
- if ((*(s-1) != RDELIM) || ((total%2) != 0))
- return (long) -1;
-
- return (total/2);
-}
+ return( poly);
+} /* poly_in() */
/*---------------------------------------------------------------
* poly_out - convert internal POLYGON representation to the
- * character string format "(f8,f8,f8,f8,...f8)"
+ * character string format "((f8,f8),...,(f8,f8))"
+ * also support old format "(f8,f8,...,f8,f8)"
*---------------------------------------------------------------*/
char *poly_out(POLYGON *poly)
{
+#if OLD_FORMAT_OUT
int i;
- double *xp, *yp;
- char *output, *outptr;
-
- /*-----------------------------------------------------
- * Get enough space for "(f8,f8,f8,f8,...,f8)"
- * which P_MAXDIG+1 for each coordinate plus 2
- * for parens and 1 for the null
- *-----------------------------------------------------*/
- output = (char *)PALLOC(2*(P_MAXDIG+1)*poly->npts + 3);
- outptr = output;
-
- if (!output)
- elog(WARN, "Memory allocation failed, can't output polygon");
-
- *outptr++ = LDELIM;
-
- xp = (double *) poly->pts;
- yp = (double *) (poly->pts + (poly->npts * sizeof(double)));
-
- sprintf(outptr, "%*g,%*g", P_MAXDIG, *xp++, P_MAXDIG, *yp++);
- outptr += (2*P_MAXDIG + 1);
-
- for (i=1; i
npts; i++,xp++,yp++)
- {
- sprintf(outptr, ",%*g,%*g", P_MAXDIG, *xp, P_MAXDIG, *yp);
- outptr += 2*(P_MAXDIG + 1);
- }
- *outptr++ = RDELIM;
- *outptr = '\0';
- return (output);
-}
-
-/*-------------------------------------------------------
- * Find the largest coordinate out of n coordinates
- *-------------------------------------------------------*/
-double poly_max(double *coords, int ncoords)
-{
- double max;
-
- max = *coords++;
- ncoords--;
- while (ncoords--)
- {
- if (*coords > max)
- max = *coords;
- coords++;
- }
- return max;
+ char *result, *cp;
+#endif
+
+ if (!PointerIsValid((char *)poly))
+ return NULL;
+
+#if OLD_FORMAT_OUT
+ if (!PointerIsValid(result = (char *)PALLOC(poly->npts*(P_MAXLEN+3)+2)))
+ elog(WARN, "Memory allocation failed, can't output polygon", NULL);
+
+ cp = result;
+ *cp++ = LDELIM;
+
+ for (i=0; i
npts; i++) {
+ if (! pair_encode( poly->p[i].x, poly->p[i].y, cp))
+ elog (WARN, "Unable to format polygon", NULL);
+ cp += strlen(cp);
+ *cp++ = DELIM;
+ };
+ *(cp-1) = RDELIM;
+ *cp = '\0';
+ return(result);
+#else
+ return( path_encode( TRUE, poly->npts, &(poly->p[0])));
+#endif
}
-/*-------------------------------------------------------
- * Find the smallest coordinate out of n coordinates
- *-------------------------------------------------------*/
-double poly_min(double *coords, int ncoords)
-{
- double min;
-
- min = *coords++;
- ncoords--;
- while (ncoords--)
- {
- if (*coords < min)
- min = *coords;
- coords++;
- }
- return min;
-}
/*-------------------------------------------------------
* Is polygon A strictly left of polygon B? i.e. is
* the right most point of A left of the left most point
* of B?
*-------------------------------------------------------*/
-long poly_left(POLYGON *polya, POLYGON *polyb)
+bool poly_left(POLYGON *polya, POLYGON *polyb)
{
- double right, left;
-
- if (polya->npts > 0)
- right = poly_max((double *)polya->pts, polya->npts);
- else
- right = polya->boundbox.xh;
- if (polyb->npts > 0)
- left = poly_min((double *)polyb->pts, polyb->npts);
- else
- left = polyb->boundbox.xl;
-
- return (right < left);
+ return (polya->boundbox.high.x < polyb->boundbox.low.x);
}
/*-------------------------------------------------------
* the left most point of A left of the right most point
* of B?
*-------------------------------------------------------*/
-long poly_overleft(POLYGON *polya, POLYGON *polyb)
+bool poly_overleft(POLYGON *polya, POLYGON *polyb)
{
- double left, right;
-
- if (polya->npts > 0)
- left = poly_min((double *)polya->pts, polya->npts);
- else
- left = polya->boundbox.xl;
- if (polyb->npts > 0)
- right = poly_max((double *)polyb->pts, polyb->npts);
- else
- right = polyb->boundbox.xh;
-
- return (left <= right);
+ return (polya->boundbox.low.x <= polyb->boundbox.high.x);
}
/*-------------------------------------------------------
* the left most point of A right of the right most point
* of B?
*-------------------------------------------------------*/
-long poly_right(POLYGON *polya, POLYGON *polyb)
+bool poly_right(POLYGON *polya, POLYGON *polyb)
{
- double right, left;
-
- if (polya->npts > 0)
- left = poly_min((double *)polya->pts, polya->npts);
- else
- left = polya->boundbox.xl;
- if (polyb->npts > 0)
- right = poly_max((double *)polyb->pts, polyb->npts);
- else
- right = polyb->boundbox.xh;
-
- return (left > right);
+ return( polya->boundbox.low.x > polyb->boundbox.high.x);
}
/*-------------------------------------------------------
* the right most point of A right of the left most point
* of B?
*-------------------------------------------------------*/
-long poly_overright(POLYGON *polya, POLYGON *polyb)
+bool poly_overright(POLYGON *polya, POLYGON *polyb)
{
- double right, left;
-
- if (polya->npts > 0)
- right = poly_max((double *)polya->pts, polya->npts);
- else
- right = polya->boundbox.xh;
- if (polyb->npts > 0)
- left = poly_min((double *)polyb->pts, polyb->npts);
- else
- left = polyb->boundbox.xl;
-
- return (right > left);
+ return( polya->boundbox.high.x > polyb->boundbox.low.x);
}
/*-------------------------------------------------------
* Is polygon A the same as polygon B? i.e. are all the
* points the same?
*-------------------------------------------------------*/
-long poly_same(POLYGON *polya, POLYGON *polyb)
+bool poly_same(POLYGON *polya, POLYGON *polyb)
{
int i;
- double *axp, *bxp; /* point to x coordinates for a and b */
-
if (polya->npts != polyb->npts)
- return 0;
-
- axp = (double *)polya->pts;
- bxp = (double *)polyb->pts;
-
- for (i=0; i
npts; axp++, bxp++, i++)
- {
- if (*axp != *bxp)
- return 0;
- }
- return 1;
+ return FALSE;
+
+ for (i = 0; i < polya->npts; i++) {
+ if ((polya->p[i].x != polyb->p[i].x)
+ || (polya->p[i].y != polyb->p[i].y))
+ return FALSE;
+ };
+ return TRUE;
}
/*-----------------------------------------------------------------
* Determine if polygon A overlaps polygon B by determining if
* their bounding boxes overlap.
*-----------------------------------------------------------------*/
-long poly_overlap(POLYGON *polya, POLYGON *polyb)
+bool poly_overlap(POLYGON *polya, POLYGON *polyb)
{
return box_overlap(&(polya->boundbox), &(polyb->boundbox));
}
* Determine if polygon A contains polygon B by determining if A's
* bounding box contains B's bounding box.
*-----------------------------------------------------------------*/
-long poly_contain(POLYGON *polya, POLYGON *polyb)
+bool poly_contain(POLYGON *polya, POLYGON *polyb)
{
return box_contain(&(polya->boundbox), &(polyb->boundbox));
}
* Determine if polygon A is contained by polygon B by determining
* if A's bounding box is contained by B's bounding box.
*-----------------------------------------------------------------*/
-long poly_contained(POLYGON *polya, POLYGON *polyb)
+bool poly_contained(POLYGON *polya, POLYGON *polyb)
{
return box_contained(&(polya->boundbox), &(polyb->boundbox));
}
+
+
+/***********************************************************************
+ **
+ ** Routines for 2D points.
+ **
+ ***********************************************************************/
+
+Point *
+point(float8 *x, float8 *y)
+{
+ if (! (PointerIsValid(x) && PointerIsValid(y)))
+ return(NULL);
+
+ return(point_construct(*x, *y));
+} /* point() */
+
+
+Point *
+point_add(Point *p1, Point *p2)
+{
+ Point *result;
+
+ if (! (PointerIsValid(p1) && PointerIsValid(p2)))
+ return(NULL);
+
+ if (!PointerIsValid(result = PALLOCTYPE(Point)))
+ elog(WARN, "Memory allocation failed, can't add points",NULL);
+
+ result->x = (p1->x + p2->x);
+ result->y = (p1->y + p2->y);
+
+ return(result);
+} /* point_add() */
+
+Point *
+point_sub(Point *p1, Point *p2)
+{
+ Point *result;
+
+ if (! (PointerIsValid(p1) && PointerIsValid(p2)))
+ return(NULL);
+
+ if (!PointerIsValid(result = PALLOCTYPE(Point)))
+ elog(WARN, "Memory allocation failed, can't add points",NULL);
+
+ result->x = (p1->x - p2->x);
+ result->y = (p1->y - p2->y);
+
+ return(result);
+} /* point_sub() */
+
+Point *
+point_mul(Point *p1, Point *p2)
+{
+ Point *result;
+
+ if (! (PointerIsValid(p1) && PointerIsValid(p2)))
+ return(NULL);
+
+ if (!PointerIsValid(result = PALLOCTYPE(Point)))
+ elog(WARN, "Memory allocation failed, can't multiply points",NULL);
+
+ result->x = (p1->x*p2->x) - (p1->y*p2->y);
+ result->y = (p1->x*p2->y) + (p1->y*p2->x);
+
+ return(result);
+} /* point_mul() */
+
+Point *
+point_div(Point *p1, Point *p2)
+{
+ Point *result;
+ double div;
+
+ if (! (PointerIsValid(p1) && PointerIsValid(p2)))
+ return(NULL);
+
+ if (!PointerIsValid(result = PALLOCTYPE(Point)))
+ elog(WARN, "Memory allocation failed, can't multiply path",NULL);
+
+ div = (p2->x*p2->x) + (p2->y*p2->y);
+
+ result->x = ((p1->x*p2->x) + (p1->y*p2->y)) / div;
+ result->y = ((p2->x*p1->y) - (p2->y*p1->x)) / div;
+
+ return(result);
+} /* point_div() */
+
+
+/***********************************************************************
+ **
+ ** Routines for 2D boxes.
+ **
+ ***********************************************************************/
+
+BOX *
+box(Point *p1, Point *p2)
+{
+ BOX *result;
+
+ if (! (PointerIsValid(p1) && PointerIsValid(p2)))
+ return(NULL);
+
+ result = box_construct( p1->x, p2->x, p1->y, p2->y);
+
+ return(result);
+} /* box() */
+
+BOX *
+box_add(BOX *box, Point *p)
+{
+ BOX *result;
+
+ if (! (PointerIsValid(box) && PointerIsValid(p)))
+ return(NULL);
+
+ result = box_construct( (box->high.x + p->x), (box->low.x + p->x),
+ (box->high.y + p->y), (box->low.y + p->y));
+
+ return(result);
+} /* box_add() */
+
+BOX *
+box_sub(BOX *box, Point *p)
+{
+ BOX *result;
+
+ if (! (PointerIsValid(box) && PointerIsValid(p)))
+ return(NULL);
+
+ result = box_construct( (box->high.x - p->x), (box->low.x - p->x),
+ (box->high.y - p->y), (box->low.y - p->y));
+
+ return(result);
+} /* box_sub() */
+
+BOX *
+box_mul(BOX *box, Point *p)
+{
+ BOX *result;
+ Point *high, *low;
+
+ if (! (PointerIsValid(box) && PointerIsValid(p)))
+ return(NULL);
+
+ high = point_mul( &box->high, p);
+ low = point_mul( &box->low, p);
+
+ result = box_construct( high->x, low->x, high->y, low->y);
+ PFREE( high);
+ PFREE( low);
+
+ return(result);
+} /* box_mul() */
+
+BOX *
+box_div(BOX *box, Point *p)
+{
+ BOX *result;
+ Point *high, *low;
+
+ if (! (PointerIsValid(box) && PointerIsValid(p)))
+ return(NULL);
+
+ high = point_div( &box->high, p);
+ low = point_div( &box->low, p);
+
+ result = box_construct( high->x, low->x, high->y, low->y);
+ PFREE( high);
+ PFREE( low);
+
+ return(result);
+} /* box_div() */
+
+
+/***********************************************************************
+ **
+ ** Routines for 2D lines.
+ ** Lines are not intended to be used as ADTs per se,
+ ** but their ops are useful tools for other ADT ops. Thus,
+ ** there are few relops.
+ **
+ ***********************************************************************/
+
+
+/***********************************************************************
+ **
+ ** Routines for 2D paths.
+ **
+ ***********************************************************************/
+
+POLYGON *path_poly(PATH *path);
+
+/* path_add()
+ * Concatenate two paths (only if they are both open).
+ */
+PATH *
+path_add(PATH *p1, PATH *p2)
+{
+ PATH *result;
+ int size;
+ int i;
+
+ if (! (PointerIsValid(p1) && PointerIsValid(p2))
+ || p1->closed || p2->closed)
+ return(NULL);
+
+ size = offsetof(PATH, p[0]) + (sizeof(p1->p[0]) * (p1->npts+p2->npts));
+ if (!PointerIsValid(result = PALLOC(size)))
+ elog(WARN, "Memory allocation failed, can't add paths",NULL);
+
+ result->size = size;
+ result->npts = (p1->npts+p2->npts);
+ result->closed = p1->closed;
+
+ for (i=0; i
npts; i++) {
+ result->p[i].x = p1->p[i].x;
+ result->p[i].y = p1->p[i].y;
+ };
+ for (i=0; i
npts; i++) {
+ result->p[i+p1->npts].x = p2->p[i].x;
+ result->p[i+p1->npts].y = p2->p[i].y;
+ };
+
+ return(result);
+} /* path_add() */
+
+/* path_add_pt()
+ * Translation operator.
+ */
+PATH *
+path_add_pt(PATH *path, Point *point)
+{
+ PATH *result;
+ int i;
+
+ if (! (PointerIsValid(path) && PointerIsValid(point)))
+ return(NULL);
+
+ if (! PointerIsValid(result = path_copy(path)))
+ elog(WARN, "Memory allocation failed, can't add path",NULL);
+
+ for (i=0; i
npts; i++) {
+ result->p[i].x += point->x;
+ result->p[i].y += point->y;
+ };
+
+ return(result);
+} /* path_add_pt() */
+
+PATH *
+path_sub_pt(PATH *path, Point *point)
+{
+ PATH *result;
+ int i;
+
+ if (! (PointerIsValid(path) && PointerIsValid(point)))
+ return(NULL);
+
+ if (! PointerIsValid(result = path_copy(path)))
+ elog(WARN, "Memory allocation failed, can't subtract path",NULL);
+
+ for (i=0; i
npts; i++) {
+ result->p[i].x -= point->x;
+ result->p[i].y -= point->y;
+ };
+
+ return(result);
+} /* path_sub_pt() */
+
+
+/* path_mul_pt()
+ * Rotation and scaling operators.
+ */
+PATH *
+path_mul_pt(PATH *path, Point *point)
+{
+ PATH *result;
+ Point *p;
+ int i;
+
+ if (! (PointerIsValid(path) && PointerIsValid(point)))
+ return(NULL);
+
+ if (! PointerIsValid(result = path_copy(path)))
+ elog(WARN, "Memory allocation failed, can't multiply path",NULL);
+
+ for (i=0; i
npts; i++) {
+ p = point_mul( &path->p[i], point);
+ result->p[i].x = p->x;
+ result->p[i].y = p->y;
+ PFREE(p);
+ };
+
+ return(result);
+} /* path_mul_pt() */
+
+PATH *
+path_div_pt(PATH *path, Point *point)
+{
+ PATH *result;
+ Point *p;
+ int i;
+
+ if (! (PointerIsValid(path) && PointerIsValid(point)))
+ return(NULL);
+
+ if (! PointerIsValid(result = path_copy(path)))
+ elog(WARN, "Memory allocation failed, can't divide path",NULL);
+
+ for (i=0; i
npts; i++) {
+ p = point_div( &path->p[i], point);
+ result->p[i].x = p->x;
+ result->p[i].y = p->y;
+ PFREE(p);
+ };
+
+ return(result);
+} /* path_div_pt() */
+
+
+POLYGON *path_poly(PATH *path)
+{
+ POLYGON *poly;
+ int size;
+ int i;
+
+ if (!PointerIsValid(path))
+ return(NULL);
+
+ if (!path->closed)
+ elog(WARN, "Open path cannot be converted to polygon",NULL);
+
+ size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * path->npts);
+ if (!PointerIsValid(poly = PALLOC(size)))
+ elog(WARN, "Memory allocation failed, can't convert path to polygon",NULL);
+
+ poly->size = size;
+ poly->npts = path->npts;
+
+ for (i=0; i
npts; i++) {
+ poly->p[i].x = path->p[i].x;
+ poly->p[i].y = path->p[i].y;
+ };
+
+ make_bound_box(poly);
+
+ return(poly);
+} /* path_polygon() */
+
+
+/***********************************************************************
+ **
+ ** Routines for 2D polygons.
+ **
+ ***********************************************************************/
+
+int4
+poly_npoints( POLYGON *poly)
+{
+ if (!PointerIsValid(poly))
+ return(0);
+
+ return(poly->npts);
+} /* poly_npoints() */
+
+BOX *
+poly_box(POLYGON *poly)
+{
+ BOX *box;
+
+ if (!PointerIsValid(poly) || (poly->npts < 1))
+ return(NULL);
+
+ box = box_copy( &poly->boundbox);
+
+ return(box);
+} /* poly_box() */
+
+POLYGON *
+box_poly(BOX *box)
+{
+ POLYGON *poly;
+ int size;
+
+ if (!PointerIsValid(box))
+ return(NULL);
+
+ size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * 4);
+ if (!PointerIsValid(poly = PALLOC(size)))
+ elog(WARN, "Memory allocation failed, can't convert box to polygon",NULL);
+
+ poly->size = size;
+ poly->npts = 4;
+
+ poly->p[0].x = box->low.x;
+ poly->p[0].y = box->low.y;
+ poly->p[1].x = box->low.x;
+ poly->p[1].y = box->high.y;
+ poly->p[2].x = box->high.x;
+ poly->p[2].y = box->high.y;
+ poly->p[3].x = box->high.x;
+ poly->p[3].y = box->low.y;
+
+ box_fill( &poly->boundbox, box->high.x, box->low.x, box->high.y, box->low.y);
+
+ return(poly);
+} /* box_poly() */
+
+PATH *
+poly_path(POLYGON *poly)
+{
+ PATH *path;
+ int size;
+ int i;
+
+ if (!PointerIsValid(poly) || (poly->npts < 0))
+ return(NULL);
+
+ size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * poly->npts);
+ if (!PointerIsValid(path = PALLOC(size)))
+ elog(WARN, "Memory allocation failed, can't convert polygon to path",NULL);
+
+ path->size = size;
+ path->npts = poly->npts;
+ path->closed = TRUE;
+
+ for (i=0; i
npts; i++) {
+ path->p[i].x = poly->p[i].x;
+ path->p[i].y = poly->p[i].y;
+ };
+
+ return(path);
+} /* poly_path() */
+
+
+/*-------------------------------------------------------------------------
+ *
+ * circle.c--
+ * 2D geometric operations
+ *
+ * Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.3 1997/04/22 17:31:32 scrappy Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PI
+#define PI 3.1415926536
+#endif
+
+int single_decode(char *str, float8 *x, char **ss);
+int single_encode(float8 x, char *str);
+
+int single_decode(char *str, float8 *x, char **s)
+{
+ char *cp;
+
+ if (!PointerIsValid(str))
+ return(FALSE);
+
+ while (isspace( *str)) str++;
+ *x = strtod( str, &cp);
+#ifdef GEODEBUG
+fprintf( stderr, "single_decode- (%x) try decoding %s to %g\n", (cp-str), str, *x);
+#endif
+ if (cp <= str) return(FALSE);
+ while (isspace( *cp)) cp++;
+
+ if (s != NULL) *s = cp;
+
+ return(TRUE);
+}
+
+int single_encode(float8 x, char *str)
+{
+ (void) sprintf(str, "%.*g", digits8, x);
+ return(TRUE);
+}
+
+
+/***********************************************************************
+ **
+ ** Routines for circles.
+ **
+ ***********************************************************************/
+
+/*----------------------------------------------------------
+ * Formatting and conversion routines.
+ *---------------------------------------------------------*/
+
+/* circle_in - convert a string to internal form.
+ *
+ * External format: (center and radius of circle)
+ * "((f8,f8))"
+ * also supports quick entry style "(f8,f8,f8)"
+ */
+CIRCLE *circle_in(char *str)
+{
+ CIRCLE *circle;
+
+ char *s, *cp;
+ int depth = 0;
+
+ if (!PointerIsValid(str))
+ elog (WARN," Bad (null) circle external representation",NULL);
+
+ if (!PointerIsValid(circle = PALLOCTYPE(CIRCLE)))
+ elog(WARN, "Memory allocation failed, can't input circle '%s'",str);
+
+ s = str;
+ while (isspace( *s)) s++;
+ if ((*s == LDELIM_C) || (*s == LDELIM)) {
+ depth++;
+ cp = (s+1);
+ while (isspace( *cp)) cp++;
+ if (*cp == LDELIM) {
+ s = cp;
+ };
+ };
+
+ if (! pair_decode( s, &circle->center.x, &circle->center.y, &s))
+ elog (WARN, "Bad circle external representation '%s'",str);
+
+ if (*s == DELIM) s++;
+ while (isspace( *s)) s++;
+
+ if (! single_decode( s, &circle->radius, &s))
+ elog (WARN, "Bad circle external representation '%s'",str);
+
+ while (depth > 0) {
+ if ((*s == RDELIM)
+ || ((*s == RDELIM_C) && (depth == 1))) {
+ depth--;
+ s++;
+ while (isspace( *s)) s++;
+ } else {
+ elog (WARN, "Bad circle external representation '%s'",str);
+ };
+ };
+
+ if (*s != '\0')
+ elog (WARN, "Bad circle external representation '%s'",str);
+
+ return(circle);
+} /* circle_in() */
+
+/* circle_out - convert a circle to external form.
+ */
+char *circle_out(CIRCLE *circle)
+{
+ char *result;
+ char *cp;
+
+ if (!PointerIsValid(circle))
+ return(NULL);
+
+ if (!PointerIsValid(result = (char *)PALLOC(3*(P_MAXLEN+1)+3)))
+ elog(WARN, "Memory allocation failed, can't output circle", NULL);
+
+ cp = result;
+ *cp++ = LDELIM_C;
+ *cp++ = LDELIM;
+ if (! pair_encode( circle->center.x, circle->center.y, cp))
+ elog (WARN, "Unable to format circle", NULL);
+
+ cp += strlen(cp);
+ *cp++ = RDELIM;
+ *cp++ = DELIM;
+ if (! single_encode( circle->radius, cp))
+ elog (WARN, "Unable to format circle", NULL);
+
+ cp += strlen(cp);
+ *cp++ = RDELIM_C;
+ *cp = '\0';
+
+ return(result);
+} /* circle_out() */
+
+
+/*----------------------------------------------------------
+ * Relational operators for CIRCLEs.
+ * <, >, <=, >=, and == are based on circle area.
+ *---------------------------------------------------------*/
+
+/* circles identical?
+ */
+bool circle_same(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPeq(circle1->radius,circle2->radius)
+ && FPeq(circle1->center.x,circle2->center.x)
+ && FPeq(circle1->center.y,circle2->center.y));
+}
+
+/* circle_overlap - does circle1 overlap circle2?
+ */
+bool circle_overlap(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle(point_dt(&circle1->center,&circle2->center),(circle1->radius+circle2->radius)));
+}
+
+/* circle_overleft - is the right edge of circle1 to the left of
+ * the right edge of circle2?
+ */
+bool circle_overleft(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle((circle1->center.x+circle1->radius),(circle2->center.x+circle2->radius)));
+}
+
+/* circle_left - is circle1 strictly left of circle2?
+ */
+bool circle_left(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle((circle1->center.x+circle1->radius),(circle2->center.x-circle2->radius)));
+}
+
+/* circle_right - is circle1 strictly right of circle2?
+ */
+bool circle_right(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPge((circle1->center.x-circle1->radius),(circle2->center.x+circle2->radius)));
+}
+
+/* circle_overright - is the left edge of circle1 to the right of
+ * the left edge of circle2?
+ */
+bool circle_overright(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPge((circle1->center.x-circle1->radius),(circle2->center.x-circle2->radius)));
+}
+
+/* circle_contained - is circle1 contained by circle2?
+ */
+bool circle_contained(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle((point_dt(&circle1->center,&circle2->center)+circle1->radius),circle2->radius));
+}
+
+/* circle_contain - does circle1 contain circle2?
+ */
+bool circle_contain(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle((point_dt(&circle1->center,&circle2->center)+circle2->radius),circle1->radius));
+}
+
+
+/* circle_positionop -
+ * is circle1 entirely {above,below} circle2?
+ */
+bool circle_below(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle((circle1->center.y+circle1->radius),(circle2->center.y-circle2->radius)));
+}
+
+bool circle_above(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPge((circle1->center.y-circle1->radius),(circle2->center.y+circle2->radius)));
+}
+
+
+/* circle_relop - is area(circle1) relop area(circle2), within
+ * our accuracy constraint?
+ */
+bool circle_eq(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPeq(circle_ar(circle1), circle_ar(circle2)) );
+} /* circle_eq() */
+
+bool circle_ne(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( !circle_eq(circle1, circle2));
+} /* circle_ne() */
+
+bool circle_lt(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPlt(circle_ar(circle1), circle_ar(circle2)) );
+} /* circle_lt() */
+
+bool circle_gt(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPgt(circle_ar(circle1), circle_ar(circle2)) );
+} /* circle_gt() */
+
+bool circle_le(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPle(circle_ar(circle1), circle_ar(circle2)) );
+} /* circle_le() */
+
+bool circle_ge(CIRCLE *circle1, CIRCLE *circle2)
+{
+ return( FPge(circle_ar(circle1), circle_ar(circle2)) );
+} /* circle_ge() */
+
+
+/*----------------------------------------------------------
+ * "Arithmetic" operators on circles.
+ * circle_foo returns foo as an object (pointer) that
+ can be passed between languages.
+ * circle_xx is an internal routine which returns the
+ * actual value.
+ *---------------------------------------------------------*/
+
+CIRCLE *circle_copy(CIRCLE *circle);
+
+CIRCLE *
+circle_copy(CIRCLE *circle)
+{
+ CIRCLE *result;
+
+ if (!PointerIsValid(circle))
+ return NULL;
+
+ if (!PointerIsValid(result = PALLOCTYPE(CIRCLE)))
+ elog(WARN, "Memory allocation failed, can't copy circle",NULL);
+
+ memmove((char *) result, (char *) circle, sizeof(CIRCLE));
+ return(result);
+} /* circle_copy() */
+
+
+/* circle_add_pt()
+ * Translation operator.
+ */
+CIRCLE *
+circle_add_pt(CIRCLE *circle, Point *point)
+{
+ CIRCLE *result;
+
+ if (!PointerIsValid(circle) && !PointerIsValid(point))
+ return(NULL);
+
+ if (! PointerIsValid(result = circle_copy(circle)))
+ elog(WARN, "Memory allocation failed, can't add circle",NULL);
+
+ result->center.x += point->x;
+ result->center.y += point->y;
+
+ return(result);
+} /* circle_add_pt() */
+
+CIRCLE *
+circle_sub_pt(CIRCLE *circle, Point *point)
+{
+ CIRCLE *result;
+
+ if (!PointerIsValid(circle) && !PointerIsValid(point))
+ return(NULL);
+
+ if (! PointerIsValid(result = circle_copy(circle)))
+ elog(WARN, "Memory allocation failed, can't subtract circle",NULL);
+
+ result->center.x -= point->x;
+ result->center.y -= point->y;
+
+ return(result);
+} /* circle_sub_pt() */
+
+
+/* circle_mul_pt()
+ * Rotation and scaling operators.
+ */
+CIRCLE *
+circle_mul_pt(CIRCLE *circle, Point *point)
+{
+ CIRCLE *result;
+ Point *p;
+
+ if (!PointerIsValid(circle) && !PointerIsValid(point))
+ return(NULL);
+
+ if (! PointerIsValid(result = circle_copy(circle)))
+ elog(WARN, "Memory allocation failed, can't multiply circle",NULL);
+
+ p = point_mul( &circle->center, point);
+ result->center.x = p->x;
+ result->center.y = p->y;
+ PFREE(p);
+ result->radius *= HYPOT( point->x, point->y);
+
+ return(result);
+} /* circle_mul_pt() */
+
+CIRCLE *
+circle_div_pt(CIRCLE *circle, Point *point)
+{
+ CIRCLE *result;
+ Point *p;
+
+ if (!PointerIsValid(circle) && !PointerIsValid(point))
+ return(NULL);
+
+ if (! PointerIsValid(result = circle_copy(circle)))
+ elog(WARN, "Memory allocation failed, can't add circle",NULL);
+
+ p = point_div( &circle->center, point);
+ result->center.x = p->x;
+ result->center.y = p->y;
+ PFREE(p);
+ result->radius /= HYPOT( point->x, point->y);
+
+ return(result);
+} /* circle_div_pt() */
+
+
+/* circle_area - returns the area of the circle.
+ */
+double *circle_area(CIRCLE *circle)
+{
+ double *result;
+
+ result = PALLOCTYPE(double);
+ *result = circle_ar(circle);
+
+ return(result);
+}
+
+
+/* circle_diameter - returns the diameter of the circle.
+ */
+double *circle_diameter(CIRCLE *circle)
+{
+ double *result;
+
+ result = PALLOCTYPE(double);
+ *result = (2*circle->radius);
+
+ return(result);
+}
+
+
+/* circle_radius - returns the radius of the circle.
+ */
+double *circle_radius(CIRCLE *circle)
+{
+ double *result;
+
+ result = PALLOCTYPE(double);
+ *result = circle->radius;
+
+ return(result);
+}
+
+
+/* circle_distance - returns the distance between the
+ * center points of two circlees.
+ */
+double *circle_distance(CIRCLE *circle1, CIRCLE *circle2)
+{
+ double *result;
+
+ result = PALLOCTYPE(double);
+ *result = point_dt(&circle1->center,&circle2->center);
+
+ return(result);
+}
+
+
+/* circle_center - returns the center point of the circle.
+ */
+Point *circle_center(CIRCLE *circle)
+{
+ Point *result;
+
+ result = PALLOCTYPE(Point);
+ result->x = circle->center.x;
+ result->y = circle->center.y;
+
+ return(result);
+}
+
+
+/* circle_ar - returns the area of the circle.
+ */
+double circle_ar(CIRCLE *circle)
+{
+ return(PI*(circle->radius*circle->radius));
+}
+
+
+/* circle_dt - returns the distance between the
+ * center points of two circlees.
+ */
+double circle_dt(CIRCLE *circle1, CIRCLE *circle2)
+{
+ double result;
+
+ result = point_dt(&circle1->center,&circle2->center);
+
+ return(result);
+}
+
+
+/*----------------------------------------------------------
+ * Conversion operators.
+ *---------------------------------------------------------*/
+
+CIRCLE *circle(Point *center, float8 *radius)
+{
+ CIRCLE *result;
+
+ if (! (PointerIsValid(center) && PointerIsValid(radius)))
+ return(NULL);
+
+ if (!PointerIsValid(result = PALLOCTYPE(CIRCLE)))
+ elog(WARN, "Memory allocation failed, can't convert point to circle",NULL);
+
+ result->center.x = center->x;
+ result->center.y = center->y;
+ result->radius = *radius;
+
+ return(result);
+}
+
+POLYGON *circle_poly(int npts, CIRCLE *circle)
+{
+ POLYGON *poly;
+ int size;
+ int i;
+ double angle;
+
+ if (!PointerIsValid(circle))
+ return(NULL);
+
+ if (FPzero(circle->radius) || (npts <= 2))
+ elog (WARN, "Unable to convert circle to polygon", NULL);
+
+ size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * npts);
+ if (!PointerIsValid(poly = (POLYGON *) PALLOC(size)))
+ elog(WARN, "Memory allocation failed, can't convert circle to polygon",NULL);
+
+ memset((char *) poly, 0, size); /* zero any holes */
+ poly->size = size;
+ poly->npts = npts;
+
+ for (i=0;i
+ angle = i*(2*PI/npts);
+ poly->p[i].x = circle->center.x - (circle->radius*cos(angle));
+ poly->p[i].y = circle->center.y + (circle->radius*sin(angle));
+ };
+
+ make_bound_box(poly);
+
+ return(poly);
+}
+
+/* poly_circle - convert polygon to circle
+ *
+ * XXX This algorithm should use weighted means of line segments
+ * rather than straight average values of points - tgl 97/01/21.
+ */
+CIRCLE *poly_circle(POLYGON *poly)
+{
+ CIRCLE *circle;
+ int i;
+
+ if (!PointerIsValid(poly))
+ return(NULL);
+
+ if (poly->npts <= 2)
+ elog (WARN, "Unable to convert polygon to circle", NULL);
+
+ if (!PointerIsValid(circle = PALLOCTYPE(CIRCLE)))
+ elog(WARN, "Memory allocation failed, can't convert polygon to circle",NULL);
+
+ circle->center.x = 0;
+ circle->center.y = 0;
+ circle->radius = 0;
+
+ circle->center.x += poly->p[i].x;
+ circle->center.y += poly->p[i].y;
+ };
+ circle->center.x /= poly->npts;
+ circle->center.y /= poly->npts;
+
+ circle->radius += point_dt( &poly->p[i], &circle->center);
+ };
+ circle->radius /= poly->npts;
+
+ if (FPzero(circle->radius))
+ elog (WARN, "Unable to convert polygon to circle", NULL);
+
+ return(circle);
+}
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_operator.h,v 1.8 1997/04/15 17:40:44 scrappy Exp $
+ * $Id: pg_operator.h,v 1.9 1997/04/22 17:31:49 scrappy Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
DATA(insert OID = 514 ( "*" PGUID 0 b t f 23 23 23 514 0 0 0 int4mul intltsel intltjoinsel ));
DATA(insert OID = 515 ( "!" PGUID 0 r t f 23 0 23 0 0 0 0 int4fac intltsel intltjoinsel ));
DATA(insert OID = 516 ( "!!" PGUID 0 l t f 0 23 23 0 0 0 0 int4fac intltsel intltjoinsel ));
-DATA(insert OID = 517 ( "<===>" PGUID 0 b t f 600 600 701 0 0 0 0 point_distance intltsel intltjoinsel ));
+DATA(insert OID = 517 ( "<===>" PGUID 0 b t f 600 600 701 517 0 0 0 point_distance intltsel intltjoinsel ));
DATA(insert OID = 518 ( "<>" PGUID 0 b t f 23 23 16 518 96 0 0 int4ne neqsel neqjoinsel ));
DATA(insert OID = 519 ( "<>" PGUID 0 b t f 21 21 16 519 94 0 0 int2ne neqsel neqjoinsel ));
DATA(insert OID = 520 ( ">" PGUID 0 b t f 21 21 16 95 0 0 0 int2gt intgtsel intgtjoinsel ));
DATA(insert OID = 610 ( ">" PGUID 0 b t f 26 26 16 609 611 0 0 int4gt intgtsel intgtjoinsel ));
DATA(insert OID = 611 ( "<=" PGUID 0 b t f 26 26 16 612 610 0 0 int4le intltsel intltjoinsel ));
DATA(insert OID = 612 ( ">=" PGUID 0 b t f 26 26 16 611 609 0 0 int4ge intgtsel intgtjoinsel ));
+
+DATA(insert OID = 613 ( "<===>" PGUID 0 b t f 600 603 701 613 0 0 0 dist_pl intltsel intltjoinsel ));
+DATA(insert OID = 614 ( "<===>" PGUID 0 b t f 600 601 701 614 0 0 0 dist_ps intltsel intltjoinsel ));
+DATA(insert OID = 615 ( "<===>" PGUID 0 b t f 600 603 701 615 0 0 0 dist_pb intltsel intltjoinsel ));
+DATA(insert OID = 616 ( "<===>" PGUID 0 b t f 600 603 701 616 0 0 0 dist_ps intltsel intltjoinsel ));
+DATA(insert OID = 617 ( "<===>" PGUID 0 b t f 601 603 701 617 0 0 0 dist_sb intltsel intltjoinsel ));
+DATA(insert OID = 618 ( "<===>" PGUID 0 b t f 600 602 701 618 0 0 0 dist_ppth intltsel intltjoinsel ));
+
DATA(insert OID = 620 ( "=" PGUID 0 b t t 700 700 16 620 621 622 622 float4eq eqsel eqjoinsel ));
DATA(insert OID = 621 ( "<>" PGUID 0 b t f 700 700 16 621 620 0 0 float4ne neqsel neqjoinsel ));
DATA(insert OID = 622 ( "<" PGUID 0 b t f 700 700 16 623 625 0 0 float4lt intltsel intltjoinsel ));
DATA(insert OID = 697 ( "~" PGUID 0 b t f 411 25 16 0 698 0 0 char8regexeq eqsel eqjoinsel ));
DATA(insert OID = 698 ( "!~" PGUID 0 b t f 411 25 16 0 697 0 0 char8regexne neqsel neqjoinsel ));
+DATA(insert OID = 706 ( "<===>" PGUID 0 b t f 603 603 701 706 0 0 0 box_distance intltsel intltjoinsel ));
+DATA(insert OID = 707 ( "<===>" PGUID 0 b t f 602 602 701 707 0 0 0 path_distance intltsel intltjoinsel ));
+DATA(insert OID = 708 ( "<===>" PGUID 0 b t f 603 603 701 708 0 0 0 line_distance intltsel intltjoinsel ));
+DATA(insert OID = 709 ( "<===>" PGUID 0 b t f 601 601 701 709 0 0 0 lseg_distance intltsel intltjoinsel ));
+
DATA(insert OID = 830 ( "<" PGUID 0 b t f 810 810 16 834 833 0 0 oidint2lt intltsel intltjoinsel ));
DATA(insert OID = 831 ( "<=" PGUID 0 b t f 810 810 16 833 834 0 0 oidint2le intltsel intltjoinsel ));
DATA(insert OID = 832 ( "=" PGUID 0 b t f 810 810 16 832 835 0 0 oidint2eq intltsel intltjoinsel ));
DATA(insert OID = 1304 ( "<=" PGUID 0 b t f 1296 1296 16 1305 1303 0 0 timestample intltsel intltjoinsel ));
DATA(insert OID = 1305 ( ">=" PGUID 0 b t f 1296 1296 16 1304 1302 0 0 timestampge intltsel intltjoinsel ));
-
+/* additional geometric operators - tgl 97/04/18 */
+DATA(insert OID = 1500 ( "=" PGUID 0 b t t 718 718 16 1500 1501 1502 1502 circle_eq eqsel eqjoinsel ));
+DATA(insert OID = 1501 ( "<>" PGUID 0 b t f 718 718 16 1501 1500 0 0 circle_ne neqsel neqjoinsel ));
+DATA(insert OID = 1502 ( "<" PGUID 0 b t f 718 718 16 1503 1505 0 0 circle_eq eqsel eqjoinsel ));
+DATA(insert OID = 1503 ( ">" PGUID 0 b t f 718 718 16 1502 1504 0 0 circle_eq eqsel eqjoinsel ));
+DATA(insert OID = 1504 ( "<=" PGUID 0 b t f 718 718 16 1505 1503 0 0 circle_eq eqsel eqjoinsel ));
+DATA(insert OID = 1505 ( ">=" PGUID 0 b t f 718 718 16 1504 1502 0 0 circle_eq eqsel eqjoinsel ));
+
+DATA(insert OID = 1506 ( "<<" PGUID 0 b t f 718 718 16 0 0 0 0 circle_left intltsel intltjoinsel ));
+DATA(insert OID = 1507 ( "&<" PGUID 0 b t f 718 718 16 0 0 0 0 circle_overleft intltsel intltjoinsel ));
+DATA(insert OID = 1508 ( "&>" PGUID 0 b t f 718 718 16 0 0 0 0 circle_overright intltsel intltjoinsel ));
+DATA(insert OID = 1509 ( ">>" PGUID 0 b t f 718 718 16 0 0 0 0 circle_right intltsel intltjoinsel ));
+DATA(insert OID = 1510 ( "@" PGUID 0 b t f 718 718 16 0 0 0 0 circle_contained intltsel intltjoinsel ));
+DATA(insert OID = 1511 ( "~" PGUID 0 b t f 718 718 16 0 0 0 0 circle_contain intltsel intltjoinsel ));
+DATA(insert OID = 1512 ( "~=" PGUID 0 b t f 718 718 16 1512 0 0 0 circle_same intltsel intltjoinsel ));
+DATA(insert OID = 1513 ( "&&" PGUID 0 b t f 718 718 16 0 0 0 0 circle_overlap intltsel intltjoinsel ));
+DATA(insert OID = 1514 ( "!^" PGUID 0 b t f 718 718 16 0 0 0 0 circle_above intltsel intltjoinsel ));
+DATA(insert OID = 1515 ( "!|" PGUID 0 b t f 718 718 16 0 0 0 0 circle_below intltsel intltjoinsel ));
+
+DATA(insert OID = 1516 ( "+" PGUID 0 b t f 718 600 718 1516 0 0 0 circle_add_pt - - ));
+DATA(insert OID = 1517 ( "-" PGUID 0 b t f 718 600 718 0 0 0 0 circle_sub_pt - - ));
+DATA(insert OID = 1518 ( "*" PGUID 0 b t f 718 600 718 1518 0 0 0 circle_mul_pt - - ));
+DATA(insert OID = 1519 ( "/" PGUID 0 b t f 718 600 718 0 0 0 0 circle_div_pt - - ));
+
+DATA(insert OID = 1520 ( "<===>" PGUID 0 b t f 718 718 701 1520 0 0 0 circle_distance intltsel intltjoinsel ));
+DATA(insert OID = 1521 ( "#" PGUID 0 l t f 0 604 23 0 0 0 0 poly_npoints - - ));
/*
* function prototypes
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_proc.h,v 1.17 1997/04/15 17:41:03 scrappy Exp $
+ * $Id: pg_proc.h,v 1.18 1997/04/22 17:32:12 scrappy Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
/* keep the following ordered by OID so that later changes can be made easier*/
/* OIDS 1 - 99 */
+
DATA(insert OID = 1242 ( boolin PGUID 11 f t f 1 f 16 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1243 ( boolout PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1244 ( byteain PGUID 11 f t f 1 f 17 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 699 ( char2regexeq PGUID 11 f t f 2 f 16 "409 25" 100 0 0 100 foo bar ));
/* OIDS 700 - 799 */
+
DATA(insert OID = 1288 ( char16regexeq PGUID 11 f t f 2 f 16 "19 25" 100 0 0 100 foo bar ));
DATA(insert OID = 1289 ( char16regexne PGUID 11 f t f 2 f 16 "19 25" 100 0 0 100 foo bar ));
DATA(insert OID = 716 ( oideqint4 PGUID 11 f t f 2 f 16 "26 23" 100 0 0 100 foo bar ));
DATA(insert OID = 717 ( int4eqoid PGUID 11 f t f 2 f 16 "23 26" 100 0 0 100 foo bar ));
-
DATA(insert OID = 720 ( byteaGetSize PGUID 11 f t f 1 f 23 "17" 100 0 0 100 foo bar ));
DATA(insert OID = 721 ( byteaGetByte PGUID 11 f t f 2 f 23 "17 23" 100 0 0 100 foo bar ));
DATA(insert OID = 722 ( byteaSetByte PGUID 11 f t f 3 f 17 "17 23 23" 100 0 0 100 foo bar ));
DATA(insert OID = 723 ( byteaGetBit PGUID 11 f t f 2 f 23 "17 23" 100 0 0 100 foo bar ));
DATA(insert OID = 724 ( byteaSetBit PGUID 11 f t f 3 f 17 "17 23 23" 100 0 0 100 foo bar ));
+DATA(insert OID = 725 ( dist_pl PGUID 11 f t f 2 f 701 "600 654" 100 0 0 100 foo bar ));
+DATA(insert OID = 726 ( dist_lb PGUID 11 f t f 2 f 701 "654 603" 100 0 0 100 foo bar ));
+DATA(insert OID = 727 ( dist_sl PGUID 11 f t f 2 f 701 "601 654" 100 0 0 100 foo bar ));
+
DATA(insert OID = 730 ( pqtest PGUID 11 f t f 1 f 23 "25" 100 0 0 100 foo bar ));
DATA(insert OID = 740 ( text_lt PGUID 11 f t f 2 f 16 "25 25" 100 0 0 0 foo bar ));
DATA(insert OID = 782 ( gistbuild PGUID 11 f t f 9 f 23 "0" 100 0 0 100 foo bar ));
/* OIDS 800 - 899 */
+
DATA(insert OID = 820 ( oidint2in PGUID 11 f t f 1 f 810 "0" 100 0 0 100 foo bar));
DATA(insert OID = 821 ( oidint2out PGUID 11 f t f 1 f 19 "0" 100 0 0 100 foo bar));
DATA(insert OID = 822 ( oidint2lt PGUID 11 f t f 2 f 16 "810 810" 100 0 0 100 foo bar));
DATA(insert OID = 1092 ( date_cmp PGUID 11 f t f 2 f 23 "1082 1082" 100 0 0 100 foo bar ));
/* OIDS 1100 - 1199 */
+
DATA(insert OID = 1102 ( time_lt PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1103 ( time_le PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1104 ( time_gt PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
/* reserve OIDs 1195-1199 for additional date/time conversion routines! tgl 97/03/19 */
/* OIDS 1200 - 1299 */
+
DATA(insert OID = 1200 ( int42reltime PGUID 11 f t f 1 f 703 "21" 100 0 0 100 foo bar ));
DATA(insert OID = 1290 ( char2icregexeq PGUID 11 f t f 2 f 16 "409 25" 100 0 0 100 foo bar ));
DATA(insert OID = 1299 ( now PGUID 11 f t f 0 f 1296 "0" 100 0 0 100 foo bar ));
/* OIDS 1300 - 1399 */
+
DATA(insert OID = 1306 ( timestampeq PGUID 11 f t f 2 f 16 "1296 1296" 100 0 0 100 foo bar ));
DATA(insert OID = 1307 ( timestampne PGUID 11 f t f 2 f 16 "1296 1296" 100 0 0 100 foo bar ));
DATA(insert OID = 1308 ( timestamplt PGUID 11 f t f 2 f 16 "1296 1296" 100 0 0 100 foo bar ));
/* reserve OIDs 1370-1399 for additional date/time conversion routines! tgl 97/04/01 */
/* OIDS 1400 - 1499 */
+
DATA(insert OID = 1400 ( float PGUID 14 f t f 1 f 701 "701" 100 0 0 100 "select $1" - ));
DATA(insert OID = 1401 ( float PGUID 14 f t f 1 f 701 "700" 100 0 0 100 "select ftod($1)" - ));
DATA(insert OID = 1402 ( float4 PGUID 14 f t f 1 f 700 "700" 100 0 0 100 "select $1" - ));
DATA(insert OID = 1404 ( int PGUID 14 f t f 1 f 23 "23" 100 0 0 100 "select $1" - ));
DATA(insert OID = 1405 ( int2 PGUID 14 f t f 1 f 21 "21" 100 0 0 100 "select $1" - ));
+DATA(insert OID = 1421 ( box PGUID 11 f t f 2 f 603 "600 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1422 ( box_add PGUID 11 f t f 2 f 603 "603 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1423 ( box_sub PGUID 11 f t f 2 f 603 "603 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1424 ( box_mul PGUID 11 f t f 2 f 603 "603 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1425 ( box_div PGUID 11 f t f 2 f 603 "603 600" 100 0 0 100 foo bar ));
+
+DATA(insert OID = 1430 ( path_isclosed PGUID 11 f t f 1 f 16 "602" 100 0 0 100 foo bar ));
+DATA(insert OID = 1431 ( path_isopen PGUID 11 f t f 1 f 16 "602" 100 0 0 100 foo bar ));
+DATA(insert OID = 1432 ( path_npoints PGUID 11 f t f 1 f 23 "602" 100 0 0 100 foo bar ));
+DATA(insert OID = 1433 ( path_close PGUID 11 f t f 1 f 602 "602" 100 0 0 100 foo bar ));
+DATA(insert OID = 1434 ( path_open PGUID 11 f t f 1 f 602 "602" 100 0 0 100 foo bar ));
+DATA(insert OID = 1435 ( path_add PGUID 11 f t f 2 f 602 "602 602" 100 0 0 100 foo bar ));
+DATA(insert OID = 1436 ( path_add_pt PGUID 11 f t f 2 f 602 "602 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1437 ( path_sub_pt PGUID 11 f t f 2 f 602 "602 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1438 ( path_mul_pt PGUID 11 f t f 2 f 602 "602 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1439 ( path_div_pt PGUID 11 f t f 2 f 602 "602 600" 100 0 0 100 foo bar ));
+
+DATA(insert OID = 1440 ( point PGUID 11 f t f 2 f 600 "701 701" 100 0 0 100 foo bar ));
+DATA(insert OID = 1441 ( point_add PGUID 11 f t f 2 f 600 "600 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1442 ( point_sub PGUID 11 f t f 2 f 600 "600 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1443 ( point_mul PGUID 11 f t f 2 f 600 "600 600" 100 0 0 100 foo bar ));
+DATA(insert OID = 1444 ( point_div PGUID 11 f t f 2 f 600 "600 600" 100 0 0 100 foo bar ));
+
+DATA(insert OID = 1445 ( poly_npoints PGUID 11 f t f 1 f 23 "604" 100 0 0 100 foo bar ));
+DATA(insert OID = 1446 ( poly_box PGUID 11 f t f 1 f 603 "604" 100 0 0 100 foo bar ));
+DATA(insert OID = 1447 ( poly_path PGUID 11 f t f 1 f 602 "604" 100 0 0 100 foo bar ));
+DATA(insert OID = 1448 ( box_poly PGUID 11 f t f 1 f 604 "603" 100 0 0 100 foo bar ));
+DATA(insert OID = 1449 ( path_poly PGUID 11 f t f 1 f 604 "602" 100 0 0 100 foo bar ));
+
+DATA(insert OID = 1450 ( circle_in PGUID 11 f t f 1 f 718 "0" 100 0 1 0 foo bar ));
+DATA(insert OID = 1451 ( circle_out PGUID 11 f t f 1 f 23 "0" 100 0 1 0 foo bar ));
+DATA(insert OID = 1452 ( circle_same PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1453 ( circle_contain PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1454 ( circle_left PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1455 ( circle_overleft PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1456 ( circle_overright PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1457 ( circle_right PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1458 ( circle_contained PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1459 ( circle_overlap PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1460 ( circle_below PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1461 ( circle_above PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1462 ( circle_eq PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1463 ( circle_ne PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1464 ( circle_lt PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1465 ( circle_gt PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1466 ( circle_le PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1467 ( circle_ge PGUID 11 f t f 2 f 16 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1468 ( circle_area PGUID 11 f t f 1 f 701 "718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1469 ( circle_diameter PGUID 11 f t f 1 f 701 "718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1470 ( circle_radius PGUID 11 f t f 1 f 701 "718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1471 ( circle_distance PGUID 11 f t f 2 f 701 "718 718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1472 ( circle_center PGUID 11 f t f 1 f 600 "718" 100 0 1 0 foo bar ));
+DATA(insert OID = 1473 ( circle PGUID 11 f t f 2 f 718 "600 701" 100 0 1 0 foo bar ));
+DATA(insert OID = 1474 ( poly_circle PGUID 11 f t f 1 f 718 "604" 100 0 1 0 foo bar ));
+DATA(insert OID = 1475 ( circle_poly PGUID 11 f t f 2 f 604 "23 718" 100 0 1 0 foo bar ));
+
+DATA(insert OID = 1530 ( point PGUID 14 f t f 2 f 600 "601 601" 100 0 0 100 "select lseg_interpt($1, $2)" - ));
+DATA(insert OID = 1531 ( point PGUID 14 f t f 1 f 600 "718" 100 0 0 100 "select circle_center($1)" - ));
+DATA(insert OID = 1532 ( isvertical PGUID 14 f t f 2 f 16 "600 600" 100 0 0 100 "select point_vert($1, $2)" - ));
+DATA(insert OID = 1533 ( ishorizonal PGUID 14 f t f 2 f 16 "600 600" 100 0 0 100 "select point_horiz($1, $2)" - ));
+DATA(insert OID = 1534 ( slope PGUID 14 f t f 2 f 701 "600 600" 100 0 0 100 "select point_slope($1, $2)" - ));
+
+DATA(insert OID = 1540 ( lseg PGUID 14 f t f 2 f 601 "600 600" 100 0 0 100 "select lseg_construct($1, $2)" - ));
+DATA(insert OID = 1541 ( lseg PGUID 14 f t f 1 f 601 "603" 100 0 0 100 "select box_diagonal($1)" - ));
+DATA(insert OID = 1542 ( isparallel PGUID 14 f t f 2 f 16 "601 601" 100 0 0 100 "select lseg_parallel($1, $2)" - ));
+DATA(insert OID = 1543 ( isperpendicular PGUID 14 f t f 2 f 16 "601 601" 100 0 0 100 "select lseg_perp($1, $2)" - ));
+DATA(insert OID = 1544 ( isvertical PGUID 14 f t f 1 f 16 "601" 100 0 0 100 "select lseg_vertical($1)" - ));
+DATA(insert OID = 1545 ( ishorizontal PGUID 14 f t f 1 f 16 "601" 100 0 0 100 "select lseg_horizontal($1)" - ));
+
+/* XXX "length" for boxes is different than "length" for paths, so use "width" for boxes instead.
+ * should go back into code and change subroutine name from "box_length" to "box_width".
+ * pclose and popen might better be named close and open, but that crashes initdb.
+ * - tgl 97/04/20
+ */
+
+DATA(insert OID = 1550 ( path PGUID 14 f t f 1 f 602 "604" 100 0 0 100 "select poly_path($1)" - ));
+DATA(insert OID = 1551 ( length PGUID 14 f t f 1 f 701 "602" 100 0 1 0 "select path_length($1)" - ));
+DATA(insert OID = 1552 ( points PGUID 14 f t f 1 f 23 "602" 100 0 0 100 "select path_npoints($1)" - ));
+DATA(insert OID = 1553 ( pclose PGUID 14 f t f 1 f 602 "602" 100 0 0 100 "select path_close($1)" - ));
+DATA(insert OID = 1554 ( popen PGUID 14 f t f 1 f 602 "602" 100 0 0 100 "select path_open($1)" - ));
+DATA(insert OID = 1555 ( isopen PGUID 14 f t f 1 f 16 "602" 100 0 0 100 "select path_isopen($1)" - ));
+DATA(insert OID = 1555 ( isclosed PGUID 14 f t f 1 f 16 "602" 100 0 0 100 "select path_isclosed($1)" - ));
+
+DATA(insert OID = 1560 ( box PGUID 14 f t f 2 f 603 "603 603" 100 0 0 100 "select box_intersect($1, $2)" - ));
+DATA(insert OID = 1561 ( box PGUID 14 f t f 1 f 603 "604" 100 0 0 100 "select poly_box($1)" - ));
+DATA(insert OID = 1562 ( width PGUID 14 f t f 1 f 701 "603" 100 0 0 100 "select box_length($1)" - ));
+DATA(insert OID = 1563 ( height PGUID 14 f t f 1 f 701 "603" 100 0 0 100 "select box_height($1)" - ));
+DATA(insert OID = 1564 ( center PGUID 14 f t f 1 f 600 "603" 100 0 0 100 "select box_center($1)" - ));
+DATA(insert OID = 1565 ( area PGUID 14 f t f 1 f 701 "603" 100 0 0 100 "select box_area($1)" - ));
+
+DATA(insert OID = 1570 ( polygon PGUID 14 f t f 1 f 604 "602" 100 0 0 100 "select path_poly($1)" - ));
+DATA(insert OID = 1571 ( polygon PGUID 14 f t f 1 f 604 "603" 100 0 0 100 "select box_poly($1)" - ));
+DATA(insert OID = 1572 ( polygon PGUID 14 f t f 2 f 604 "23 718" 100 0 0 100 "select circle_poly($1, $2)" - ));
+DATA(insert OID = 1573 ( polygon PGUID 14 f t f 1 f 604 "718" 100 0 0 100 "select circle_poly(12, $1)" - ));
+DATA(insert OID = 1574 ( points PGUID 14 f t f 1 f 23 "604" 100 0 0 100 "select poly_npoints($1)" - ));
+DATA(insert OID = 1575 ( center PGUID 14 f t f 1 f 600 "604" 100 0 0 100 "select poly_center($1)" - ));
+
+DATA(insert OID = 1580 ( circle PGUID 14 f t f 1 f 701 "604" 100 0 0 100 "select poly_circle($1)" - ));
+DATA(insert OID = 1581 ( center PGUID 14 f t f 1 f 600 "718" 100 0 0 100 "select circle_center($1)" - ));
+DATA(insert OID = 1582 ( radius PGUID 14 f t f 1 f 701 "718" 100 0 0 100 "select circle_radius($1)" - ));
+DATA(insert OID = 1583 ( diameter PGUID 14 f t f 1 f 701 "718" 100 0 0 100 "select circle_diameter($1)" - ));
+DATA(insert OID = 1584 ( area PGUID 14 f t f 1 f 701 "718" 100 0 0 100 "select circle_area($1)" - ));
+
/* Oracle Compatibility Related Functions - By Edmund Mergl */
DATA(insert OID = 870 ( lower PGUID 11 f t f 1 f 25 "25" 100 0 0 100 foo bar ));
DATA(insert OID = 871 ( upper PGUID 11 f t f 1 f 25 "25" 100 0 0 100 foo bar ));
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_type.h,v 1.10 1997/04/15 17:41:19 scrappy Exp $
+ * $Id: pg_type.h,v 1.11 1997/04/22 17:32:26 scrappy Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
DATA(insert OID = 602 ( path PGUID -1 -1 f b t \054 0 600 path_in path_out path_in path_out d _null_ ));
DATA(insert OID = 603 ( box PGUID 32 100 f b t \073 0 600 box_in box_out box_in box_out d _null_ ));
DATA(insert OID = 604 ( polygon PGUID -1 -1 f b t \054 0 -1 poly_in poly_out poly_in poly_out d _null_ ));
-DATA(insert OID = 605 ( filename PGUID 256 -1 f b t \054 0 18 filename_in filename_out filename_in filename_out i _null_ ));
+DATA(insert OID = 605 ( filename PGUID 256 -1 f b t \054 0 18 filename_in filename_out filename_in filename_out i _null_ ));
+
+DATA(insert OID = 628 ( line PGUID 32 48 f b t \054 0 701 line_in line_out line_in line_out d _null_ ));
+DATA(insert OID = 629 ( _line PGUID -1 -1 f b t \054 0 628 array_in array_out array_in array_out d _null_ ));
/* OIDS 700 - 799 */
DATA(insert OID = 705 ( unknown PGUID -1 -1 f b t \054 0 18 textin textout textin textout i _null_ ));
#define UNKNOWNOID 705
-DATA(insert OID = 790 ( money PGUID 4 47 f b t \054 0 0 cash_in cash_out cash_in cash_out i _null_ ));
-#define CASHOID 790
+DATA(insert OID = 718 ( circle PGUID 24 47 f b t \054 0 0 circle_in circle_out circle_in circle_out d _null_ ));
+DATA(insert OID = 719 ( _circle PGUID -1 -1 f b t \054 0 718 array_in array_out array_in array_out i _null_ ));
+DATA(insert OID = 790 ( money PGUID 4 24 f b t \054 0 0 cash_in cash_out cash_in cash_out i _null_ ));
DATA(insert OID = 791 ( _money PGUID -1 -1 f b t \054 0 790 array_in array_out array_in array_out i _null_ ));
/* OIDS 800 - 899 */
/*-------------------------------------------------------------------------
*
- * geo_decls.h--
- * Declarations for various 2D constructs.
+ * geo_decls.h - Declarations for various 2D constructs.
*
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: geo_decls.h,v 1.1 1997/03/14 23:33:27 scrappy Exp $
+ * $Id: geo_decls.h,v 1.2 1997/04/22 17:32:41 scrappy Exp $
*
* NOTE
* These routines do *not* use the float types from adt/.
*
* XXX These routines were not written by a numerical analyst.
+ * XXX I have made some attempt to flesh out the operators
+ * and data types. There are still some more to do. - tgl 97/04/19
*
*-------------------------------------------------------------------------
*/
/*#ifndef FmgrIncluded -- seems like always included. (it's FMgrIncluded) AY */
/*--------------------------------------------------------------------
- * Useful floating point utilities and constants.
+ * Useful floating point utilities and constants.
*-------------------------------------------------------------------*/
#define EPSILON 1.0E-06
+#ifdef EPSILON
#define FPzero(A) (fabs(A) <= EPSILON)
#define FPeq(A,B) (fabs((A) - (B)) <= EPSILON)
#define FPlt(A,B) ((B) - (A) > EPSILON)
#define FPle(A,B) ((A) - (B) <= EPSILON)
#define FPgt(A,B) ((A) - (B) > EPSILON)
#define FPge(A,B) ((B) - (A) <= EPSILON)
+#else
+#define FPzero(A) (A == 0)
+#define FPeq(A,B) (A == B)
+#define FPlt(A,B) (A < B)
+#define FPle(A,B) (A <= B)
+#define FPgt(A,B) (A > B)
+#define FPge(A,B) (A >= B)
+#endif
#define HYPOT(A, B) sqrt((A) * (A) + (B) * (B))
/*--------------------------------------------------------------------
- * Memory management.
+ * Memory management.
*-------------------------------------------------------------------*/
#define PALLOC(SIZE) palloc(SIZE)
/*#endif !FmgrIncluded */
/*---------------------------------------------------------------------
- * Point - (x,y)
+ * Point - (x,y)
*-------------------------------------------------------------------*/
typedef struct {
double x, y;
/*---------------------------------------------------------------------
- * LSEG - A straight line, specified by endpoints.
+ * LSEG - A straight line, specified by endpoints.
*-------------------------------------------------------------------*/
typedef struct {
Point p[2];
/*---------------------------------------------------------------------
- * PATH - Specified by vertex points.
+ * PATH - Specified by vertex points.
*-------------------------------------------------------------------*/
typedef struct {
- int32 length; /* XXX varlena */
+ int32 size; /* XXX varlena */
int32 npts;
int32 closed; /* is this a closed polygon? */
int32 dummy; /* padding to make it double align */
- Point p[1]; /* variable length array of POINTs */
+ Point p[0]; /* variable length array of POINTs */
} PATH;
/*---------------------------------------------------------------------
- * LINE - Specified by its general equation (Ax+By+C=0).
- * If there is a y-intercept, it is C, which
- * incidentally gives a freebie point on the line
- * (if B=0, then C is the x-intercept).
- * Slope m is precalculated to save time; if
- * the line is not vertical, m == A.
+ * LINE - Specified by its general equation (Ax+By+C=0).
+ * If there is a y-intercept, it is C, which
+ * incidentally gives a freebie point on the line
+ * (if B=0, then C is the x-intercept).
+ * Slope m is precalculated to save time; if
+ * the line is not vertical, m == A.
*-------------------------------------------------------------------*/
typedef struct {
double A, B, C;
/*---------------------------------------------------------------------
- * BOX - Specified by two corner points, which are
- * sorted to save calculation time later.
+ * BOX - Specified by two corner points, which are
+ * sorted to save calculation time later.
*-------------------------------------------------------------------*/
typedef struct {
- double xh, yh, xl, yl; /* high and low coords */
+ Point high, low; /* corner POINTs */
} BOX;
/*---------------------------------------------------------------------
- * POLYGON - Specified by an array of doubles defining the points,
- * keeping the number of points and the bounding box for
- * speed purposes.
+ * POLYGON - Specified by an array of doubles defining the points,
+ * keeping the number of points and the bounding box for
+ * speed purposes.
*-------------------------------------------------------------------*/
typedef struct {
int32 size; /* XXX varlena */
int32 npts;
BOX boundbox;
- char pts[1];
+ Point p[0]; /* variable length array of POINTs */
} POLYGON;
+/*---------------------------------------------------------------------
+ * CIRCLE - Specified by a center point and radius.
+ *-------------------------------------------------------------------*/
+typedef struct {
+ Point center;
+ double radius;
+} CIRCLE;
/*
* in geo_ops.h
extern BOX *box_construct(double x1, double x2, double y1, double y2);
extern BOX *box_fill(BOX *result, double x1, double x2, double y1, double y2);
extern BOX *box_copy(BOX *box);
-extern long box_same(BOX *box1, BOX *box2);
-extern long box_overlap(BOX *box1, BOX *box2);
-extern long box_overleft(BOX *box1, BOX *box2);
-extern long box_left(BOX *box1, BOX *box2);
-extern long box_right(BOX *box1, BOX *box2);
-extern long box_overright(BOX *box1, BOX *box2);
-extern long box_contained(BOX *box1, BOX *box2);
-extern long box_contain(BOX *box1, BOX *box2);
-extern long box_below(BOX *box1, BOX *box2);
-extern long box_above(BOX *box1, BOX *box2);
-extern long box_lt(BOX *box1, BOX *box2);
-extern long box_gt(BOX *box1, BOX *box2);
-extern long box_eq(BOX *box1, BOX *box2);
-extern long box_le(BOX *box1, BOX *box2);
-extern long box_ge(BOX *box1, BOX *box2);
+extern bool box_same(BOX *box1, BOX *box2);
+extern bool box_overlap(BOX *box1, BOX *box2);
+extern bool box_overleft(BOX *box1, BOX *box2);
+extern bool box_left(BOX *box1, BOX *box2);
+extern bool box_right(BOX *box1, BOX *box2);
+extern bool box_overright(BOX *box1, BOX *box2);
+extern bool box_contained(BOX *box1, BOX *box2);
+extern bool box_contain(BOX *box1, BOX *box2);
+extern bool box_below(BOX *box1, BOX *box2);
+extern bool box_above(BOX *box1, BOX *box2);
+extern bool box_lt(BOX *box1, BOX *box2);
+extern bool box_gt(BOX *box1, BOX *box2);
+extern bool box_eq(BOX *box1, BOX *box2);
+extern bool box_le(BOX *box1, BOX *box2);
+extern bool box_ge(BOX *box1, BOX *box2);
+extern Point *box_center(BOX *box);
extern double *box_area(BOX *box);
extern double *box_length(BOX *box);
extern double *box_height(BOX *box);
extern double *box_distance(BOX *box1, BOX *box2);
extern Point *box_center(BOX *box);
+extern BOX *box_intersect(BOX *box1, BOX *box2);
+extern LSEG *box_diagonal(BOX *box);
+
+/* private routines */
extern double box_ar(BOX *box);
extern double box_ln(BOX *box);
extern double box_ht(BOX *box);
extern double box_dt(BOX *box1, BOX *box2);
-extern BOX *box_intersect(BOX *box1, BOX *box2);
-extern LSEG *box_diagonal(BOX *box);
+
+extern BOX *box(Point *p1, Point *p2);
+extern BOX *box_add(BOX *box, Point *p);
+extern BOX *box_sub(BOX *box, Point *p);
+extern BOX *box_mul(BOX *box, Point *p);
+extern BOX *box_div(BOX *box, Point *p);
+
extern LINE *line_construct_pm(Point *pt, double m);
extern LINE *line_construct_pp(Point *pt1, Point *pt2);
-extern long line_intersect(LINE *l1, LINE *l2);
-extern long line_parallel(LINE *l1, LINE *l2);
-extern long line_perp(LINE *l1, LINE *l2);
-extern long line_vertical(LINE *line);
-extern long line_horizontal(LINE *line);
-extern long line_eq(LINE *l1, LINE *l2);
+extern bool line_intersect(LINE *l1, LINE *l2);
+extern bool line_parallel(LINE *l1, LINE *l2);
+extern bool line_perp(LINE *l1, LINE *l2);
+extern bool line_vertical(LINE *line);
+extern bool line_horizontal(LINE *line);
+extern bool line_eq(LINE *l1, LINE *l2);
extern double *line_distance(LINE *l1, LINE *l2);
extern Point *line_interpt(LINE *l1, LINE *l2);
+
extern PATH *path_in(char *str);
extern char *path_out(PATH *path);
-extern long path_n_lt(PATH *p1, PATH *p2);
-extern long path_n_gt(PATH *p1, PATH *p2);
-extern long path_n_eq(PATH *p1, PATH *p2);
-extern long path_n_le(PATH *p1, PATH *p2);
-extern long path_n_ge(PATH *p1, PATH *p2);
-extern long path_inter(PATH *p1, PATH *p2);
+extern bool path_n_lt(PATH *p1, PATH *p2);
+extern bool path_n_gt(PATH *p1, PATH *p2);
+extern bool path_n_eq(PATH *p1, PATH *p2);
+extern bool path_n_le(PATH *p1, PATH *p2);
+extern bool path_n_ge(PATH *p1, PATH *p2);
+extern bool path_inter(PATH *p1, PATH *p2);
extern double *path_distance(PATH *p1, PATH *p2);
extern double *path_length(PATH *path);
+
+/* private routines */
extern double path_ln(PATH *path);
+
+extern bool path_isclosed(PATH *path);
+extern bool path_isopen(PATH *path);
+extern int4 path_npoints(PATH *path);
+
+extern PATH *path_close(PATH *path);
+extern PATH *path_open(PATH *path);
+extern PATH *path_add(PATH *p1, PATH *p2);
+extern PATH *path_add_pt(PATH *path, Point *point);
+extern PATH *path_sub_pt(PATH *path, Point *point);
+extern PATH *path_mul_pt(PATH *path, Point *point);
+extern PATH *path_div_pt(PATH *path, Point *point);
+
+extern POLYGON *path_poly(PATH *path);
+
extern Point *point_in(char *str);
extern char *point_out(Point *pt);
extern Point *point_construct(double x, double y);
extern Point *point_copy(Point *pt);
-extern long point_left(Point *pt1, Point *pt2);
-extern long point_right(Point *pt1, Point *pt2);
-extern long point_above(Point *pt1, Point *pt2);
-extern long point_below(Point *pt1, Point *pt2);
-extern long point_vert(Point *pt1, Point *pt2);
-extern long point_horiz(Point *pt1, Point *pt2);
-extern long point_eq(Point *pt1, Point *pt2);
-extern long pointdist(Point *p1, Point *p2);
+extern bool point_left(Point *pt1, Point *pt2);
+extern bool point_right(Point *pt1, Point *pt2);
+extern bool point_above(Point *pt1, Point *pt2);
+extern bool point_below(Point *pt1, Point *pt2);
+extern bool point_vert(Point *pt1, Point *pt2);
+extern bool point_horiz(Point *pt1, Point *pt2);
+extern bool point_eq(Point *pt1, Point *pt2);
+extern int32 pointdist(Point *p1, Point *p2);
extern double *point_distance(Point *pt1, Point *pt2);
-extern double point_dt(Point *pt1, Point *pt2);
extern double *point_slope(Point *pt1, Point *pt2);
+
+/* private routines */
+extern double point_dt(Point *pt1, Point *pt2);
extern double point_sl(Point *pt1, Point *pt2);
+
+extern Point *point(float8 *x, float8 *y);
+extern Point *point_add(Point *p1, Point *p2);
+extern Point *point_sub(Point *p1, Point *p2);
+extern Point *point_mul(Point *p1, Point *p2);
+extern Point *point_div(Point *p1, Point *p2);
+
extern LSEG *lseg_in(char *str);
extern char *lseg_out(LSEG *ls);
-extern LSEG *lseg_construct(Point *pt1, Point *pt2);
-extern void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
-extern long lseg_intersect(LSEG *l1, LSEG *l2);
-extern long lseg_parallel(LSEG *l1, LSEG *l2);
-extern long lseg_perp(LSEG *l1, LSEG *l2);
-extern long lseg_vertical(LSEG *lseg);
-extern long lseg_horizontal(LSEG *lseg);
-extern long lseg_eq(LSEG *l1, LSEG *l2);
+extern bool lseg_intersect(LSEG *l1, LSEG *l2);
+extern bool lseg_parallel(LSEG *l1, LSEG *l2);
+extern bool lseg_perp(LSEG *l1, LSEG *l2);
+extern bool lseg_vertical(LSEG *lseg);
+extern bool lseg_horizontal(LSEG *lseg);
+extern bool lseg_eq(LSEG *l1, LSEG *l2);
extern double *lseg_distance(LSEG *l1, LSEG *l2);
-extern double lseg_dt(LSEG *l1, LSEG *l2);
extern Point *lseg_interpt(LSEG *l1, LSEG *l2);
extern double *dist_pl(Point *pt, LINE *line);
extern double *dist_ps(Point *pt, LSEG *lseg);
extern Point *close_sl(LSEG *lseg, LINE *line);
extern Point *close_sb(LSEG *lseg, BOX *box);
extern Point *close_lb(LINE *line, BOX *box);
-extern long on_pl(Point *pt, LINE *line);
-extern long on_ps(Point *pt, LSEG *lseg);
-extern long on_pb(Point *pt, BOX *box);
-extern long on_ppath(Point *pt, PATH *path);
-extern long on_sl(LSEG *lseg, LINE *line);
-extern long on_sb(LSEG *lseg, BOX *box);
-extern long inter_sl(LSEG *lseg, LINE *line);
-extern long inter_sb(LSEG *lseg, BOX *box);
-extern long inter_lb(LINE *line, BOX *box);
+extern bool on_pl(Point *pt, LINE *line);
+extern bool on_ps(Point *pt, LSEG *lseg);
+extern bool on_pb(Point *pt, BOX *box);
+extern bool on_ppath(Point *pt, PATH *path);
+extern bool on_sl(LSEG *lseg, LINE *line);
+extern bool on_sb(LSEG *lseg, BOX *box);
+extern bool inter_sl(LSEG *lseg, LINE *line);
+extern bool inter_sb(LSEG *lseg, BOX *box);
+extern bool inter_lb(LINE *line, BOX *box);
+
+/* private routines */
+extern LSEG *lseg_construct(Point *pt1, Point *pt2);
+extern void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
+extern double lseg_dt(LSEG *l1, LSEG *l2);
extern void make_bound_box(POLYGON *poly);
+
extern POLYGON *poly_in(char *s);
-extern long poly_pt_count(char *s, char delim);
extern char *poly_out(POLYGON *poly);
-extern double poly_max(double *coords, int ncoords);
-extern double poly_min(double *coords, int ncoords);
-extern long poly_left(POLYGON *polya, POLYGON *polyb);
-extern long poly_overleft(POLYGON *polya, POLYGON *polyb);
-extern long poly_right(POLYGON *polya, POLYGON *polyb);
-extern long poly_overright(POLYGON *polya, POLYGON *polyb);
-extern long poly_same(POLYGON *polya, POLYGON *polyb);
-extern long poly_overlap(POLYGON *polya, POLYGON *polyb);
-extern long poly_contain(POLYGON *polya, POLYGON *polyb);
-extern long poly_contained(POLYGON *polya, POLYGON *polyb);
+extern bool poly_left(POLYGON *polya, POLYGON *polyb);
+extern bool poly_overleft(POLYGON *polya, POLYGON *polyb);
+extern bool poly_right(POLYGON *polya, POLYGON *polyb);
+extern bool poly_overright(POLYGON *polya, POLYGON *polyb);
+extern bool poly_same(POLYGON *polya, POLYGON *polyb);
+extern bool poly_overlap(POLYGON *polya, POLYGON *polyb);
+extern bool poly_contain(POLYGON *polya, POLYGON *polyb);
+extern bool poly_contained(POLYGON *polya, POLYGON *polyb);
+
+extern int4 poly_npoints(POLYGON *poly);
+extern BOX *poly_box(POLYGON *poly);
+extern PATH *poly_path(POLYGON *poly);
+extern POLYGON *box_poly(BOX *box);
+
+extern CIRCLE *circle_in(char *str);
+extern char *circle_out(CIRCLE *circle);
+extern bool circle_same(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_overlap(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_overleft(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_left(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_right(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_overright(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_contained(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_contain(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_below(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_above(CIRCLE *circle1, CIRCLE *circle2);
+
+extern bool circle_eq(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_ne(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_lt(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_gt(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_le(CIRCLE *circle1, CIRCLE *circle2);
+extern bool circle_ge(CIRCLE *circle1, CIRCLE *circle2);
+extern CIRCLE *circle_add_pt(CIRCLE *circle, Point *point);
+extern CIRCLE *circle_sub_pt(CIRCLE *circle, Point *point);
+extern CIRCLE *circle_mul_pt(CIRCLE *circle, Point *point);
+extern CIRCLE *circle_div_pt(CIRCLE *circle, Point *point);
+extern double *circle_area(CIRCLE *circle);
+extern double *circle_diameter(CIRCLE *circle);
+extern double *circle_radius(CIRCLE *circle);
+extern double *circle_distance(CIRCLE *circle1, CIRCLE *circle2);
+extern Point *circle_center(CIRCLE *circle);
+extern CIRCLE *circle(Point *center, float8 *radius);
+extern CIRCLE *poly_circle(POLYGON *poly);
+extern POLYGON *circle_poly(int npts, CIRCLE *circle);
+
+/* private routines */
+extern double circle_ar(CIRCLE *circle);
+extern double circle_dt(CIRCLE *circle1, CIRCLE *circle2);
/* geo_selfuncs.c */
extern float64 areasel(Oid opid, Oid relid, AttrNumber attno,
extern float64 contsel(Oid opid, Oid relid, AttrNumber attno,
char *value, int32 flag);
extern float64 contjoinsel(Oid opid, Oid relid, AttrNumber attno,
- char *value, int32 flag);
+ char *value, int32 flag);
#endif /* GEO_DECLS_H */
);
QUERY: CREATE OPERATOR <% (
leftarg = point,
- rightarg = circle,
- procedure = pt_in_circle,
+ rightarg = widget,
+ procedure = pt_in_widget,
commutator = >=%
);
QUERY: CREATE OPERATOR @#@ (
-QUERY: CREATE TYPE circle (
+QUERY: CREATE TYPE widget (
internallength = 24,
- input = circle_in,
- output = circle_out,
+ input = widget_in,
+ output = widget_out,
alignment = double
);
QUERY: CREATE TYPE city_budget (
QUERY: DROP FUNCTION hobby_construct(text,text);
QUERY: DROP FUNCTION equipment(hobbies_r);
QUERY: DROP FUNCTION user_relns();
-QUERY: DROP FUNCTION circle_in(opaque);
-QUERY: DROP FUNCTION circle_out(opaque);
-QUERY: DROP FUNCTION pt_in_circle(point,circle);
+QUERY: DROP FUNCTION widget_in(opaque);
+QUERY: DROP FUNCTION widget_out(opaque);
+QUERY: DROP FUNCTION pt_in_widget(point,widget);
QUERY: DROP FUNCTION overpaid(emp);
QUERY: DROP FUNCTION boxarea(box);
QUERY: DROP FUNCTION interpt_pp(path,path);
QUERY: DROP FUNCTION reverse_c16(char16);
QUERY: DROP OPERATOR ## (path, path);
-QUERY: DROP OPERATOR <% (point, circle);
+QUERY: DROP OPERATOR <% (point, widget);
QUERY: DROP OPERATOR @#@ (none, int4);
QUERY: DROP OPERATOR #@# (int4, none);
QUERY: DROP OPERATOR #%# (int4, none);
QUERY: DROP TYPE city_budget;
-QUERY: DROP TYPE circle;
+QUERY: DROP TYPE widget;
QUERY: DROP AGGREGATE newavg;
QUERY: DROP AGGREGATE newsum;
QUERY: DROP AGGREGATE newcnt;
--
--
-CREATE FUNCTION circle_in(opaque)
- RETURNS circle
+CREATE FUNCTION widget_in(opaque)
+ RETURNS widget
AS '_OBJWD_/regress_DLSUFFIX_'
LANGUAGE 'c';
-CREATE FUNCTION circle_out(opaque)
+CREATE FUNCTION widget_out(opaque)
RETURNS opaque
AS '_OBJWD_/regress_DLSUFFIX_'
LANGUAGE 'c';
relkind <> ''i'' '
LANGUAGE 'sql';
-CREATE FUNCTION pt_in_circle(point, circle)
+CREATE FUNCTION pt_in_widget(point, widget)
RETURNS int4
AS '_OBJWD_/regress_DLSUFFIX_'
LANGUAGE 'c';
/*
- * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.5 1997/03/14 23:34:16 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.6 1997/04/22 17:33:00 scrappy Exp $
*/
#include /* faked on sunos */
{
int i;
char *output = (char *)PALLOC(2*(P_MAXDIG + 1)*poly->npts + 64);
- char *outptr = output;
- double *xp, *yp;
+ char buf[2*(P_MAXDIG)+20];
- sprintf(outptr, "(1, %*d", P_MAXDIG, poly->npts);
- xp = (double *) poly->pts;
- yp = (double *) (poly->pts + (poly->npts * sizeof(double *)));
+ sprintf(output, "(1, %*d", P_MAXDIG, poly->npts);
- for (i=
1; inpts; i++,xp++,yp++)
{
- sprintf(outptr, ",%*g,%*g", P_MAXDIG, *xp, P_MAXDIG, *yp);
- outptr += 2*(P_MAXDIG + 1);
+ sprintf(buf, ",%*g,%*g", P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
+ strcat(output, buf);
}
- *outptr++ = RDELIM;
- *outptr = '\0';
- return(path_in(outptr));
+ sprintf(buf, "%c", RDELIM);
+ strcat(output, buf);
+ return(path_in(output));
}
/* return the point where two paths intersect. Assumes that they do. */
return(salary > 699);
}
+/* New type "widget"
+ * This used to be "circle", but I added circle to builtins,
+ * so needed to make sure the names do not collide. - tgl 97/04/21
+ */
+
typedef struct {
Point center;
double radius;
-} CIRCLE;
+} WIDGET;
-extern CIRCLE *circle_in (char *str);
-extern char *circle_out (CIRCLE *circle);
-extern int pt_in_circle (Point *point, CIRCLE *circle);
+extern WIDGET *widget_in (char *str);
+extern char *widget_out (WIDGET *widget);
+extern int pt_in_widget (Point *point, WIDGET *widget);
#define NARGS 3
-CIRCLE *
-circle_in(str)
+WIDGET *
+widget_in(str)
char *str;
{
char *p, *coord[NARGS], buf2[1000];
int i;
- CIRCLE *result;
+ WIDGET *result;
if (str == NULL)
return(NULL);
coord[i++] = p + 1;
if (i < NARGS - 1)
return(NULL);
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = (WIDGET *) palloc(sizeof(WIDGET));
result->center.x = atof(coord[0]);
result->center.y = atof(coord[1]);
result->radius = atof(coord[2]);
- sprintf(buf2, "circle_in: read (%f, %f, %f)\n", result->center.x,
+ sprintf(buf2, "widget_in: read (%f, %f, %f)\n", result->center.x,
result->center.y,result->radius);
return(result);
}
char *
-circle_out(circle)
- CIRCLE *circle;
+widget_out(widget)
+ WIDGET *widget;
{
char *result;
- if (circle == NULL)
+ if (widget == NULL)
return(NULL);
result = (char *) palloc(60);
(void) sprintf(result, "(%g,%g,%g)",
- circle->center.x, circle->center.y, circle->radius);
+ widget->center.x, widget->center.y, widget->radius);
return(result);
}
int
-pt_in_circle(point, circle)
+pt_in_widget(point, widget)
Point *point;
- CIRCLE *circle;
+ WIDGET *widget;
{
extern double point_dt();
- return( point_dt(point, &circle->center) < circle->radius );
+ return( point_dt(point, &widget->center) < widget->radius );
}
#define ABS(X) ((X) > 0 ? (X) : -(X))
{
int width, height;
- width = ABS(box->xh - box->xl);
- height = ABS(box->yh - box->yl);
+ width = ABS(box->high.x - box->low.x);
+ height = ABS(box->high.y - box->low.y);
return (width * height);
}
CREATE OPERATOR <% (
leftarg = point,
- rightarg = circle,
- procedure = pt_in_circle,
+ rightarg = widget,
+ procedure = pt_in_widget,
commutator = >=%
);
--
--
-CREATE TYPE circle (
+CREATE TYPE widget (
internallength = 24,
- input = circle_in,
- output = circle_out,
+ input = widget_in,
+ output = widget_out,
alignment = double
);