SEXP attribute_hidden do_nextn(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP n, f, ans; int i, nn, nf; checkArity(op, args); PROTECT(n = coerceVector(CAR(args), INTSXP)); PROTECT(f = coerceVector(CADR(args), INTSXP)); nn = LENGTH(n); nf = LENGTH(f); /* check the factors */ if (nf == 0) error(_("no factors")); for (i = 0; i < nf; i++) if (INTEGER(f)[i] == NA_INTEGER || INTEGER(f)[i] <= 1) error(_("invalid factors")); ans = allocVector(INTSXP, nn); for (i = 0; i < nn; i++) { if (INTEGER(n)[i] == NA_INTEGER) INTEGER(ans)[i] = NA_INTEGER; else if (INTEGER(n)[i] <= 1) INTEGER(ans)[i] = 1; else INTEGER(ans)[i] = nextn(INTEGER(n)[i], INTEGER(f), nf); } UNPROTECT(2); return ans; }
void TLens::draw_3d_e(TRenderer &r, const TElement *ref) const { // surfaces TGroup::draw_3d_e(r, ref); #if 0 // FIXME check / broken code // draw TLens contours for (unsigned int i = 0; i < _surfaces.size() - 1; i++) { const TSurface & left = _surfaces[i]; const TSurface & right = _surfaces[i+1]; const TShapeBase &s = left.get_shape(); TRgb color = left.get_color(r); if (&s != &right.get_shape()) continue; for (unsigned int i = 0; i < s.get_contour_count(); i++) { // get 2d contour points std::vector<Math::Vector2 > contour; delegate_push<typeof(contour)> contour_push(contour); s.get_contour(i, contour_push, r.get_feature_size()); unsigned int j; unsigned int count = contour.size(); if (count < 2) continue; Math::Vector3 pr[count]; Math::Vector3 pl[count]; // compute 3d contour points const Math::Transform<3> &rtr = right.get_global_transform(); const Math::Transform<3> <r = left.get_global_transform(); for (j = 0; j < count; j++) { pr[j] = rtr.transform(Math::Vector3(contour[j], right.get_curve().sagitta(contour[j]))); pl[j] = ltr.transform(Math::Vector3(contour[j], left.get_curve().sagitta(contour[j]))); } // compute normals and draw Math::Vector3 prevn(Math::Triangle<3>(pr[count - 1], pl[count - 1], pl[0]).normal()); Math::Triangle<3> cur(pr[0], pl[0], pl[1]); Math::Vector3 curn(cur.normal()); for (j = 0; j < count; j++) { Math::Triangle<3> next(pr[(j+1) % count], pl[(j+1) % count], pl[(j+2) % count]); Math::Vector3 nextn(next.normal()); Math::Vector3 n1((prevn + curn) * 0.5); Math::Vector3 n2((curn + nextn) * 0.5); r.draw_triangle(cur, Math::Triangle<3>(n1, n1, n2), color); r.draw_triangle(Math::Triangle<3>(pl[(j+1) % count], pr[(j+1) % count], pr[j]), Math::Triangle<3>(n2, n2, n1), color); prevn = curn; cur = next; curn = nextn; } } } #endif }