/* * ---------------------------------------------------------------- * FILE * polyfuncs.c * * DESCRIPTION * simple functions to support polygon data queries for the Sequoia * benchmark. * * IDENTIFICATION * * $Header: /home/merlin/dave/Sequoia/benchmiro/RCS/polyfuncs.c,v 1.10 1993/10/07 23:24:03 mer Exp $ * * HISTORY * before (lots of folks) lots of good work 7/27/93 (elein) get rid of * internal include files, redefined large object stuff. Sept 9 (mer) * does a quick port to miro version 1.0 runs the file through indent. * * ---------------------------------------------------------------- */ /* * ---------------- include files ---------------- */ #include "monadt.h" #include "spatial_types.h" #include double * size(p) Poly *p; { double *result; result = (double *) mi_alloc(sizeof(double)); *result = (p->bbox.up_right.x - p->bbox.low_left.x) * (p->bbox.up_right.y - p->bbox.low_left.y); return (result); } Box * make_box(pt, radius) Pnt *pt; double *radius; { Box *b = (Box *) mi_alloc(sizeof(Box)); b->low_left.x = pt->x - *radius; b->low_left.y = pt->y - *radius; b->up_right.x = pt->x + *radius; b->up_right.y = pt->y + *radius; return b; } Poly * box_make_poly(box) Box *box; { Poly *p; Pnt *pts; p = (Poly *) mi_alloc(varAlloc(POLYSIZE(5))); /* * XXX This is a workaround to an executor bug in 2.0.5. The executor's * releasing memory allocated by functions invoked that return values * used as keys in joins. We force the memory to be preserved until * the end of the command here, but this code should come out when * hong gets back from vacation. * */ mi_set_mem_duration((char *) p, PER_COMMAND); p->vl_len = varAlloc(POLYSIZE(5)); p->npts = 5; p->bbox = *box; p->flags = p->spare = p->spare2 = 0; pts = (Pnt *) &p->val.mr_data; pts[0].x = box->up_right.x; pts[1].x = box->up_right.x; pts[2].x = box->low_left.x; pts[3].x = box->low_left.x; pts[4].x = box->up_right.x; pts[0].y = box->low_left.y; pts[1].y = box->up_right.y; pts[2].y = box->up_right.y; pts[3].y = box->low_left.y; pts[4].y = box->low_left.y; return p; } Poly * pt_make_poly(pt) Pnt *pt; { Poly *p; Pnt *pts; p = (Poly *) mi_alloc(varAlloc(POLYSIZE(2))); /* * XXX This is a workaround to an executor bug in 2.0.5. The executor's * releasing memory allocated by functions invoked that return values * used as keys in joins. We force the memory to be preserved until * the end of the command here, but this code should come out when * hong gets back from vacation. * */ mi_set_mem_duration((char *) p, PER_COMMAND); p->vl_len = varAlloc(POLYSIZE(2)); p->npts = 2; p->flags = p->spare = p->spare2 = 0; p->bbox.up_right.x = p->bbox.low_left.x = pt->x; p->bbox.up_right.y = p->bbox.low_left.y = pt->y; pts = (Pnt *) &p->val.mr_data; pts[0].x = pts[1].x = pt->x; pts[0].y = pts[1].y = pt->y; return p; }