*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.35 1997/09/04 18:43:21 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.36 1997/09/05 18:11:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#define isleap(y) (((y % 4) == 0) && (((y % 100) != 0) || ((y % 400) == 0)))
-int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
+int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL}
char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday", NULL};
+ "Thursday", "Friday", "Saturday", NULL}
/* TMODULO()
* Macro to replace modf(), which is broken on some platforms.
default:
elog(WARN,"Internal coding error, can't input datetime '%s'",str);
- };
+ }
return(result);
} /* datetime_in() */
} else {
EncodeSpecialDateTime(DT_INVALID, buf);
- };
+ }
result = PALLOC(strlen(buf)+1);
TIMESPAN_INVALID(span);
#endif
elog(WARN,"Bad timespan external representation %s",str);
- };
+ }
break;
default:
elog(WARN,"Internal coding error, can't input timespan '%s'",str);
- };
+ }
return(span);
} /* timespan_in() */
#ifdef DATEDEBUG
printf( "SetDateTime- epoch time is %f\n", dt);
#endif
- };
+ }
return(dt);
} /* SetDateTime() */
} else {
if (DATETIME_IS_RELATIVE(dt1)) dt1 = SetDateTime(dt1);
if (DATETIME_IS_RELATIVE(dt2)) dt2 = SetDateTime(dt2);
- };
+ }
return( ((dt1 < dt2)? -1: ((dt1 > dt2)? 1: 0)));
} /* datetime_cmp() */
} else if (TIMESPAN_IS_INVALID(*timespan2)) {
return( -1);
- };
+ }
span1 = timespan1->time;
if (timespan1->month != 0) span1 += (timespan1->month * (30.0*86400));
*result = dt1;
} else {
*result = ((dt2 < dt1)? dt2: dt1);
- };
+ }
return(result);
} /* datetime_smaller() */
*result = dt1;
} else {
*result = ((dt2 > dt1)? dt2: dt1);
- };
+ }
return(result);
} /* datetime_larger() */
} else {
result->time = JROUND(dt1 - dt2);
- };
+ }
result->month = 0;
return(result);
} else if (tm->tm_mon < 1) {
tm->tm_year += ((tm->tm_mon / 12) - 1);
tm->tm_mon = ((tm->tm_mon % 12) + 12);
- };
+ }
/* adjust for end of month boundary problems... */
if (tm->tm_mday > mdays[ tm->tm_mon-1]) {
tm->tm_mday = (mdays[ tm->tm_mon-1]+1);
} else {
tm->tm_mday = mdays[ tm->tm_mon-1];
- };
- };
+ }
+ }
#ifdef DATEDEBUG
printf( "datetime_pl_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n",
} else {
DATETIME_INVALID(dt);
- };
- };
+ }
+ }
*result = dt;
- };
+ }
return(result);
} /* datetime_pl_span() */
} else {
result->time = timespan1->time;
result->month = timespan1->month;
- };
- };
+ }
+ }
return(result);
} /* timespan_smaller() */
} else {
result->time = timespan1->time;
result->month = timespan1->month;
- };
- };
+ }
+ }
return(result);
} /* timespan_larger() */
tm->tm_mday = -tm->tm_mday;
tm->tm_mon = -tm->tm_mon;
tm->tm_year = -tm->tm_year;
- };
+ }
if (tm->tm_sec < 0) {
tm->tm_sec += 60;
tm->tm_min--;
- };
+ }
if (tm->tm_min < 0) {
tm->tm_min += 60;
tm->tm_hour--;
- };
+ }
if (tm->tm_hour < 0) {
tm->tm_hour += 24;
tm->tm_mday--;
- };
+ }
if (tm->tm_mday < 0) {
if (dt1 < dt2) {
tm->tm_mday += mdays[tm2->tm_mon-1];
if (isleap(tm2->tm_year) && (tm2->tm_mon == 2)) tm->tm_mday++;
tm->tm_mon--;
- };
- };
+ }
+ }
if (tm->tm_mon < 0) {
tm->tm_mon += 12;
tm->tm_year--;
- };
+ }
/* recover sign if necessary... */
if (dt1 < dt2) {
tm->tm_mday = -tm->tm_mday;
tm->tm_mon = -tm->tm_mon;
tm->tm_year = -tm->tm_year;
- };
+ }
if (tm2timespan(tm, fsec, result) != 0) {
elog(WARN,"Unable to decode datetime",NULL);
- };
+ }
#if FALSE
result->time = (fsec2 - fsec1);
} else {
elog(WARN,"Unable to decode datetime",NULL);
- };
+ }
return(result);
} /* datetime_age() */
#if FALSE
if (type == IGNORE) {
type = DecodeSpecial( 0, lowunits, &val);
- };
+ }
#endif
#ifdef DATEDEBUG
default:
elog(WARN,"Datetime units %s not supported",lowunits);
result = NULL;
- };
+ }
if (IS_VALID_UTIME( tm->tm_year, tm->tm_mon, tm->tm_mday)) {
#ifdef USE_POSIX_TIME
} else {
tm->tm_isdst = 0;
tz = 0;
- };
+ }
if (tm2datetime( tm, fsec, &tz, result) != 0)
elog(WARN,"Unable to truncate datetime to %s",lowunits);
} else {
elog(WARN,"Datetime units %s not recognized",lowunits);
result = NULL;
- };
- };
+ }
+ }
return(result);
} /* datetime_trunc() */
#if FALSE
if (type == IGNORE) {
type = DecodeSpecial( 0, lowunits, &val);
- };
+ }
#endif
#ifdef DATEDEBUG
default:
elog(WARN,"Timespan units %s not supported",lowunits);
result = NULL;
- };
+ }
if (tm2timespan(tm, fsec, result) != 0)
elog(WARN,"Unable to truncate timespan to %s",lowunits);
} else {
elog(NOTICE,"Timespan out of range",NULL);
result = NULL;
- };
+ }
#if FALSE
} else if ((type == RESERV) && (val == DTK_EPOCH)) {
if (timespan->month != 0) {
*result += ((365.25*86400)*(timespan->month / 12));
*result += ((30*86400)*(timespan->month % 12));
- };
+ }
#endif
} else {
elog(WARN,"Timespan units %s not recognized",units);
result = NULL;
- };
+ }
return(result);
} /* timespan_trunc() */
type = DecodeUnits( 0, lowunits, &val);
if (type == IGNORE) {
type = DecodeSpecial( 0, lowunits, &val);
- };
+ }
#ifdef DATEDEBUG
if (type == IGNORE) strcpy(lowunits, "(unknown)");
default:
elog(WARN,"Datetime units %s not supported",lowunits);
*result = 0;
- };
+ }
} else if (type == RESERV) {
switch (val) {
default:
elog(WARN,"Datetime units %s not supported",lowunits);
*result = 0;
- };
+ }
} else {
elog(WARN,"Datetime units %s not recognized",lowunits);
*result = 0;
- };
- };
+ }
+ }
return(result);
} /* datetime_part() */
type = DecodeUnits( 0, lowunits, &val);
if (type == IGNORE) {
type = DecodeSpecial( 0, lowunits, &val);
- };
+ }
#ifdef DATEDEBUG
if (type == IGNORE) strcpy(lowunits, "(unknown)");
default:
elog(WARN,"Timespan units %s not yet supported",units);
result = NULL;
- };
+ }
} else {
elog(NOTICE,"Timespan out of range",NULL);
*result = 0;
- };
+ }
} else if ((type == RESERV) && (val == DTK_EPOCH)) {
*result = timespan->time;
if (timespan->month != 0) {
*result += ((365.25*86400)*(timespan->month / 12));
*result += ((30*86400)*(timespan->month % 12));
- };
+ }
} else {
elog(WARN,"Timespan units %s not recognized",units);
*result = 0;
- };
+ }
return(result);
} /* timespan_part() */
} else {
elog(WARN,"Time zone %s not recognized",lowzone);
result = NULL;
- };
+ }
return(result);
} /* datetime_zone() */
{ "zp6", TZ, NEG(36)}, /* GMT +6 hours. */
{ "z", RESERV, DTK_ZULU}, /* 00:00:00 */
{ ZULU, RESERV, DTK_ZULU}, /* 00:00:00 */
-};
+}
static unsigned int szdatetktbl = sizeof datetktbl / sizeof datetktbl[0];
{ "years", UNITS, DTK_YEAR}, /* "years" relative time units */
{ "yr", UNITS, DTK_YEAR}, /* "year" relative time units */
{ "yrs", UNITS, DTK_YEAR}, /* "years" relative time units */
-};
+}
static unsigned int szdeltatktbl = sizeof deltatktbl / sizeof deltatktbl[0];
#if USE_DATE_CACHE
-datetkn *datecache[MAXDATEFIELDS] = {NULL};
+datetkn *datecache[MAXDATEFIELDS] = {NULL}
-datetkn *deltacache[MAXDATEFIELDS] = {NULL};
+datetkn *deltacache[MAXDATEFIELDS] = {NULL}
#endif
if (time < 0) {
time += 86400;
date -= 1;
- };
+ }
/* Julian day routine does not work for negative Julian days */
if (date < -date0)
*tzp = 0;
tm->tm_isdst = 0;
if (tzn != NULL) *tzn = NULL;
- };
+ }
dt = dt2local( dt, *tzp);
} else {
tm->tm_isdst = 0;
if (tzn != NULL) *tzn = NULL;
- };
+ }
#ifdef DATEDEBUG
printf( "datetime2tm- date is %d.%02d.%02d\n", tm->tm_year, tm->tm_mon, tm->tm_mday);
} else {
tm->tm_year = 0;
tm->tm_mon = 0;
- };
+ }
#ifdef ROUND_ALL
time = JROUND(span.time);
/* otherwise, number only and will determine year, month, or day later */
} else {
ftype[nf] = DTK_NUMBER;
- };
+ }
/* text? then date string, month, day of week, special, or timezone */
} else if (isalpha(*cp)) {
ftype[nf] = DTK_DATE;
while (isdigit(*cp) || (*cp == '-') || (*cp == '/') || (*cp == '.'))
*lp++ = tolower(*cp++);
- };
+ }
/* skip leading spaces */
} else if (isspace(*cp)) {
/* otherwise something wrong... */
} else {
return -1;
- };
+ }
/* ignore punctuation but use as delimiter */
} else if (ispunct(*cp)) {
} else {
return -1;
- };
+ }
/* force in a delimiter */
*lp++ = '\0';
nf++;
if (nf > MAXDATEFIELDS) {
return -1;
- };
+ }
#ifdef DATEDEBUG
printf( "ParseDateTime- set field[%d] to %s type %d\n", (nf-1), field[nf-1], ftype[nf-1]);
#endif
- };
+ }
*numfields = nf;
} else {
if (DecodeNumber( flen, field[i], fmask, &tmask, tm, fsec) != 0)
return -1;
- };
+ }
break;
case DTK_STRING:
default:
*dtype = val;
- };
+ }
break;
default:
return -1;
- };
+ }
break;
default:
return -1;
- };
+ }
#ifdef DATEDEBUG
printf( "DecodeDateTime- field[%d] %s (%08x/%08x) value is %d\n",
if (tmask & fmask) return -1;
fmask |= tmask;
- };
+ }
/* there is no year zero in AD/BC notation; i.e. "1 BC" == year 0 */
if (bc) tm->tm_year = -(tm->tm_year-1);
} else {
tm->tm_isdst = 0;
*tzp = 0;
- };
- };
+ }
+ }
return 0;
} /* DecodeDateTime() */
default:
return -1;
- };
+ }
break;
default:
return -1;
- };
+ }
break;
default:
return -1;
- };
+ }
if (tmask & fmask) return -1;
fmask |= tmask;
#ifdef DATEDEBUG
printf( "DecodeTimeOnly- field[%d] %s value is %d\n", i, field[i], val);
#endif
- };
+ }
#ifdef DATEDEBUG
printf( "DecodeTimeOnly- mask %08x (%08x)", fmask, DTK_TIME_M);
while (isdigit(*str)) str++;
} else if (isalpha(*str)) {
while (isalpha(*str)) str++;
- };
+ }
if (*str != '\0') *str++ = '\0';
nf++;
- };
+ }
/* don't allow too many fields */
if (nf > 3) return -1;
printf( "DecodeDate- illegal field %s value is %d\n", field[i], val);
#endif
return -1;
- };
+ }
if (fmask & dmask) return -1;
fmask |= dmask;
/* mark this field as being completed */
field[i] = NULL;
- };
- };
+ }
+ }
/* now pick up remaining numeric fields */
for (i = 0; i < nf; i++) {
fmask |= dmask;
*tmask |= dmask;
- };
+ }
return 0;
} /* DecodeDate() */
if (cp == str) return -1;
} else {
return -1;
- };
- };
+ }
+ }
/* do a sanity check */
if ((tm->tm_hour < 0)
if (*cp == '.') {
*fsec = strtod( cp, &cp);
if (*cp != '\0') return -1;
- };
+ }
#ifdef DATEDEBUG
printf( "DecodeNumber- %s is %d fmask=%08x tmask=%08x\n", str, val, fmask, *tmask);
#endif
tm->tm_mday = tm->tm_year;
*tmask = DTK_M(DAY);
- };
- };
+ }
+ }
tm->tm_year = val;
tm->tm_year += 2000;
} else if (tm->tm_year < 100) {
tm->tm_year += 1900;
- };
+ }
} else {
return -1;
- };
+ }
return 0;
} /* DecodeNumber() */
tm->tm_mon = atoi(str+2);
*(str+2) = '\0';
tm->tm_year = atoi(str+0);
- };
+ }
} else if (strchr(str,'.') != NULL) {
#ifdef DATEDEBUG
if (cp == (str+4)) return -1;
if (*cp == '.') {
*fsec = strtod( cp, NULL);
- };
+ }
*(str+4) = '\0';
tm->tm_min = strtod( (str+2), &cp);
*(str+2) = '\0';
} else {
return -1;
- };
+ }
return 0;
} /* DecodeNumberField() */
} else {
min = 0;
- };
+ }
tz = (hr*60+min)*60;
if (*str == '-') tz = -tz;
#endif
tp = datebsearch(lowtoken, datetktbl, szdatetktbl);
#if USE_DATE_CACHE
- };
+ }
datecache[field] = tp;
#endif
if (tp == NULL) {
default:
*val = tp->value;
break;
- };
- };
+ }
+ }
return(type);
} /* DecodeSpecial() */
} else {
break;
- };
- };
+ }
+ }
/* read through remaining list backwards to pick up units before values */
for (i = nf-1; i >= ii; i--) {
if (*cp == '.') {
*fsec = strtod( cp, NULL);
if (val < 0) *fsec = - (*fsec);
- };
+ }
flen = strlen(field[i]);
tmask = 0; /* DTK_M(type); */
default:
return -1;
- };
+ }
break;
case DTK_STRING:
default:
return -1;
- };
+ }
break;
default:
return -1;
- };
+ }
#ifdef DATEDEBUG
printf( "DecodeDateDelta- (%08x/%08x) field[%d] %s value is %d\n",
if (tmask & fmask) return -1;
fmask |= tmask;
- };
+ }
if (*fsec != 0) {
TMODULO(*fsec,sec,1);
tm->tm_sec += sec;
- };
+ }
if (is_before) {
*fsec = -(*fsec);
tm->tm_mday = -(tm->tm_mday);
tm->tm_mon = -(tm->tm_mon);
tm->tm_year = -(tm->tm_year);
- };
+ }
#ifdef DATEDEBUG
printf( "DecodeDateDelta- mask %08x (%08x)", fmask, DTK_DATE_M);
#endif
tp = datebsearch(lowtoken, deltatktbl, szdeltatktbl);
#if USE_DATE_CACHE
- };
+ }
deltacache[field] = tp;
#endif
if (tp == NULL) {
*val = FROMVAL(tp);
} else {
*val = tp->value;
- };
- };
+ }
+ }
return(type);
} /* DecodeUnits() */
printf( "EncodeSpecialDateTime- unrecognized date\n");
#endif
strcpy( str, INVALID);
- };
+ }
return(TRUE);
- };
+ }
return(FALSE);
} /* EncodeSpecialDateTime() */
} else {
sprintf( str, "%04d-%02d-%02d %s",
-(tm->tm_year-1), tm->tm_mon, tm->tm_mday, "BC");
- };
+ }
/* compatible with Oracle/Ingres date formats */
} else if (style == USE_SQL_DATES) {
sprintf( str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
} else {
sprintf( str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
- };
+ }
if (tm->tm_year > 0) {
sprintf( (str+5), "/%04d", tm->tm_year);
} else {
sprintf( (str+5), "/%04d %s", -(tm->tm_year-1), "BC");
- };
+ }
/* backward-compatible with traditional Postgres abstime dates */
} else { /* if (style == USE_POSTGRES_DATES) */
sprintf( (str+4), "%02d %3s", tm->tm_mday, months[tm->tm_mon-1]);
} else {
sprintf( (str+4), "%3s %02d", months[tm->tm_mon-1], tm->tm_mday);
- };
+ }
if (tm->tm_year > 0) {
sprintf( (str+10), " %04d", tm->tm_year);
} else {
sprintf( (str+10), " %04d %s", -(tm->tm_year-1), "BC");
- };
+ }
#endif
/* traditional date-only style for Postgres */
sprintf( str, "%02d-%02d", tm->tm_mday, tm->tm_mon);
} else {
sprintf( str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
- };
+ }
if (tm->tm_year > 0) {
sprintf( (str+5), "-%04d", tm->tm_year);
} else {
sprintf( (str+5), "-%04d %s", -(tm->tm_year-1), "BC");
- };
- };
+ }
+ }
#ifdef DATEDEBUG
printf( "EncodeDateOnly- date result is %s\n", str);
} else {
hour = 0;
min = 0;
- };
+ }
sprintf( (str+strlen(str)), ((min != 0)? "%+03d:%02d": "%+03d"), hour, min);
- };
+ }
} else {
if (tm->tm_hour || tm->tm_min) {
} else {
sprintf( str, "%04d-%02d-%02d %s",
-(tm->tm_year-1), tm->tm_mon, tm->tm_mday, "BC");
- };
- };
+ }
+ }
/* compatible with Oracle/Ingres date formats */
} else if (style == USE_SQL_DATES) {
sprintf( str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
} else {
sprintf( str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
- };
+ }
if (tm->tm_year > 0) {
sprintf( (str+5), "/%04d %02d:%02d:%05.2f",
tm->tm_year, tm->tm_hour, tm->tm_min, sec);
if ((*tzn != NULL) && (tm->tm_isdst >= 0)) {
strcpy( (str+22), " ");
strcpy( (str+23), *tzn);
- };
+ }
} else {
sprintf( (str+5), "/%04d %02d:%02d %s",
-(tm->tm_year-1), tm->tm_hour, tm->tm_min, "BC");
- };
+ }
/* backward-compatible with traditional Postgres abstime dates */
} else { /* if (style == USE_POSTGRES_DATES) */
sprintf( (str+4), "%02d %3s", tm->tm_mday, months[tm->tm_mon-1]);
} else {
sprintf( (str+4), "%3s %02d", months[tm->tm_mon-1], tm->tm_mday);
- };
+ }
if (tm->tm_year > 0) {
sprintf( (str+10), " %02d:%02d", tm->tm_hour, tm->tm_min);
if (fsec != 0) {
if ((*tzn != NULL) && (tm->tm_isdst >= 0)) {
strcpy( (str+27), " ");
strcpy( (str+28), *tzn);
- };
+ }
} else {
sprintf( (str+16), ":%02.0f %04d", sec, tm->tm_year);
if ((*tzn != NULL) && (tm->tm_isdst >= 0)) {
strcpy( (str+24), " ");
strcpy( (str+25), *tzn);
- };
- };
+ }
+ }
} else {
sprintf( (str+10), " %02d:%02d %04d %s",
tm->tm_hour, tm->tm_min, -(tm->tm_year-1), "BC");
- };
- };
+ }
+ }
#ifdef DATEDEBUG
printf( "EncodeDateTime- date result is %s\n", str);
is_before |= (tm->tm_year < 0);
sprintf( cp, " %d year%s", abs(tm->tm_year), ((abs(tm->tm_year) != 1)? "s": ""));
cp += strlen(cp);
- };
+ }
if (tm->tm_mon != 0) {
is_nonzero = TRUE;
is_before |= (tm->tm_mon < 0);
sprintf( cp, " %d mon%s", abs(tm->tm_mon), ((abs(tm->tm_mon) != 1)? "s": ""));
cp += strlen(cp);
- };
+ }
if (tm->tm_mday != 0) {
is_nonzero = TRUE;
is_before |= (tm->tm_mday < 0);
sprintf( cp, " %d day%s", abs(tm->tm_mday), ((abs(tm->tm_mday) != 1)? "s": ""));
cp += strlen(cp);
- };
+ }
if (tm->tm_hour != 0) {
is_nonzero = TRUE;
is_before |= (tm->tm_hour < 0);
sprintf( cp, " %d hour%s", abs(tm->tm_hour), ((abs(tm->tm_hour) != 1)? "s": ""));
cp += strlen(cp);
- };
+ }
if (tm->tm_min != 0) {
is_nonzero = TRUE;
is_before |= (tm->tm_min < 0);
sprintf( cp, " %d min%s", abs(tm->tm_min), ((abs(tm->tm_min) != 1)? "s": ""));
cp += strlen(cp);
- };
+ }
/* fractional seconds? */
if (fsec != 0) {
is_before |= (tm->tm_sec < 0);
sprintf( cp, " %d sec%s", abs(tm->tm_sec), ((abs(tm->tm_sec) != 1)? "s": ""));
cp += strlen(cp);
- };
+ }
/* identically zero? then put in a unitless zero... */
if (! is_nonzero) {
strcat( cp, " 0");
cp += strlen(cp);
- };
+ }
if (is_before) {
strcat( cp, " ago");
cp += strlen(cp);
- };
+ }
#ifdef DATEDEBUG
printf( "EncodeTimeSpan- result is %s\n", str);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.16 1997/08/21 23:56:41 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.17 1997/09/05 18:11:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
if (*str != RDELIM) return(FALSE);
str++;
while (isspace( *str)) str++;
- };
+ }
if (s != NULL) *s = str;
return(TRUE);
} else if (strrchr( s, LDELIM) == s) {
depth++;
s = cp;
- };
- };
+ }
+ }
for (i = 0; i < npts; i++) {
if (! pair_decode( s, &(p->x), &(p->y), &s))
if (*s == DELIM) s++;
p++;
- };
+ }
while (depth > 0) {
if ((*s == RDELIM)
while (isspace( *s)) s++;
} else {
return(FALSE);
- };
- };
+ }
+ }
*ss = s;
return(TRUE);
break;
default:
break;
- };
+ }
for (i = 0; i < npts; i++) {
*cp++ = LDELIM;
*cp++ = RDELIM;
*cp++ = DELIM;
pt++;
- };
+ }
cp--;
switch (closed) {
case TRUE:
break;
default:
break;
- };
+ }
*cp = '\0';
return(result);
while ((s = strchr( s, delim)) != NULL) {
ndelim++;
s++;
- };
+ }
return((ndelim % 2)? ((ndelim+1)/2): -1);
}
x = box->high.x;
box->high.x = box->low.x;
box->low.x = x;
- };
+ }
if (box->high.y < box->low.y) {
y = box->high.y;
box->high.y = box->low.y;
box->low.y = y;
- };
+ }
return(box);
} /* box_in() */
} else {
result->high.x = x2;
result->low.x = x1;
- };
+ }
if (y1 > y2) {
result->high.y = y1;
result->low.y = y2;
} else {
result->high.y = y2;
result->low.y = y1;
- };
+ }
return(result);
}
digits8, (pt2->x - pt1->x), digits8, (pt2->y - pt1->y));
#endif
result->m = result->A;
- };
+ }
return(result);
} /* line_construct_pp() */
#endif
if (FPzero(l1->B)) {
return(FPzero(l2->B));
- };
+ }
return(FPeq(l2->A, l1->A*(l2->B / l1->B)));
} /* line_parallel() */
return( FPzero(l2->B) );
} else if (FPzero(l1->B)) {
return( FPzero(l2->A) );
- };
+ }
return( FPeq(((l1->A * l2->B) / (l1->B * l2->A)), -1.0) );
} /* line_perp() */
#endif
x = (l1->C - l2->C) / (l2->A - l1->A);
y = (l1->A * x + l1->C);
- };
+ }
result = point_construct(x, y);
#ifdef GEODEBUG
if ((*s == LDELIM) && (strrchr( s, LDELIM) == s)) {
s++;
depth++;
- };
+ }
size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * npts);
path = PALLOC(size);
min = tmp;
} else {
PFREE(tmp);
- };
+ }
}
return(min);
|| (FPeq( l1->p[1].x, l2->p[1].x) && FPeq( l1->p[1].y, l2->p[1].y))) {
result->x = l1->p[1].x;
result->y = l1->p[1].y;
- };
+ }
} else {
PFREE(result);
result = NULL;
- };
- };
+ }
+ }
PFREE(tmp1);
PFREE(tmp2);
(lseg->p[1].x - lseg->p[0].x);
#endif
m = ((lseg->p[0].y - lseg->p[1].y) / (lseg->p[1].x - lseg->p[0].x));
- };
+ }
ln = line_construct_pm(pt, m);
#ifdef GEODEBUG
tmpdist = point_distance(pt, &lseg->p[1]);
if (*tmpdist < *result) *result = *tmpdist;
PFREE (tmpdist);
- };
+ }
if (ip != NULL) PFREE(ip);
PFREE(ln);
result = d2;
} else {
PFREE( d2);
- };
- };
+ }
+ }
return(result);
}
*result = 0;
return(result);
- };
+ }
/* initialize distance with segment between first and last points */
seg.p[0].x = poly->p[0].x;
#endif
if (*d < *result) *result = *d;
PFREE(d);
- };
+ }
*result -= circle->radius;
if (*result < 0) *result = 0;
} else {
PFREE(p);
p = NULL;
- };
- };
+ }
+ }
PFREE(tmp);
return(p);
if (poly->p[i].x > x2) x2 = poly->p[i].x;
if (poly->p[i].y < y1) y1 = poly->p[i].y;
if (poly->p[i].y > y2) y2 = poly->p[i].y;
- };
+ }
box_fill(&(poly->boundbox), x1, x2, y1, y2);
} else {
elog (WARN, "Unable to create bounding box for empty polygon", NULL);
- };
+ }
}
/*------------------------------------------------------------------
if ((polya->p[i].x != polyb->p[i].x)
|| (polya->p[i].y != polyb->p[i].y))
return FALSE;
- };
+ }
return TRUE;
#endif
} /* poly_same() */
printf( "poly_contain- point (%f,%f) not in polygon\n", polyb->p[i].x, polyb->p[i].y);
#endif
return(FALSE);
- };
- };
+ }
+ }
for (i = 0; i < polya->npts; i++) {
if (point_inside(&(polya->p[i]), polyb->npts, &(polyb->p[0])) == 1) {
#if GEODEBUG
printf( "poly_contain- point (%f,%f) in polygon\n", polya->p[i].x, polya->p[i].y);
#endif
return(FALSE);
- };
- };
+ }
+ }
return(TRUE);
- };
+ }
#if GEODEBUG
printf( "poly_contain- bound box ((%f,%f),(%f,%f)) not inside ((%f,%f),(%f,%f))\n",
polyb->boundbox.low.x,polyb->boundbox.low.y,polyb->boundbox.high.x,polyb->boundbox.high.y,
for (i=0; i<p1->npts; i++) {
result->p[i].x = p1->p[i].x;
result->p[i].y = p1->p[i].y;
- };
+ }
for (i=0; i<p2->npts; i++) {
result->p[i+p1->npts].x = p2->p[i].x;
result->p[i+p1->npts].y = p2->p[i].y;
- };
+ }
return(result);
} /* path_add() */
for (i=0; i<path->npts; i++) {
result->p[i].x += point->x;
result->p[i].y += point->y;
- };
+ }
return(result);
} /* path_add_pt() */
for (i=0; i<path->npts; i++) {
result->p[i].x -= point->x;
result->p[i].y -= point->y;
- };
+ }
return(result);
} /* path_sub_pt() */
result->p[i].x = p->x;
result->p[i].y = p->y;
PFREE(p);
- };
+ }
return(result);
} /* path_mul_pt() */
result->p[i].x = p->x;
result->p[i].y = p->y;
PFREE(p);
- };
+ }
return(result);
} /* path_div_pt() */
for (i=0; i<path->npts; i++) {
poly->p[i].x = path->p[i].x;
poly->p[i].y = path->p[i].y;
- };
+ }
make_bound_box(poly);
for (i=0; i<result->npts; i++) {
result->p[i].x = path->p[i+1].x;
result->p[i].y = path->p[i+1].y;
- };
+ }
return(result);
} /* upgradepath() */
} else {
result = NULL;
- };
+ }
return(result);
} /* poly_center() */
for (i=0; i<poly->npts; i++) {
path->p[i].x = poly->p[i].x;
path->p[i].y = poly->p[i].y;
- };
+ }
return(path);
} /* poly_path() */
for (i=0; i<n2; i++) {
result->p[2*i].x = poly->p[i].x; /* even indices */
result->p[2*i+1].x = poly->p[i].y; /* odd indices */
- };
+ }
if ((ii = ((poly->npts % 2)? 1: 0))) {
result->p[poly->npts-1].x = poly->p[n2].x;
result->p[0].y = poly->p[n2].y;
- };
+ }
for (i=0; i<n2; i++) {
result->p[2*i+ii].y = poly->p[i+n2+ii].x; /* even (+offset) indices */
result->p[2*i+ii+1].y = poly->p[i+n2+ii].y; /* odd (+offset) indices */
- };
+ }
return(result);
} /* upgradepoly() */
for (i=0; i<n2; i++) {
result->p[i].x = poly->p[2*i].x; /* even indices */
result->p[i].y = poly->p[2*i+1].x; /* odd indices */
- };
+ }
if ((ii = ((poly->npts % 2)? 1: 0))) {
result->p[n2].x = poly->p[poly->npts-1].x;
result->p[n2].y = poly->p[0].y;
- };
+ }
for (i=0; i<n2; i++) {
result->p[i+n2+ii].x = poly->p[2*i+ii].y; /* even (+offset) indices */
result->p[i+n2+ii].y = poly->p[2*i+ii+1].y; /* odd (+offset) indices */
- };
+ }
return(result);
} /* revertpoly() */
while (isspace( *cp)) cp++;
if (*cp == LDELIM) {
s = cp;
- };
- };
+ }
+ }
if (! pair_decode( s, &circle->center.x, &circle->center.y, &s))
elog (WARN, "Bad circle external representation '%s'",str);
while (isspace( *s)) s++;
} else {
elog (WARN, "Bad circle external representation '%s'",str);
- };
- };
+ }
+ }
if (*s != '\0')
elog (WARN, "Bad circle external representation '%s'",str);
angle = i*(2*PI/npts);
poly->p[i].x = circle->center.x - (circle->radius*cos(angle));
poly->p[i].y = circle->center.y + (circle->radius*sin(angle));
- };
+ }
make_bound_box(poly);
for (i=0;i<poly->npts;i++) {
circle->center.x += poly->p[i].x;
circle->center.y += poly->p[i].y;
- };
+ }
circle->center.x /= poly->npts;
circle->center.y /= poly->npts;
for (i=0;i<poly->npts;i++) {
circle->radius += point_dt( &poly->p[i], &circle->center);
- };
+ }
circle->radius /= poly->npts;
if (FPzero(circle->radius))
} else { /* x < 0 */
if (FPzero( py)) return(FPlt( px, 0)? 0 : HIT_IT);
return(0);
- };
- };
+ }
+ }
/* Now we know y != 0; set sgn to sign of y */
sgn = (FPgt( y, 0)? 1 : -1);
z = (x-px) * y - (y-py) * x;
if (FPzero( z)) return(HIT_IT);
return( FPgt( (sgn*z), 0)? 0 : 2 * sgn);
- };
+ }
} /* lseg_crossing() */
printf( "plist_same- %d failed forward match with %d\n", j, ii);
#endif
break;
- };
- };
+ }
+ }
#ifdef GEODEBUG
printf( "plist_same- ii = %d/%d after forward match\n", ii, npts);
#endif
printf( "plist_same- %d failed reverse match with %d\n", j, ii);
#endif
break;
- };
- };
+ }
+ }
#ifdef GEODEBUG
printf( "plist_same- ii = %d/%d after reverse match\n", ii, npts);
#endif
if (ii == npts)
return(TRUE);
- };
- };
+ }
+ }
return(FALSE);
} /* plist_same() */