2 * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.12 1997/09/08 20:59:27 momjian Exp $
5 #include <float.h> /* faked on sunos */
7 #include <string.h> /* for memset() */
11 #include "utils/geo_decls.h" /* includes <math.h> */
12 #include "executor/executor.h" /* For GetAttributeByName */
21 extern double *regress_dist_ptpath(Point * pt, PATH * path);
22 extern double *regress_path_dist(PATH * p1, PATH * p2);
23 extern PATH *poly2path(POLYGON * poly);
24 extern Point *interpt_pp(PATH * p1, PATH * p2);
25 extern void regress_lseg_construct(LSEG * lseg, Point * pt1, Point * pt2);
26 extern char overpaid(TUPLE tuple);
27 extern int boxarea(BOX *box);
28 extern char *reverse_c16(char *string);
31 ** Distance from a point to a path
34 regress_dist_ptpath(pt, path)
46 result = PALLOCTYPE(double);
47 *result = Abs((double) DBL_MAX); /* +infinity */
50 result = point_distance(pt, &path->p[0]);
55 * the distance from a point to a path is the smallest
56 * distance from the point to any of its constituent segments.
58 Assert(path->npts > 1);
59 result = PALLOCTYPE(double);
60 for (i = 0; i < path->npts - 1; ++i)
62 regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]);
63 tmp = dist_ps(pt, &lseg);
64 if (i == 0 || *tmp < *result)
74 /* this essentially does a cartesian product of the lsegs in the
75 two paths, and finds the min distance between any two lsegs */
77 regress_path_dist(p1, p2)
88 regress_lseg_construct(&seg1, &p1->p[0], &p1->p[1]);
89 regress_lseg_construct(&seg2, &p2->p[0], &p2->p[1]);
90 min = lseg_distance(&seg1, &seg2);
92 for (i = 0; i < p1->npts - 1; i++)
93 for (j = 0; j < p2->npts - 1; j++)
95 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
96 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
98 if (*min < *(tmp = lseg_distance(&seg1, &seg2)))
111 char *output = (char *) PALLOC(2 * (P_MAXDIG + 1) * poly->npts + 64);
112 char buf[2 * (P_MAXDIG) + 20];
114 sprintf(output, "(1, %*d", P_MAXDIG, poly->npts);
116 for (i = 0; i < poly->npts; i++)
118 sprintf(buf, ",%*g,%*g", P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
122 sprintf(buf, "%c", RDELIM);
124 return (path_in(output));
127 /* return the point where two paths intersect. Assumes that they do. */
144 bool found; /* We've found the intersection */
146 found = false; /* Haven't found it yet */
148 for (i = 0; i < p1->npts - 1 && !found; i++)
149 for (j = 0; j < p2->npts - 1 && !found; j++)
151 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
152 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
153 if (lseg_intersect(&seg1, &seg2))
158 ln = line_construct_pp(&seg2.p[0], &seg2.p[1]);
159 retval = interpt_sl(&seg1, ln);
161 retval = lseg_interpt(&seg1, &seg2);
167 /* like lseg_construct, but assume space already allocated */
169 regress_lseg_construct(lseg, pt1, pt2)
174 lseg->p[0].x = pt1->x;
175 lseg->p[0].y = pt1->y;
176 lseg->p[1].x = pt2->x;
177 lseg->p[1].y = pt2->y;
178 lseg->m = point_sl(pt1, pt2);
189 salary = (long) GetAttributeByName(tuple, "salary", &isnull);
190 return (salary > 699);
194 * This used to be "circle", but I added circle to builtins,
195 * so needed to make sure the names do not collide. - tgl 97/04/21
204 WIDGET *widget_in(char *str);
205 char *widget_out(WIDGET * widget);
206 int pt_in_widget(Point * point, WIDGET * widget);
222 for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
223 if (*p == ',' || (*p == LDELIM && !i))
227 result = (WIDGET *) palloc(sizeof(WIDGET));
228 result->center.x = atof(coord[0]);
229 result->center.y = atof(coord[1]);
230 result->radius = atof(coord[2]);
232 sprintf(buf2, "widget_in: read (%f, %f, %f)\n", result->center.x,
233 result->center.y, result->radius);
246 result = (char *) palloc(60);
247 sprintf(result, "(%g,%g,%g)",
248 widget->center.x, widget->center.y, widget->radius);
253 pt_in_widget(point, widget)
257 extern double point_dt();
259 return (point_dt(point, &widget->center) < widget->radius);
262 #define ABS(X) ((X) > 0 ? (X) : -(X))
273 width = ABS(box->high.x - box->low.x);
274 height = ABS(box->high.y - box->low.y);
275 return (width * height);
286 if (!(new_string = palloc(16)))
288 fprintf(stderr, "reverse_c16: palloc failed\n");
291 memset(new_string, 0, 16);
292 for (i = 0; i < 16 && string[i]; ++i)
294 if (i == 16 || !string[i])
298 new_string[len - i] = string[i];