void LAPACKE_cgb_trans( int matrix_order, lapack_int m, lapack_int n, lapack_int kl, lapack_int ku, const lapack_complex_float *in, lapack_int ldin, lapack_complex_float *out, lapack_int ldout ) { lapack_int i, j; if( in == NULL || out == NULL ) return; if( matrix_order == LAPACK_COL_MAJOR ) { for( j = 0; j < MIN( ldout, n ); j++ ) { for( i = MAX( ku-j, 0 ); i < MIN3( ldin, m+ku-j, kl+ku+1 ); i++ ) { out[(size_t)i*ldout+j] = in[i+(size_t)j*ldin]; } } } else if ( matrix_order == LAPACK_ROW_MAJOR ) { /* TODO: interchange loops for performance. * This is just reference impemeltation. */ for( j = 0; j < MIN( n, ldin ); j++ ) { for( i = MAX( ku-j, 0 ); i < MIN3( ldout, m+ku-j, kl+ku+1 ); i++ ) { out[i+(size_t)j*ldout] = in[(size_t)i*ldin+j]; } } } }
int ed(WorkPtr work, int s1, int s2, int rcflag) { // if rcflag==1 then we study the rc(s2) rather than s2 int row, col, l1, l2, r1, r2, curr,prev; int num_words_1, num_words_2; int score=0; void *x, *y; dmat1Arr dmat[2]; int the_min,min_min=0; dmat[0] = work->fn_data; dmat[1] = work->fn_data+MAX_SEQ_LEN; //memset(dmat[0],0,2*sizeof(dmatEntry)*MAX_SEQ_LEN); // rather than comparing the entire ESTs, we narrow down // the regions on the ESTs where the match could be get_bounds(work,s1, s2, &l1, &r1); // bounds for s1 get_bounds(work,s2, s1, &l2, &r2); // bounds for s2 if (r1-l1< 4)return (10*window_len);// don't bother if not there l1 = MAX(0,l1-window_len); // region could star l2 = MAX(0,l2-window_len); r1 = MIN(r1+window_len,seqInfo[s1].len); r2 = MIN(r2+window_len,seqInfo[s2].len); NUM_dfn++; num_words_1 = r1-word_len+1; num_words_2 = r2-word_len+1; create_word_lists(work,s1, s2, rcflag); prev=0; curr=1; for(row=0; row<=r1; row++) dmat[0][row].f = OPEN; for(col=l2; col<r2 && min_min > theta ; col++) { dmat[curr][l1].f=dmat[curr][l1].m=0; dmat[curr][l1].e=OPEN; for (row=l1+1; row<=r1 && min_min > theta; row++) { the_min=0; dmat[curr][row].f = MIN3(dmat[prev][row].e+EXTEND+OPEN, dmat[prev][row].f+EXTEND, dmat[prev][row].g+OPEN+EXTEND); if (dmat[curr][row].f < the_min) the_min = dmat[curr][row].f; dmat[curr][row].g = dmat[prev][row-1].m+ cost[work->word1[row-1]][work->word2[col]]; if (dmat[curr][row].g < the_min) the_min = dmat[curr][row].g; dmat[curr][row].e = MIN3(dmat[curr][row-1].e+EXTEND, dmat[curr][row-1].f+EXTEND+OPEN, dmat[curr][row-1].g+OPEN+EXTEND); if (dmat[curr][row].e < the_min) the_min = dmat[curr][row].e; dmat[curr][row].m=the_min; if (the_min<min_min) min_min=the_min; } prev = curr; curr = 1-curr; } return min_min; }
int edpair(WorkPtr work, int s1, int s2, int rcflag) { // if rcflag==1 then we study the rc(s2) rather than s2 int row, col, l1, l2, r1, r2, curr,prev; int num_words_1, num_words_2; int score=0; void *x, *y; dmat1Arr dmat[2]; int the_min,min_min=0; dmat[0] = work->fn_data; dmat[1] = work->fn_data+MAX_SEQ_LEN; //memset(dmat[0],0,2*sizeof(dmatEntry)*MAX_SEQ_LEN); l1 = 0; // region could star l2 = 0; r1 = seqInfo[s1].len; r2 = seqInfo[s2].len; NUM_dfn++; num_words_1 = r1-word_len+1; num_words_2 = r2-word_len+1; create_word_lists(work,s1, s2, rcflag); prev=0; curr=1; for(row=0; row<=r1; row++) dmat[0][row].f = OPEN; for(col=l2; col<r2 && min_min > theta ; col++) { dmat[curr][l1].f=dmat[curr][l1].m=0; dmat[curr][l1].e=OPEN; for (row=l1+1; row<=r1 && min_min > theta; row++) { the_min=0; dmat[curr][row].f = MIN3(dmat[prev][row].e+EXTEND+OPEN, dmat[prev][row].f+EXTEND, dmat[prev][row].g+OPEN+EXTEND); if (dmat[curr][row].f < the_min) the_min = dmat[curr][row].f; dmat[curr][row].g = dmat[prev][row-1].m+ cost[work->word1[row-1]][work->word2[col]]; if (dmat[curr][row].g < the_min) the_min = dmat[curr][row].g; dmat[curr][row].e = MIN3(dmat[curr][row-1].e+EXTEND, dmat[curr][row-1].f+EXTEND+OPEN, dmat[curr][row-1].g+OPEN+EXTEND); if (dmat[curr][row].e < the_min) the_min = dmat[curr][row].e; dmat[curr][row].m=the_min; if (the_min<min_min) min_min=the_min; } prev = curr; curr = 1-curr; } return min_min; }
long point_triangle_intersection(Point3 p, Triangle3 t) { long sign12,sign23,sign31; Point3 vect12,vect23,vect31,vect1h,vect2h,vect3h; Point3 cross12_1p,cross23_2p,cross31_3p; /* First, a quick bounding-box test: */ /* If P is outside triangle bbox, there cannot be an intersection. */ if (p.x > MAX3(t.v1.x, t.v2.x, t.v3.x)) return(OUTSIDE); if (p.y > MAX3(t.v1.y, t.v2.y, t.v3.y)) return(OUTSIDE); if (p.z > MAX3(t.v1.z, t.v2.z, t.v3.z)) return(OUTSIDE); if (p.x < MIN3(t.v1.x, t.v2.x, t.v3.x)) return(OUTSIDE); if (p.y < MIN3(t.v1.y, t.v2.y, t.v3.y)) return(OUTSIDE); if (p.z < MIN3(t.v1.z, t.v2.z, t.v3.z)) return(OUTSIDE); /* For each triangle side, make a vector out of it by subtracting vertexes; */ /* make another vector from one vertex to point P. */ /* The crossproduct of these two vectors is orthogonal to both and the */ /* signs of its X,Y,Z components indicate whether P was to the inside or */ /* to the outside of this triangle side. */ SUB(t.v1, t.v2, vect12) SUB(t.v1, p, vect1h); CROSS(vect12, vect1h, cross12_1p) sign12 = SIGN3(cross12_1p); /* Extract X,Y,Z signs as 0..7 or 0...63 integer */ SUB(t.v2, t.v3, vect23) SUB(t.v2, p, vect2h); CROSS(vect23, vect2h, cross23_2p) sign23 = SIGN3(cross23_2p); SUB(t.v3, t.v1, vect31) SUB(t.v3, p, vect3h); CROSS(vect31, vect3h, cross31_3p) sign31 = SIGN3(cross31_3p); /* If all three crossproduct vectors agree in their component signs, */ /* then the point must be inside all three. */ /* P cannot be OUTSIDE all three sides simultaneously. */ /* this is the old test; with the revised SIGN3() macro, the test * needs to be revised. */ #ifdef OLD_TEST if ((sign12 == sign23) && (sign23 == sign31)) return(INSIDE); else return(OUTSIDE); #else return ((sign12 & sign23 & sign31) == 0) ? OUTSIDE : INSIDE; #endif }
/****************************************************************************** FUNCTION: RGBtoHLS PURPOSE: Convert from RGB to HLS IN: RGB color (0xBBGGRR) OUT: Hue, Saturation, Luminance from 0 to 1 COPYRIGHT:1995-1997 Robert Mashlan Modified for LabWindows/CVI, 1999 Guillaume Dargaud ******************************************************************************/ void RGBtoHLS(const COLORREF rgb, double *H, double *L, double *S ) { double delta; double r = (double)((rgb )&0xFF)/255; double g = (double)((rgb>> 8)&0xFF)/255; double b = (double)((rgb>>16)&0xFF)/255; double cmax = MAX3(r,g,b); double cmin = MIN3(r,g,b); *L=(cmax+cmin)/2.0; if(cmax == cmin) { *S = *H = 0; // it's really undefined } else { if(*L < 0.5) *S = (cmax-cmin)/(cmax+cmin); else *S = (cmax-cmin)/(2.0-cmax-cmin); delta = cmax - cmin; if(r == cmax) { *H = (g - b) / delta; } else { if(g == cmax) *H = 2.0 + (b-r) / delta; else *H = 4.0 + (r-g) / delta; } *H /= 6.0; if (*H < 0.0) *H += 1; } }
int main() { int mult_2, mult_3, mult_5; int i, j, k, l; int prev_un; #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif UN[0] = prev_un = 1; j = k = l = 0; for (i = 1; i < MAX_NUM; i++) { for (; (mult_2 = UN[j] * 2) <= prev_un; j++); for (; (mult_3 = UN[k] * 3) <= prev_un; k++); for (; (mult_5 = UN[l] * 5) <= prev_un; l++); UN[i] = prev_un = MIN3(mult_2, mult_3, mult_5); /*printf("%d, %d, %d, %d\n", mult_2, mult_3, mult_5, UN[i]);*/ } printf("The 1500'th ugly number is %d.\n", UN[MAX_NUM-1]); #ifndef ONLINE_JUDGE system("pause"); #endif return 0; }
int main(){ scanf("%u",&t); t++; // :D while(--t){ scanf("%u %u",&n,&m); int32_t MAP[n][m],COSTS[n][m]; for(int32_t i=0;i<n;++i){ for (int32_t j=0;j<m;++j){ scanf("%d",&MAP[i][j]); COSTS[i][j]=MAP[i][j]; } } for (int32_t j=1;j<m;++j){ for(int32_t i=0;i<n;++i){ if (i==0){ COSTS[i][j]+= MIN2(COSTS[i][j-1],COSTS[i+1][j-1]); } else if (i==n-1){ COSTS[i][j]+= MIN2(COSTS[i][j-1],COSTS[i-1][j-1]); } else { COSTS[i][j]+= MIN3(COSTS[i][j-1],COSTS[i+1][j-1],COSTS[i-1][j-1]); } } } int32_t min=1<<30; for(int32_t i=0;i<n;++i){ min=MIN2(min,COSTS[i][m-1]); } printf("%d\n",min); } }
int _IsolateMinorE4(graphP theGraph) { isolatorContextP IC = &theGraph->IC; if (IC->px != IC->x) { if (_MarkPathAlongBicompExtFace(theGraph, IC->r, IC->w) != OK || _MarkPathAlongBicompExtFace(theGraph, IC->py, IC->r) != OK) return NOTOK; } else { if (_MarkPathAlongBicompExtFace(theGraph, IC->r, IC->px) != OK || _MarkPathAlongBicompExtFace(theGraph, IC->w, IC->r) != OK) return NOTOK; } if (theGraph->functions.fpMarkDFSPath(theGraph, MIN3(IC->ux, IC->uy, IC->uz), MAX3(IC->ux, IC->uy, IC->uz)) != OK || _MarkDFSPathsToDescendants(theGraph) != OK || _JoinBicomps(theGraph) != OK || _AddAndMarkUnembeddedEdges(theGraph) != OK) return NOTOK; theGraph->IC.minorType |= MINORTYPE_E4; return OK; }
static void RGBtoHSV (double r, double g, double b, double *h, double *s, double *v) { double min, max, delta; min = MIN3 (r, g, b ); max = MAX3 (r, g, b ); *v = max; // v delta = max - min; if (max != 0) *s = delta / max; // s else { *s = 0.0; *h = 0.0; return; } if (delta == 0.0) *h = 0.0; // some shade of grey else if (r == max) *h = (g - b) / delta; // between yellow & magenta else if (g == max) *h = 2 + ( b - r ) / delta; // between cyan & yellow else *h = 4 + (r - g) / delta; // between magenta & cyan #if 0 if (isnan (*h)) { printf ("isnan %f %f %f %f %f %f\n", r, g, b, delta, max, min); } #endif *h *= M_PI / 3.0; // degrees if (*h < 0) *h += 2.0 * M_PI; }
struct hsv_color rgbtohsv_int(struct rgb_color rgb) { struct hsv_color hsv; uint8_T rgb_min, rgb_max; rgb_min = MIN3(rgb.r, rgb.g, rgb.b); rgb_max = MAX3(rgb.r, rgb.g, rgb.b); if((rgb_max-rgb_min)==0){ return hsv; }else if(rgb_max==0){ return hsv; } /* Compute hue */ if (rgb_max == rgb.r) { hsv.hue = 0 + 43*(rgb.g - rgb.b)/(rgb_max - rgb_min); } else if (rgb_max == rgb.g) { hsv.hue = 85 + 43*(rgb.b - rgb.r)/(rgb_max - rgb_min); } else /* rgb_max == rgb.b */ { hsv.hue = 171 + 43*(rgb.r - rgb.g)/(rgb_max - rgb_min); } hsv.val = rgb_max; hsv.sat = 255*(long)(rgb_max - rgb_min)/rgb_max; return hsv; }
double OperaColors::RGB2HUE(double r, double g, double b) { double H; double m2 = MAX3(r, g, b); double m1 = CENTER(r, g, b); double m0 = MIN3(r, g, b); if (m2 == m1) { if (r == g) { H = 60; goto _RGB2HUE_END; } if (g == b) { H = 180; goto _RGB2HUE_END; } H = 60; goto _RGB2HUE_END; } double F = 60 * (m1 - m0) / (m2 - m0); if (r == m2) { H = 0 + F * (g - b); goto _RGB2HUE_END; } if (g == m2) { H = 120 + F * (b - r); goto _RGB2HUE_END; } H = 240 + F * (r - g); _RGB2HUE_END: if (H < 0) H = H + 360; return H; }
int _IsolateMinorE4(graphP theGraph) { isolatorContextP IC = &theGraph->IC; if (IC->px != IC->x) { if (_MarkPathAlongBicompExtFace(theGraph, IC->r, IC->w) != OK || _MarkPathAlongBicompExtFace(theGraph, IC->py, IC->r) != OK) return NOTOK; } else { if (_MarkPathAlongBicompExtFace(theGraph, IC->r, IC->px) != OK || _MarkPathAlongBicompExtFace(theGraph, IC->w, IC->r) != OK) return NOTOK; } // Note: The x-y path is already marked, due to identifying E as the type of non-planarity minor if (theGraph->functions.fpMarkDFSPath(theGraph, MIN3(IC->ux, IC->uy, IC->uz), MAX3(IC->ux, IC->uy, IC->uz)) != OK || _MarkDFSPathsToDescendants(theGraph) != OK || _JoinBicomps(theGraph) != OK || _AddAndMarkUnembeddedEdges(theGraph) != OK) return NOTOK; theGraph->IC.minorType |= MINORTYPE_E4; return OK; }
/** * @brief Convert an sRGB color to Hue-Saturation-Value (HSV) * * @param H, S, V pointers to hold the result * @param R, G, B the input sRGB values scaled in [0,1] * * This routine transforms from sRGB to the hexcone HSV color space. The * sRGB values are assumed to be between 0 and 1. The output values are * H = hexagonal hue angle (0 <= H < 360), * S = C/V (0 <= S <= 1), * V = max(R',G',B') (0 <= V <= 1), * where C = max(R',G',B') - min(R',G',B'). The inverse color transformation * is given by Hsv2Rgb. * * Wikipedia: http://en.wikipedia.org/wiki/HSL_and_HSV */ void Rgb2Hsv(num *H, num *S, num *V, num R, num G, num B) { num Max = MAX3(R, G, B); num Min = MIN3(R, G, B); num C = Max - Min; *V = Max; if(C > 0) { if(Max == R) { *H = (G - B) / C; if(G < B) *H += 6; } else if(Max == G) *H = 2 + (B - R) / C; else *H = 4 + (R - G) / C; *H *= 60; *S = C / Max; } else *H = *S = 0; }
/* Find substrings matching .(expr), where expr is a balanced expression * (following R rules for matching [], (), {}, '', "", ``, %%, \, and comments.) * Returns a _list_ of _character arrays_ one array per each input string. * Each character array alternates between "outside quote" and "inside quote." */ SEXP _find_subst_expressions_list(SEXP strs, SEXP begin, SEXP end) { int ns, nb, ne; assert_type(strs, STRSXP); assert_type(begin, STRSXP); assert_type(end, STRSXP); ns = LENGTH(strs); nb = LENGTH(begin); ne = LENGTH(end); int nout; if (MIN3(ns, nb, ne) == 0) { nout = 0; } else { nout = MAX3(ns, nb, ne); if ((nout % ns > 0)||(nout % nb > 0)||(nout % ne > 0)) { warning("longer object length is not a multiple" " of shorter object length"); } } SEXP out = PROTECT(allocVector(VECSXP, nout)); if (ns == nout) setAttrib(out, R_NamesSymbol, getAttrib(strs, R_NamesSymbol)); for (int i = 0; i < nout; i++) { SET_VECTOR_ELT(out, i, find_subst_expressions(STRING_ELT(strs, i%ns), STRING_ELT(begin, i%nb), STRING_ELT(end, i%ne))); } UNPROTECT(1); return out; }
void MSTrafficLightLogic::init(NLDetectorBuilder&) { const Phases& phases = getPhases(); if (phases.size() > 1) { bool haveWarnedAboutUnusedStates = false; // warn about transistions from green to red without intermediate yellow for (int i = 0; i < (int)phases.size(); ++i) { const int iNext = (i + 1) % phases.size(); const std::string& state1 = phases[i]->getState(); const std::string& state2 = phases[iNext]->getState(); assert(state1.size() == state2.size()); if (!haveWarnedAboutUnusedStates && state1.size() > myLanes.size()) { WRITE_WARNING("Unused states in tlLogic '" + getID() + "', program '" + getProgramID() + "' in phase " + toString(i) + " after tl-index " + toString((int)myLanes.size() - 1)); haveWarnedAboutUnusedStates = true; } for (int j = 0; j < (int)MIN3(state1.size(), state2.size(), myLanes.size()); ++j) { if ((LinkState)state2[j] == LINKSTATE_TL_RED && ((LinkState)state1[j] == LINKSTATE_TL_GREEN_MAJOR || (LinkState)state1[j] == LINKSTATE_TL_GREEN_MINOR)) { for (LaneVector::const_iterator it = myLanes[j].begin(); it != myLanes[j].end(); ++it) { if ((*it)->getPermissions() != SVC_PEDESTRIAN) { WRITE_WARNING("Missing yellow phase in tlLogic '" + getID() + "', program '" + getProgramID() + "' for tl-index " + toString(j) + " when switching to phase " + toString(iNext)); return; // one warning per program is enough } } } } } } }
inline void rgb_to_hls(float r, float g, float b, float &h, float &l, float &s) { /* Given: r, b, g each in [0.1] * Desired: h in [0,360), l and s in [0,1] */ float max = MAX3(r,g,b); float min = MIN3(r,g,b); l = (max+min)/2.0f; /* This is lightness */ /* Next calculate saturation */ if (max == min) { /* Achromatic, because r = g = b */ s = 0.0f; h = 0.0f; /* Actually: UNDEFINED */ } else { /* Chromatic case */ float delta = max-min; /* First calculate saturation */ s = (l<=0.5f) ? (delta / (max+min)) : (delta / (2.0f - (max+min))); /* Next calculate the hue */ if (r == max) h = (g-b)/delta; else if (g == max) h = 2.0f + (b-r)/delta; else if (b == max) h = 4.0f + (r-g)/delta; h *= 60.0f; if (h<0.0f) h += 360.0f; } /*Chromatic case */ } /* RGB_To_HLS */
hsv_color RGBtoHSV(rgba_color rgb) { float min, max, delta; min = MIN3(rgb.r, rgb.g, rgb.b); max = MAX3(rgb.r, rgb.g, rgb.b); hsv_color ret; ret.a = rgb.a; ret.v = max; // v delta = max - min; if (max != 0) ret.s = delta / max; // s else { // r = g = b = 0 // s = 0, v is undefined ret.s = 0; ret.h = -1; return ret; } if (rgb.r == max) ret.h = (rgb.g - rgb.b) / delta; // between yellow & magenta else if (rgb.g == max) ret.h = 2 + (rgb.b - rgb.r) / delta; // between cyan & yellow else ret.h = 4 + (rgb.r - rgb.g) / delta; // between magenta & cyan ret.h *= 60; // degrees if (ret.h < 0) ret.h += 360; return ret; }
/** * @brief Convert an sRGB color to Hue-Saturation-Lightness (HSL) * * @param H, S, L pointers to hold the result * @param R, G, B the input sRGB values scaled in [0,1] * * This routine transforms from sRGB to the double hexcone HSL color space * The sRGB values are assumed to be between 0 and 1. The outputs are * H = hexagonal hue angle (0 <= H < 360), * S = { C/(2L) if L <= 1/2 (0 <= S <= 1), * { C/(2 - 2L) if L > 1/2 * L = (max(R',G',B') + min(R',G',B'))/2 (0 <= L <= 1), * where C = max(R',G',B') - min(R',G',B'). The inverse color transformation * is given by Hsl2Rgb. * * Wikipedia: http://en.wikipedia.org/wiki/HSL_and_HSV */ void Rgb2Hsl(num *H, num *S, num *L, num R, num G, num B) { num Max = MAX3(R, G, B); num Min = MIN3(R, G, B); num C = Max - Min; *L = (Max + Min)/2; if(C > 0) { if(Max == R) { *H = (G - B) / C; if(G < B) *H += 6; } else if(Max == G) *H = 2 + (B - R) / C; else *H = 4 + (R - G) / C; *H *= 60; *S = (*L <= 0.5) ? (C/(2*(*L))) : (C/(2 - 2*(*L))); } else *H = *S = 0; }
void Rgb2Hf(float *H, float R, float G, float B) { float Max = MAX3(R, G, B); float Min = MIN3(R, G, B); float C = Max - Min; if(C > 0) { if(Max == R) { *H = (G - B) / C; if(G < B) *H += 6; } else if(Max == G) *H = 2 + (B - R) / C; else *H = 4 + (R - G) / C; *H *= 60; } else *H = 0; }
SUMOReal MSCFModel_SmartSK::moveHelper(MSVehicle* const veh, SUMOReal vPos) const { const SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation const SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops // we need the acceleration for emission computation; // in this case, we neglect dawdling, nonetheless, using // vSafe does not incorporate speed reduction due to interaction // on lane changing const SUMOReal vMin = getSpeedAfterMaxDecel(oldV); const SUMOReal vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe); #ifdef _DEBUG if (vMin > vMax) { WRITE_WARNING("Vehicle's '" + veh->getID() + "' maximum speed is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ")."); } #endif updateMyHeadway(veh); SSKVehicleVariables* vars = (SSKVehicleVariables*)veh->getCarFollowVariables(); #ifdef _DEBUG if (vars->ggOld.size() > 1) { std::cout << "# more than one entry in ggOld list. Speed is " << vPos << ", corresponding dist is " << vars->ggOld[(int) vPos] << "\n"; for (std::map<int, SUMOReal>::iterator I = vars->ggOld.begin(); I != vars->ggOld.end(); I++) { std::cout << "# " << (*I).first << ' ' << (*I).second << std::endl; } } #endif vars->gOld = vars->ggOld[(int) vPos]; vars->ggOld.clear(); return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax)), vMax, *this); }
STATIC ssize_t fat_read(fs_handle handle, char *buf, size_t bufsize) { fat_file_handle *h = (fat_file_handle *) handle; fat_fs_device_data *d = h->fs->device_data; u32 fsize = h->e->DIR_FileSize; size_t written_to_buf = 0; if (h->pos >= fsize) { /* * The cursor is at the end or past the end: nothing to read. */ return 0; } do { char *data = fat_get_pointer_to_cluster_data(d->hdr, h->curr_cluster); const ssize_t file_rem = (ssize_t)(fsize - h->pos); const ssize_t buf_rem = (ssize_t)(bufsize - written_to_buf); const size_t cluster_offset = h->pos % d->cluster_size; const ssize_t cluster_rem = (ssize_t)(d->cluster_size - cluster_offset); const ssize_t to_read = MIN3(cluster_rem, buf_rem, file_rem); ASSERT(to_read >= 0); memcpy(buf + written_to_buf, data + cluster_offset, (size_t)to_read); written_to_buf += (size_t)to_read; h->pos += (size_t)to_read; if (to_read < cluster_rem) { /* * We read less than cluster_rem because the buf was not big enough * or because the file was not big enough. In either case, we cannot * continue. */ break; } // find the next cluster u32 fatval = fat_read_fat_entry(d->hdr, d->type, h->curr_cluster, 0); if (fat_is_end_of_clusterchain(d->type, fatval)) { ASSERT(h->pos == fsize); break; } // we do not expect BAD CLUSTERS ASSERT(!fat_is_bad_cluster(d->type, fatval)); h->curr_cluster = fatval; // go reading the new cluster in the chain. } while (true); return (ssize_t)written_to_buf; }
static hsv_color rgb_to_hsv(rgb_color rgb) { uint8_t rgb_min, rgb_max; hsv_color hsv; //integer find min and max RGB value rgb_min = MIN3(rgb.r, rgb.g, rgb.b); rgb_max = MAX3(rgb.r, rgb.g, rgb.b); //compute value hsv.v = rgb_max; if (hsv.v == 0) { hsv.h = hsv.s = 0; } else { //integer compute saturation hsv.s = 255*((uint16_t)(rgb_max - rgb_min))/hsv.v; if (hsv.s == 0) { hsv.h = 0; } else { //integer compute hue if (rgb_max == rgb.r) { hsv.h = 0 + 43*(rgb.g - rgb.b)/(rgb_max - rgb_min); } else if (rgb_max == rgb.g) { hsv.h = 85 + 43*(rgb.b - rgb.r)/(rgb_max - rgb_min); } else /* rgb_max == rgb.b */ { hsv.h = 171 + 43*(rgb.r - rgb.g)/(rgb_max - rgb_min); } } } return hsv; }
int _IsolateMinorE(graphP theGraph) { isolatorContextP IC = &theGraph->IC; /* Minor E1: Isolate a K3,3 homeomorph */ if (IC->z != IC->w) return _IsolateMinorE1(theGraph); /* Minor E2: Isolate a K3,3 homeomorph */ if (IC->uz > MAX(IC->ux, IC->uy)) return _IsolateMinorE2(theGraph); /* Minor E3: Isolate a K3,3 homeomorph */ if (IC->uz < MAX(IC->ux, IC->uy) && IC->ux != IC->uy) return _IsolateMinorE3(theGraph); /* Minor E4: Isolate a K3,3 homeomorph */ else if (IC->x != IC->px || IC->y != IC->py) return _IsolateMinorE4(theGraph); /* Minor E: Isolate a K5 homeomorph */ if (_MarkPathAlongBicompExtFace(theGraph, IC->r, IC->r) != OK || theGraph->functions.fpMarkDFSPath(theGraph, MIN3(IC->ux, IC->uy, IC->uz), IC->r) != OK || _MarkDFSPathsToDescendants(theGraph) != OK || _JoinBicomps(theGraph) != OK || _AddAndMarkUnembeddedEdges(theGraph) != OK) return NOTOK; return OK; }
struct hsv_color rgb_to_hsv(struct rgb_color rgb) { struct hsv_color hsv; unsigned char rgb_min, rgb_max; rgb_min = MIN3(rgb.r, rgb.g, rgb.b); rgb_max = MAX3(rgb.r, rgb.g, rgb.b); hsv.val = rgb_max; if (hsv.val == 0) { hsv.hue = hsv.sat = 0; return hsv; } hsv.sat = 255*long(rgb_max - rgb_min)/hsv.val; if (hsv.sat == 0) { hsv.hue = 0; return hsv; } /* Compute hue */ if (rgb_max == rgb.r) { hsv.hue = 0 + 43*(rgb.g - rgb.b)/(rgb_max - rgb_min); } else if (rgb_max == rgb.g) { hsv.hue = 85 + 43*(rgb.b - rgb.r)/(rgb_max - rgb_min); } else /* rgb_max == rgb.b */ { hsv.hue = 171 + 43*(rgb.r - rgb.g)/(rgb_max - rgb_min); } return hsv; }
void RGBFtoHSV( float r, float g, float b, float *h, float *s, float *v ) { float min, max, delta; min = MIN3( r, g, b ); max = MAX3( r, g, b ); *v = max; // v delta = max - min; if( max != 0 ) *s = delta / max; // s else { // r = g = b = 0 // s = 0, v is undefined *s = 0; *h = -1; return; } if( r == max ) *h = ( g - b ) / delta; // between yellow & magenta else if( g == max ) *h = 2 + ( b - r ) / delta; // between cyan & yellow else *h = 4 + ( r - g ) / delta; // between magenta & cyan *h *= 60; // degrees if( *h < 0 ) *h += 360; }
lapack_logical LAPACKE_dgb_nancheck( int matrix_layout, lapack_int m, lapack_int n, lapack_int kl, lapack_int ku, const double *ab, lapack_int ldab ) { lapack_int i, j; if( ab == NULL ) return (lapack_logical) 0; if( matrix_layout == LAPACK_COL_MAJOR ) { for( j = 0; j < n; j++ ) { for( i = MAX( ku-j, 0 ); i < MIN3( ldab, m+ku-j, kl+ku+1 ); i++ ) { if( LAPACK_DISNAN( ab[i+(size_t)j*ldab] ) ) return (lapack_logical) 1; } } } else if ( matrix_layout == LAPACK_ROW_MAJOR ) { for( j = 0; j < MIN( n, ldab ); j++ ) { for( i = MAX( ku-j, 0 ); i < MIN( m+ku-j, kl+ku+1 ); i++ ) { if( LAPACK_DISNAN( ab[(size_t)i*ldab+j] ) ) return (lapack_logical) 1; } } } return (lapack_logical) 0; }
// See comments on request_old_gen_expansion() bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) { assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); // If eden is not empty, the boundary can be moved but no advantage // can be made of the move since eden cannot be moved. if (!young_gen()->eden_space()->is_empty()) { return false; } bool result = false; const size_t young_gen_available = young_gen()->available_for_expansion(); const size_t old_gen_available = old_gen()->available_for_contraction(); const size_t alignment = virtual_spaces()->alignment(); size_t change_in_bytes = MIN3(young_gen_available, old_gen_available, align_size_up_(expand_in_bytes, alignment)); if (change_in_bytes == 0) { return false; } if (TraceAdaptiveGCBoundary) { gclog_or_tty->print_cr("Before expansion of young gen with boundary move"); gclog_or_tty->print_cr(" Requested change: 0x%zx Attempted change: 0x%zx", expand_in_bytes, change_in_bytes); if (!PrintHeapAtGC) { Universe::print_on(gclog_or_tty); } gclog_or_tty->print_cr(" PSYoungGen max size: " SIZE_FORMAT "K", young_gen()->max_size()/K); } // Move the boundary between the generations down (smaller old gen). MutexLocker x(ExpandHeap_lock); if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) { young_gen()->reset_after_change(); old_gen()->reset_after_change(); result = true; } // The total reserved for the generations should match the sum // of the two even if the boundary is moving. assert(reserved_byte_size() == old_gen()->max_gen_size() + young_gen()->max_size(), "Space is missing"); young_gen()->space_invariants(); old_gen()->space_invariants(); if (TraceAdaptiveGCBoundary) { gclog_or_tty->print_cr("After expansion of young gen with boundary move"); if (!PrintHeapAtGC) { Universe::print_on(gclog_or_tty); } gclog_or_tty->print_cr(" PSYoungGen max size: " SIZE_FORMAT "K", young_gen()->max_size()/K); } return result; }
unsigned int levenshtein ( const char *needle, const char *haystack ) { unsigned int x, y, lastdiag, olddiag; size_t needlelen = g_utf8_strlen ( needle, -1 ); size_t haystacklen = g_utf8_strlen ( haystack, -1 ); unsigned int column[needlelen + 1]; for ( y = 0; y <= needlelen; y++ ) { column[y] = y; } for ( x = 1; x <= haystacklen; x++ ) { const char *needles = needle; column[0] = x; gunichar haystackc = g_utf8_get_char ( haystack ); if ( !config.case_sensitive ) { haystackc = g_unichar_tolower ( haystackc ); } for ( y = 1, lastdiag = x - 1; y <= needlelen; y++ ) { gunichar needlec = g_utf8_get_char ( needles ); if ( !config.case_sensitive ) { needlec = g_unichar_tolower ( needlec ); } olddiag = column[y]; column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( needlec == haystackc ? 0 : 1 ) ); lastdiag = olddiag; needles = g_utf8_next_char ( needles ); } haystack = g_utf8_next_char ( haystack ); } return column[needlelen]; }
/* TODO This function is only used by the fade to random HSV. It might be possible to eliminate */ void rgb_to_hsv(uint8_t red, uint8_t green, uint8_t blue, uint8_t* hue, uint8_t* sat, uint8_t* val) { uint8_t rgb_min, rgb_max; rgb_min = MIN3(red, green, blue); rgb_max = MAX3(red, green, blue); *val = rgb_max; if (*val == 0) { *hue = *sat = 0; return; } *sat = 255*(rgb_max - rgb_min)/ *val; if (*sat == 0) { *hue = 0; return; } /* Compute hue */ if (rgb_max == red) { *hue = 0 + 43*(green - blue)/(rgb_max - rgb_min); } else if (rgb_max == green) { *hue = 85 + 43*(blue - red)/(rgb_max - rgb_min); } else /* rgb_max == rgb.b */ { *hue = 171 + 43*(red - green)/(rgb_max - rgb_min); } }
/// // PointTriangleIntersection() // // Test if 3D point is inside 3D triangle static int PointTriangleIntersection(const vector3& p, const TRI& t) { int sign12,sign23,sign31; vector3 vect12,vect23,vect31,vect1h,vect2h,vect3h; vector3 cross12_1p,cross23_2p,cross31_3p; /// // First, a quick bounding-box test: // If P is outside triangle bbox, there cannot be an intersection. // if (p.x() > MAX3(t.m_P[0].x(), t.m_P[1].x(), t.m_P[2].x())) return(OUTSIDE); if (p.y() > MAX3(t.m_P[0].y(), t.m_P[1].y(), t.m_P[2].y())) return(OUTSIDE); if (p.z() > MAX3(t.m_P[0].z(), t.m_P[1].z(), t.m_P[2].z())) return(OUTSIDE); if (p.x() < MIN3(t.m_P[0].x(), t.m_P[1].x(), t.m_P[2].x())) return(OUTSIDE); if (p.y() < MIN3(t.m_P[0].y(), t.m_P[1].y(), t.m_P[2].y())) return(OUTSIDE); if (p.z() < MIN3(t.m_P[0].z(), t.m_P[1].z(), t.m_P[2].z())) return(OUTSIDE); /// // For each triangle side, make a vector out of it by subtracting vertexes; // make another vector from one vertex to point P. // The crossproduct of these two vectors is orthogonal to both and the // signs of its X,Y,Z components indicate whether P was to the inside or // to the outside of this triangle side. // SUB(t.m_P[0], t.m_P[1], vect12); SUB(t.m_P[0], p, vect1h); CROSS(vect12, vect1h, cross12_1p) sign12 = SIGN3(cross12_1p); /* Extract X,Y,Z signs as 0..7 or 0...63 integer */ SUB(t.m_P[1], t.m_P[2], vect23) SUB(t.m_P[1], p, vect2h); CROSS(vect23, vect2h, cross23_2p) sign23 = SIGN3(cross23_2p); SUB(t.m_P[2], t.m_P[0], vect31) SUB(t.m_P[2], p, vect3h); CROSS(vect31, vect3h, cross31_3p) sign31 = SIGN3(cross31_3p); /// // If all three crossproduct vectors agree in their component signs, / // then the point must be inside all three. // P cannot be OUTSIDE all three sides simultaneously. // return (((sign12 & sign23 & sign31) == 0) ? OUTSIDE : INSIDE); }