OSL_SHADEOP void osl_spline_dfdff(void *out, const char *spline_, void *x, float *knots, int knot_count) { const Spline::SplineBasis *spline = Spline::getSplineBasis(USTR(spline_)); Spline::spline_evaluate<Dual2<float>, Dual2<float>, float, float, false> (spline, DFLOAT(out), DFLOAT(x), knots, knot_count); }
OSL_SHADEOP void osl_splineinverse_dfdff(void *out, const char *spline_, void *x, float *knots, int knot_count, int knot_arraylen) { // x has derivs, so return derivs as well const Spline::SplineBasis *spline = Spline::getSplineBasis(USTR(spline_)); Spline::spline_inverse<Dual2<float> > (spline, DFLOAT(out), DFLOAT(x), knots, knot_count, knot_arraylen); }
LispObj * Lisp_XawScrollbarSetThumb(LispBuiltin *builtin) /* xaw-scrollbar-set-thumb widget top &optional shown */ { Widget widget; double top, shown; LispObj *owidget, *otop, *oshown; oshown = ARGUMENT(2); otop = ARGUMENT(1); owidget = ARGUMENT(0); if (!CHECKO(owidget, xawWidget_t)) LispDestroy("%s: cannot convert %s to Widget", STRFUN(builtin), STROBJ(owidget)); widget = (Widget)(owidget->data.opaque.data); CHECK_DFLOAT(otop); top = DFLOAT_VALUE(otop); if (oshown == UNSPEC) shown = 1.0; else { CHECK_DFLOAT(oshown); shown = DFLOAT_VALUE(oshown); } XawScrollbarSetThumb(widget, top, shown); return (oshown == UNSPEC ? DFLOAT(shown) : oshown); }
OSL_SHADEOP void osl_spline_dvdfdv(void *out, const char *spline_, void *x, Vec3 *knots, int knot_count) { const Spline::SplineBasis *spline = Spline::getSplineBasis(USTR(spline_)); Spline::spline_evaluate<Dual2<Vec3>, Dual2<float>, Dual2<Vec3>, Vec3, true> (spline, DVEC(out), DFLOAT(x), knots, knot_count); }
OSL_SHADEOP void osl_spline_dffdf(void *out, const char *spline_, void *x, float *knots, int knot_count, int knot_arraylen) { const Spline::SplineBasis *spline = Spline::getSplineBasis(USTR(spline_)); Spline::spline_evaluate<Dual2<float>, float, Dual2<float>, float, true> (spline, DFLOAT(out), *(float *)x, knots, knot_count, knot_arraylen); }
OSL_SHADEOP void osl_splineinverse_dffdf(void *out, const char *spline_, void *x, float *knots, int knot_count, int knot_arraylen) { // Ignore knot derivs float outtmp = 0; osl_splineinverse_fff (&outtmp, spline_, x, knots, knot_count, knot_arraylen); DFLOAT(out) = outtmp; }
LispObj * Lisp_XawScrollbarCoerceToReal(LispBuiltin *builtin) /* xaw-scrollbar-coerce-to-real opaque */ { float *floatp; double real; LispObj *opaque; opaque = ARGUMENT(0); if (!CHECKO(opaque, xawFloatp_t)) LispDestroy("%s: cannot convert %s to float*", STRFUN(builtin), STROBJ(opaque)); floatp = (float*)(opaque->data.opaque.data); real = *floatp; return (DFLOAT(real)); }
LispObj * Lisp_PQgetvalue(LispBuiltin *builtin) /* pq-getvalue result tuple field &optional type-specifier */ { char *string; double real = 0.0; PGresult *res; int tuple, field, isint = 0, isreal = 0, integer; LispObj *result, *otupple, *field_number, *type; type = ARGUMENT(3); field_number = ARGUMENT(2); otupple = ARGUMENT(1); result = ARGUMENT(0); if (!CHECKO(result, PGresult_t)) LispDestroy("%s: cannot convert %s to PGresult*", STRFUN(builtin), STROBJ(result)); res = (PGresult*)(result->data.opaque.data); CHECK_INDEX(otupple); tuple = FIXNUM_VALUE(otupple); CHECK_INDEX(field_number); field = FIXNUM_VALUE(field_number); string = PQgetvalue(res, tuple, field); if (type != UNSPEC) { char *typestring; CHECK_SYMBOL(type); typestring = ATOMID(type); if (strcmp(typestring, "INT16") == 0) { integer = *(short*)string; isint = 1; goto simple_type; } else if (strcmp(typestring, "INT32") == 0) { integer = *(int*)string; isint = 1; goto simple_type; } else if (strcmp(typestring, "FLOAT") == 0) { real = *(float*)string; isreal = 1; goto simple_type; } else if (strcmp(typestring, "REAL") == 0) { real = *(double*)string; isreal = 1; goto simple_type; } else if (strcmp(typestring, "PG-POLYGON") == 0) goto polygon_type; else if (strcmp(typestring, "STRING") != 0) LispDestroy("%s: unknown type %s", STRFUN(builtin), typestring); } simple_type: return (isint ? INTEGER(integer) : isreal ? DFLOAT(real) : (string ? STRING(string) : NIL)); polygon_type: { LispObj *poly, *box, *p = NIL, *cdr, *obj; POLYGON *polygon; int i, size; size = PQgetlength(res, tuple, field); polygon = (POLYGON*)(string - sizeof(int)); GCDisable(); /* get polygon->boundbox */ cdr = EVAL(CONS(ATOM("MAKE-PG-POINT"), CONS(KEYWORD("X"), CONS(REAL(polygon->boundbox.high.x), CONS(KEYWORD("Y"), CONS(REAL(polygon->boundbox.high.y), NIL)))))); obj = EVAL(CONS(ATOM("MAKE-PG-POINT"), CONS(KEYWORD("X"), CONS(REAL(polygon->boundbox.low.x), CONS(KEYWORD("Y"), CONS(REAL(polygon->boundbox.low.y), NIL)))))); box = EVAL(CONS(ATOM("MAKE-PG-BOX"), CONS(KEYWORD("HIGH"), CONS(cdr, CONS(KEYWORD("LOW"), CONS(obj, NIL)))))); /* get polygon->p values */ for (i = 0; i < polygon->npts; i++) { obj = EVAL(CONS(ATOM("MAKE-PG-POINT"), CONS(KEYWORD("X"), CONS(REAL(polygon->p[i].x), CONS(KEYWORD("Y"), CONS(REAL(polygon->p[i].y), NIL)))))); if (i == 0) p = cdr = CONS(obj, NIL); else { RPLACD(cdr, CONS(obj, NIL)); cdr = CDR(cdr); } } /* make result */ poly = EVAL(CONS(ATOM("MAKE-PG-POLYGON"), CONS(KEYWORD("SIZE"), CONS(REAL(size), CONS(KEYWORD("NUM-POINTS"), CONS(REAL(polygon->npts), CONS(KEYWORD("BOUNDBOX"), CONS(box, CONS(KEYWORD("POINTS"), CONS(QUOTE(p), NIL)))))))))); GCEnable(); return (poly); } }