mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Major patch from Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
OK, here are a passel of patches for the geometric data types. These add a "circle" data type, new operators and functions for the existing data types, and change the default formats for some of the existing types to make them consistant with each other. Current formatting conventions (e.g. compatible with v6.0 to allow dump/reload) are supported, but the new conventions should be an improvement and we can eventually drop the old conventions entirely. For example, there are two kinds of paths (connected line segments), open and closed, and the old format was '(1,2,1,2,3,4)' for a closed path with two points (1,2) and (3,4) '(0,2,1,2,3,4)' for an open path with two points (1,2) and (3,4) Pretty arcane, huh? The new format for paths is '((1,2),(3,4))' for a closed path with two points (1,2) and (3,4) '[(1,2),(3,4)]' for an open path with two points (1,2) and (3,4) For polygons, the old convention is '(0,4,2,0,4,3)' for a triangle with points at (0,0),(4,4), and (2,3) and the new convention is '((0,0),(4,4),(2,3))' for a triangle with points at (0,0),(4,4), and (2,3) Other data types which are also represented as lists of points (e.g. boxes, line segments, and polygons) have similar representations (they surround each point with parens). For v6.1, any format which can be interpreted as the old style format is decoded as such; we can remove that backwards compatibility but ugly convention for v7.0. This will allow dump/reloads from v6.0. These include some updates to the regression test files to change the test for creating a data type from "circle" to "widget" to keep the test from trashing the new builtin circle type.
This commit is contained in:
@ -6,8 +6,8 @@ QUERY: CREATE OPERATOR ## (
|
||||
);
|
||||
QUERY: CREATE OPERATOR <% (
|
||||
leftarg = point,
|
||||
rightarg = circle,
|
||||
procedure = pt_in_circle,
|
||||
rightarg = widget,
|
||||
procedure = pt_in_widget,
|
||||
commutator = >=%
|
||||
);
|
||||
QUERY: CREATE OPERATOR @#@ (
|
||||
|
@ -1,7 +1,7 @@
|
||||
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 (
|
||||
|
@ -3357,20 +3357,20 @@ QUERY: DROP FUNCTION hobbies(person);
|
||||
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;
|
||||
|
@ -3,12 +3,12 @@
|
||||
--
|
||||
--
|
||||
|
||||
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';
|
||||
@ -42,7 +42,7 @@ CREATE FUNCTION user_relns()
|
||||
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';
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $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 <float.h> /* faked on sunos */
|
||||
@ -103,22 +103,19 @@ poly2path(poly)
|
||||
{
|
||||
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; i<poly->npts; i++,xp++,yp++)
|
||||
for (i=0; i<poly->npts; i++)
|
||||
{
|
||||
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. */
|
||||
@ -176,24 +173,29 @@ char overpaid(tuple)
|
||||
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);
|
||||
@ -202,39 +204,39 @@ char *str;
|
||||
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))
|
||||
@ -247,8 +249,8 @@ BOX *box;
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ CREATE OPERATOR ## (
|
||||
|
||||
CREATE OPERATOR <% (
|
||||
leftarg = point,
|
||||
rightarg = circle,
|
||||
procedure = pt_in_circle,
|
||||
rightarg = widget,
|
||||
procedure = pt_in_widget,
|
||||
commutator = >=%
|
||||
);
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
--
|
||||
--
|
||||
|
||||
CREATE TYPE circle (
|
||||
CREATE TYPE widget (
|
||||
internallength = 24,
|
||||
input = circle_in,
|
||||
output = circle_out,
|
||||
input = widget_in,
|
||||
output = widget_out,
|
||||
alignment = double
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user