long pointdist(Point *p1, Point *p2) { long result; result = point_dt(p1, p2); return(result); }
Datum pt_in_widget(PG_FUNCTION_ARGS) { Point *point = PG_GETARG_POINT_P(0); WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius); }
double path_ln(PATH *path) { double result; int ct, i; ct = path->npts - 1; for (result = i = 0; i < ct; ++i) result += point_dt(&path->p[i], &path->p[i+1]); return(result); }
double *path_length(PATH *path) { double *result; int ct, i; result = PALLOCTYPE(double); ct = path->npts - 1; for (i = 0; i < ct; ++i) *result += point_dt(&path->p[i], &path->p[i+1]); return(result); }
Datum regress_dist_ptpath(PG_FUNCTION_ARGS) { Point *pt = PG_GETARG_POINT_P(0); PATH *path = PG_GETARG_PATH_P(1); float8 result = 0.0; /* keep compiler quiet */ float8 tmp; int i; LSEG lseg; switch (path->npts) { case 0: PG_RETURN_NULL(); case 1: result = point_dt(pt, &path->p[0]); break; default: /* * the distance from a point to a path is the smallest distance * from the point to any of its constituent segments. */ Assert(path->npts > 1); for (i = 0; i < path->npts - 1; ++i) { regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]); tmp = DatumGetFloat8(DirectFunctionCall2(dist_ps, PointPGetDatum(pt), LsegPGetDatum(&lseg))); if (i == 0 || tmp < result) result = tmp; } break; } PG_RETURN_FLOAT8(result); }