/* * Returns the index of the biggest rectangle of color id pcolorid * Returns -1 if no rectangle of color id pcolorid is found, or all * rectangle are strictly smaller than pminarea. */ int getbiggestrect(int pcolorid, int pminarea) { int rectindex = -1; int i; int maxarea = pminarea; for (i = 0; i < nxtcamdata[0]; i++) { int colorid = (int) nxtcamdata[1 + 5 * i + 0]; if (colorid == pcolorid) { int xul = (int) nxtcamdata[1 + 5 * i + 1]; int yul = (int) nxtcamdata[1 + 5 * i + 2]; int xlr = (int) nxtcamdata[1 + 5 * i + 3]; int ylr = (int) nxtcamdata[1 + 5 * i + 4]; // int w = ABS(xlr - xul); // int h = ABS(ylr - yul); int w = MYABS(xlr - xul); int h = MYABS(ylr - yul); int area = w * h; if (area >= maxarea) { maxarea = area; rectindex = i; } } } return rectindex; }
static Bool CHECK_isDrg(MNT_BERTH * pMntBerth) { long diff_lon; long diff_lat; float r = 0.0; //INFO("DRG check"); if(pMntBerth->pBoat == NULL || pMntBerth->pBoat->dist > 100000) { return FALSE; } diff_lon = pMntBerth->pBoat->longitude - pMntBerth->mntBoat.lg; diff_lat = pMntBerth->pBoat->latitude - pMntBerth->mntBoat.lt; diff_lon = MYABS(diff_lon); diff_lat = MYABS(diff_lat); /// 先判断是否在走锚报警区域的内切正方形内,若是就不必勾股了,不是的话再老老实实sqrt吧。 if( diff_lon + 2*diff_lon/5 > pMntBerth->mntBoat.mntSetting.DRG_Setting.Dist ||diff_lat + 2*diff_lat/5 > pMntBerth->mntBoat.mntSetting.DRG_Setting.Dist) { r = sqrt(diff_lon*diff_lon + diff_lat*diff_lat); } if(r > pMntBerth->mntBoat.mntSetting.DRG_Setting.Dist) { return TRUE; } else { return FALSE; } }
int CompDbl( double n1, double n2 ) { double num; if( MYABS( n1 ) < 0.000001 && MYABS( n2 ) < 0.000001 ) return( TRUE ); if( n1 == 0.0 || n2 == 0.0 ) { return( FALSE ); } else { num = ( n1 - n2 ) / ( n1 < n2 ? n1 : n2 ); if( MYABS( num ) > 0.0001 ) return( FALSE ); } return( TRUE ); }
int tang(int argc, char * argv[]) { double x; unsigned int n,i; char * err; if (argc >5) { fprintf(stderr, "ERROR bolo zadanych vela argumentov pre funkciu --tan \n");// ak je zadanych viac argumentov ako je dane pre funkciu vypise chybu return EXIT_FAILURE; } x = strtod(argv[2],&err); //osterenie chybneho vstupu if (err == argv[2]) { fprintf(stderr,"ERROR zaddana zla hodnota\n"); return EXIT_FAILURE; } n = atoi(argv[4]); //posledny prvok rozsahu i= atoi(argv[3]);// prvy prvok rozsahu if (x>1.4) { fprintf(stderr, "ERROR zadany zly rozsah parametrov\n");// ak je zadany zly rozsah parametrov tak vypise chybove hlasenie return EXIT_FAILURE; } if (i>n || n >14) { fprintf(stderr, "ERROR zadany zly rozsah\n"); // ak je zadany zly rozsah tak vypise chybove hlasenie return EXIT_FAILURE; } for(;i<=n;i++) printf ("%d %e %e %e %e %e\n",i , tan(x), taylor_tan(x,i-1), MYABS(tan(x) - taylor_tan(x,i-1) ) , cfrac_tan(x,i),MYABS((tan(x) - cfrac_tan(x,i)) )); // vypis funkcie --tan return EXIT_SUCCESS; }
static Bool CHECK_isBgl(MNT_BERTH * pMntBerth) { int i ; //INFO("BGL check"); if(pMntBerth->pBoat == NULL || pMntBerth->pBoat->dist > 100000) { return FALSE; } for(i=N_boat-1; i>=0; i--) { if(SimpBerthes[i].pBerth->mntState == MNTState_None) { /// Is invader if( (MYABS(SimpBerthes[i].longitude - pMntBerth->pBoat->longitude) <= pMntBerth->mntBoat.mntSetting.BGL_Setting.Dist) &&(MYABS(SimpBerthes[i].latitude - pMntBerth->pBoat->latitude) <= pMntBerth->mntBoat.mntSetting.BGL_Setting.Dist)) { INFO("find invader"); if(INVD_add(pMntBerth-MNT_Berthes, SimpBerthes[i].pBerth)) SimpBerthes[i].pBerth->isInvader = pMntBerth->mntBoat.mmsi; } /// Is not invader but has been.So remove it from black list. else if(SimpBerthes[i].pBerth->isInvader == pMntBerth->mntBoat.mmsi) { INFO("black -> white"); INVD_delete(pMntBerth-MNT_Berthes, SimpBerthes[i].pBerth); SimpBerthes[i].pBerth->isInvader = 0; } } } INVD_printf(); if(INVD_isAllMasked(pMntBerth-MNT_Berthes) == FALSE) { return TRUE; } else { return FALSE; } }
double mycos(double x) { double s = 1.0; double ti = s; double k = 1.0; x = -x*x; while (MYABS(ti) > 0) { ti = ti * x / ((k+1)*k); k = k + 2.0; s = s + ti; } return s; }
/* * Returns the height of the rectangle of index rectindex. */ int getHeight(U8 rectindex) { int yul = (int) nxtcamdata[5 * rectindex + 1 + 2]; int ylr = (int) nxtcamdata[5 * rectindex + 1 + 4]; return MYABS(ylr - yul); }
/* * Returns the width of the rectangle of index rectindex. */ int getWidth(U8 rectindex) { int xul = (int) nxtcamdata[5 * rectindex + 1 + 1]; int xlr = (int) nxtcamdata[5 * rectindex + 1 + 3]; return MYABS(xlr - xul); }