2 * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.2 1996/11/11 16:33:12 scrappy Exp $
5 #include <float.h> /* faked on sunos */
10 #include "utils/geo-decls.h" /* includes <math.h> */
18 extern double *regress_dist_ptpath (Point *pt, PATH *path);
19 extern double *regress_path_dist (PATH *p1, PATH *p2);
20 extern PATH *poly2path (POLYGON *poly);
21 extern Point *interpt_pp (PATH *p1, PATH *p2);
22 extern void regress_lseg_construct (LSEG *lseg, Point *pt1, Point *pt2);
23 extern char overpaid (TUPLE tuple);
24 extern int boxarea (BOX *box);
25 extern char *reverse_c16 (char *string);
28 ** Distance from a point to a path
31 regress_dist_ptpath(pt, path)
42 result = PALLOCTYPE(double);
43 *result = Abs((double) DBL_MAX); /* +infinity */
46 result = point_distance(pt, &path->p[0]);
50 * the distance from a point to a path is the smallest distance
51 * from the point to any of its constituent segments.
53 Assert(path->npts > 1);
54 result = PALLOCTYPE(double);
55 for (i = 0; i < path->npts - 1; ++i) {
56 regress_lseg_construct(&lseg, &path->p[i], &path->p[i+1]);
57 tmp = dist_ps(pt, &lseg);
58 if (i == 0 || *tmp < *result)
68 /* this essentially does a cartesian product of the lsegs in the
69 two paths, and finds the min distance between any two lsegs */
71 regress_path_dist(p1, p2)
79 regress_lseg_construct(&seg1, &p1->p[0], &p1->p[1]);
80 regress_lseg_construct(&seg2, &p2->p[0], &p2->p[1]);
81 min = lseg_distance(&seg1, &seg2);
83 for (i = 0; i < p1->npts - 1; i++)
84 for (j = 0; j < p2->npts - 1; j++)
86 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i+1]);
87 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j+1]);
89 if (*min < *(tmp = lseg_distance(&seg1, &seg2)))
102 char *output = (char *)PALLOC(2*(P_MAXDIG + 1)*poly->npts + 64);
103 char *outptr = output;
106 sprintf(outptr, "(1, %*d", P_MAXDIG, poly->npts);
107 xp = (double *) poly->pts;
108 yp = (double *) (poly->pts + (poly->npts * sizeof(double *)));
110 for (i=1; i<poly->npts; i++,xp++,yp++)
112 sprintf(outptr, ",%*g,%*g", P_MAXDIG, *xp, P_MAXDIG, *yp);
113 outptr += 2*(P_MAXDIG + 1);
118 return(path_in(outptr));
121 /* return the point where two paths intersect. Assumes that they do. */
133 for (i = 0; i < p1->npts - 1; i++)
134 for (j = 0; j < p2->npts - 1; j++)
136 regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i+1]);
137 regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j+1]);
138 if (lseg_intersect(&seg1, &seg2))
140 ln = line_construct_pp(&seg2.p[0], &seg2.p[1]);
141 retval = interpt_sl(&seg1, ln);
151 /* like lseg_construct, but assume space already allocated */
153 regress_lseg_construct(lseg, pt1, pt2)
158 lseg->p[0].x = pt1->x;
159 lseg->p[0].y = pt1->y;
160 lseg->p[1].x = pt2->x;
161 lseg->p[1].y = pt2->y;
162 lseg->m = point_sl(pt1, pt2);
172 salary = (long)GetAttributeByName(tuple, "salary", &isnull);
173 return(salary > 699);
181 extern CIRCLE *circle_in (char *str);
182 extern char *circle_out (CIRCLE *circle);
183 extern int pt_in_circle (Point *point, CIRCLE *circle);
191 char *p, *coord[NARGS], buf2[1000];
197 for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
198 if (*p == ',' || (*p == LDELIM && !i))
202 result = (CIRCLE *) palloc(sizeof(CIRCLE));
203 result->center.x = atof(coord[0]);
204 result->center.y = atof(coord[1]);
205 result->radius = atof(coord[2]);
207 sprintf(buf2, "circle_in: read (%f, %f, %f)\n", result->center.x,
208 result->center.y,result->radius);
221 result = (char *) palloc(60);
222 (void) sprintf(result, "(%g,%g,%g)",
223 circle->center.x, circle->center.y, circle->radius);
228 pt_in_circle(point, circle)
232 extern double point_dt();
234 return( point_dt(point, &circle->center) < circle->radius );
237 #define ABS(X) ((X) > 0 ? (X) : -(X))
247 width = ABS(box->xh - box->xl);
248 height = ABS(box->yh - box->yl);
249 return (width * height);
260 if (!(new_string = palloc(16))) {
261 fprintf(stderr, "reverse_c16: palloc failed\n");
264 memset(new_string, 0, 16);
265 for (i = 0; i < 16 && string[i]; ++i)
267 if (i == 16 || !string[i])
271 new_string[len-i] = string[i];