// Code from Wikipedia void line(int x0, int y0, int x1, int y1) { char steep = (abs(y1-y0) > abs(x1-x0)) ? 1 : 0; if(steep) { swap(&x0, &y0); swap(&x1, &y1); } if( x0 > x1 ) { swap(&x0, &x1); swap(&y0, &y1); } int deltax = x1 - x0; int deltay = abs(y1-y0); int error = deltax / 2; int ystep; int y = y0; int x; ystep = (y0 < y1) ? 1 : -1; for( x = x0; x <= x1; x++ ) { if(steep) printf("%4d %4d\n", y, x); else printf("%4d %4d\n", x, y); error = error - deltay; if( error < 0 ) { y += ystep; error += deltax; } } }

/* See: l3d_0.4/source/app/lib/raster/ras_sw.cc */ void Rasterizer::drawLine(int x0, int y0, int x1, int y1, unsigned int color) { float fx,fy,m; int x,y,tmp,dx,dy; dx = x1 - x0; dy = y1 - y0; if(abs(dx) > abs(dy)) { //- a "mostly horizontal" line //- ensure (x0,y0) is horizontally smaller than (x1,y1) if(x1<x0) { tmp=x0;x0=x1;x1=tmp; tmp=y0;y0=y1;y1=tmp;} fy = y0; m = (float)dy / (float)dx; for(x=x0; x<=x1; x++) { drawPoint(x, (int)(height, // TODO: Y-reversal? (int) (fy+0.5)), color); fy = fy + m; } } else { //- mostly vertical line //- ensure (x0,y0) is vertically smaller than (x1,y1) if(y1<y0) { tmp=x0;x0=x1;x1=tmp; tmp=y0;y0=y1;y1=tmp;} fx = (float)x0; if( !(float)dy) return; //- degenerate: line is just a point m = (float)dx / (float)dy; for(y=y0; y<=y1; y++) { drawPoint((int)fx+0.5, (int)(height,y), // TODO: Y-reversal? color); fx = fx + m; } } }

kmBool kmAABB3IntersectsAABB(const kmAABB3* box, const kmAABB3* other) { /* Probably should store center point and radius for things like this */ kmScalar acx = (box->min.x + box->max.x) * 0.5; kmScalar acy = (box->min.y + box->max.y) * 0.5; kmScalar acz = (box->min.z + box->max.z) * 0.5; kmScalar bcx = (other->min.x + other->max.x) * 0.5; kmScalar bcy = (other->min.y + other->max.y) * 0.5; kmScalar bcz = (other->min.z + other->max.z) * 0.5; kmScalar arx = (box->max.x - box->min.x) * 0.5; kmScalar ary = (box->max.y - box->min.y) * 0.5; kmScalar arz = (box->max.z - box->min.z) * 0.5; kmScalar brx = (other->max.x - other->min.x) * 0.5; kmScalar bry = (other->max.y - other->min.y) * 0.5; kmScalar brz = (other->max.z - other->min.z) * 0.5; kmBool x = abs(acx - bcx) <= (arx + brx); kmBool y = abs(acy - bcy) <= (ary + bry); kmBool z = abs(acz - bcz) <= (arz + brz); return x && y && z; }

static void pidMultiWii(void) { int axis, prop; int32_t error, errorAngle; int32_t PTerm, ITerm, PTermACC = 0, ITermACC = 0, PTermGYRO = 0, ITermGYRO = 0, DTerm; static int16_t lastGyro[3] = { 0, 0, 0 }; static int32_t delta1[3], delta2[3]; int32_t deltaSum; int32_t delta; // **** PITCH & ROLL & YAW PID **** prop = max(abs(rcCommand[PITCH]), abs(rcCommand[ROLL])); // range [0;500] for (axis = 0; axis < 3; axis++) { if ((f.ANGLE_MODE || f.HORIZON_MODE) && axis < 2) { // MODE relying on ACC // 50 degrees max inclination errorAngle = constrain(2 * rcCommand[axis] + GPS_angle[axis], -((int)mcfg.max_angle_inclination), +mcfg.max_angle_inclination) - angle[axis] + cfg.angleTrim[axis]; PTermACC = errorAngle * cfg.P8[PIDLEVEL] / 100; // 32 bits is needed for calculation: errorAngle*P8[PIDLEVEL] could exceed 32768 16 bits is ok for result PTermACC = constrain(PTermACC, -cfg.D8[PIDLEVEL] * 5, +cfg.D8[PIDLEVEL] * 5); errorAngleI[axis] = constrain(errorAngleI[axis] + errorAngle, -10000, +10000); // WindUp ITermACC = (errorAngleI[axis] * cfg.I8[PIDLEVEL]) >> 12; } if (!f.ANGLE_MODE || f.HORIZON_MODE || axis == 2) { // MODE relying on GYRO or YAW axis error = (int32_t)rcCommand[axis] * 10 * 8 / cfg.P8[axis]; error -= gyroData[axis]; PTermGYRO = rcCommand[axis]; errorGyroI[axis] = constrain(errorGyroI[axis] + error, -16000, +16000); // WindUp if ((abs(gyroData[axis]) > 640) || ((axis == YAW) && (abs(rcCommand[axis]) > 100))) errorGyroI[axis] = 0; ITermGYRO = (errorGyroI[axis] / 125 * cfg.I8[axis]) >> 6; }

int lowestTerm(int number1, int number2) { if (abs(number1) <= abs(number2)) { return number1; } else { return number2; } }

// Test for missing data in genotype // => all genos are equal bool miss_data(double *geno){ if(abs(geno[0] - geno[1]) < EPSILON && abs(geno[1] - geno[2]) < EPSILON) return true; else return false; }

void Rectan::Draw(Graphics* graphics) { Pen myPen(m_Color, m_Width); graphics->DrawRectangle(&myPen, min(m_x1, m_x2), min(m_y1, m_y2), abs(m_x1 - m_x2), abs(m_y1 - m_y2)); SolidBrush myBrush(m_Background_Color); graphics->FillRectangle(&myBrush, min(m_x1, m_x2), min(m_y1, m_y2), abs(m_x1 - m_x2), abs(m_y1 - m_y2)); }

void Mirobot::arc(float angle, float radius){ // Drawing an arc means drawing three concentric circular arcs with two wheels and a pen at the centre // So we need to work out the length of the outer, wheel arcs and then move them by that amount in the same time // To calculate the distance we can work out: // circumference = 2 * pi * radius // distance = circumference * (angle / 360) // combined: // distance = 2 * pi * radius * (angle / 360) // distance = 2 * 3.141593 * radius * (angle / 360) // distance = 6.283185 * radius * (angle / 360) // distance = 0.017453 * radius * angle float right_distance, left_distance; float right_rate, left_rate; int wheel_distance = 120; // extract the sign of the direction (+1 / -1) which will give us the correct distance to turn the steppers char dir = (radius > 0) - (radius < 0); // work out the distances each wheel has to move right_distance = 0.017453 * (radius - (wheel_distance / 2.0)) * angle * dir; left_distance = 0.017453 * (radius + (wheel_distance / 2.0)) * angle * dir; // work out the rate the wheel should move relative to full speed right_rate = abs((right_distance > left_distance) ? 1 : (right_distance / left_distance)); left_rate = abs((right_distance > left_distance) ? (left_distance / right_distance) : 1); // move the wheels takeUpSlack((right_distance > 0), (left_distance < 0)); rightMotor.turn(abs(right_distance) * steps_per_mm * settings.moveCalibration, (right_distance > 0), right_rate); leftMotor.turn(abs(left_distance) * steps_per_mm * settings.moveCalibration, (left_distance < 0), left_rate); wait(); }

static inline moving_speed_t angular_speed_to_ticks( typename protocols::Protocol1::id_t id, double rad_per_s, OperatingMode operating_mode) { // convert radians per second to ticks int32_t speed_ticks = round(60 * rad_per_s / (two_pi * ct_t::rpm_per_tick)); // The actuator is operated as a wheel (continuous rotation) if (operating_mode == OperatingMode::wheel) { // Check that desired speed is within the actuator's bounds if (!(abs(speed_ticks) >= ct_t::min_goal_speed && abs(speed_ticks) <= ct_t::max_goal_speed)) { double min_goal_speed = -ct_t::max_goal_speed * ct_t::rpm_per_tick * two_pi / 60; double max_goal_speed = ct_t::max_goal_speed * ct_t::rpm_per_tick * two_pi / 60; throw errors::ServoLimitError(id, min_goal_speed, max_goal_speed, rad_per_s, "speed (rad/s)"); } // Move negatives values in the range [ct_t::min_goal_speed, // ct_t::2*max_goal_speed+1] if (speed_ticks < 0) { speed_ticks = -speed_ticks + ct_t::max_goal_speed + 1; } } // The actuator is operated as a joint (not continuous rotation) else if (operating_mode == OperatingMode::joint) { if (!(speed_ticks >= ct_t::min_goal_speed && speed_ticks <= ct_t::max_goal_speed)) { double min_goal_speed = ct_t::min_goal_speed * ct_t::rpm_per_tick * two_pi / 60; double max_goal_speed = ct_t::max_goal_speed * ct_t::rpm_per_tick * two_pi / 60; throw errors::ServoLimitError(id, min_goal_speed, max_goal_speed, rad_per_s, "speed (rad/s)"); } } return (moving_speed_t)speed_ticks; }

// sea float sea_octave(vec2 uv, float choppy) { uv += noise(uv); vec2 wv = 1.0-abs(sin(uv)); vec2 swv = abs(cos(uv)); wv = mix(wv,swv,wv); return pow(1.0-pow(wv.x * wv.y,0.65),choppy); }

void Mirobot::initSettings(){ uint16_t eepromOffset = sizeof(MarceauSettings) + 2; EEPROM.begin(sizeof(MarceauSettings) + sizeof(settings)+4); if(EEPROM.read(eepromOffset) == MAGIC_BYTE_1 && EEPROM.read(eepromOffset + 1) == MAGIC_BYTE_2 && EEPROM.read(eepromOffset + 2) == SETTINGS_VERSION){ // We've previously written something valid to the EEPROM for (unsigned int t=0; t<sizeof(settings); t++){ *((char*)&settings + t) = EEPROM.read(eepromOffset + 2 + t); } // Sanity check the values to make sure they look correct if(settings.settingsVersion == SETTINGS_VERSION && settings.slackCalibration < 50 && abs(settings.moveCalibration) > 0.5f && abs(settings.moveCalibration) < 1.5f && abs(settings.turnCalibration) > 0.5f && abs(settings.turnCalibration) < 1.5f){ // The values look OK so let's leave them as they are return; } } // Either this is the first boot or the settings are bad so let's reset them settings.settingsVersion = SETTINGS_VERSION; settings.slackCalibration = 14; settings.moveCalibration = 1.0f; settings.turnCalibration = 1.0f; #ifdef ESP8266 settings.discovery = true; #endif //ESP8266 saveSettings(); }

void NaiveMotionDetector::process_new_frame(const Mat& frame) { if (motion_map_.rows == 0) { motion_map_.create(frame.rows, frame.cols, CV_8UC1); } const uchar* previous_pixels = static_cast<const uchar*>(previous_frame_.data); int cn = previous_frame_.channels(); int cols = previous_frame_.cols; int rows = previous_frame_.rows; const uchar* current_pixels = static_cast<const uchar*>(frame.data); for (int row = 0; row < rows; ++row) { for (int column = 0; column < cols; ++column) { size_t shift = row * cols * cn + column * cn; if (abs(previous_pixels[shift + 0] - current_pixels[shift + 0]) > threshold_ || // Blue abs(previous_pixels[shift + 1] - current_pixels[shift + 1]) > threshold_ || // Green abs(previous_pixels[shift + 2] - current_pixels[shift + 2]) > threshold_) { // Red motion_map_.at<uchar>(row, column) = 255; } else { motion_map_.at<uchar>(row, column) = 0; } } } previous_frame_ = frame.clone(); }

/* bool Collisions::checkCollisionAAB(ObjectBox a, ObjectBox b) { { //check the Y axis if(abs(a.getY() - b.getY()) < a.getSizeY() + b.getSizeY()) { //check the X axis if(abs(a.getX() - b.getX()) < a.getSizeX() + b.getSizeX()) { //check the Z axis if(abs(a.getZ() - b.getZ()) < a.getSizeZ() + b.getSizeZ()) { return true; } } } return false; } }//*/ int Collisions::checkForSelect(float mousePointX, float mousePointY, float shapePointSX, float shapePointSY, float shapePointEX, float shapePointEY) { int i; float centerX = (shapePointSX + shapePointEX) / 2; float centerY = (shapePointSY + shapePointEY) / 2; if (abs((int)mousePointX - shapePointSX) <= radius) { if (abs((int)mousePointY - shapePointSY) <= radius) { return STARTPOINTS; } } if (abs((int)mousePointX - shapePointEX) <= radius) { if (abs((int)mousePointY - shapePointEY) <= radius) { return ENDPOINTS; } } for (i = (-radius); i <= radius; i++) { //first point in line if (((int)mousePointX + i) == (int)shapePointSX)//check X within radius { for (i = (-radius); i <= radius; i++)//check Y within radius { if ((int)(mousePointY + i) == (int)shapePointSY) { return STARTPOINTS; } } } //second point in line if ((int)(mousePointX + i) == (int)shapePointEX)//check X within radius { for (i = (-radius); i <= radius; i++)//check Y within radius { if ((int)(mousePointY + i) == (int)shapePointEY) { return ENDPOINTS; } } } //center point in line if ((int)(mousePointX + i) == (int)centerX)//check X within radius { for (i = (-radius); i <= radius; i++)//check Y within radius { if ((int)(mousePointY + i) == (int)centerY) { return CENTERPOINT; } } } } return 0; }

int main(int argc, char* argv[]) { try { if(!AppInitRPC(argc, argv)) return abs(RPC_MISC_ERROR); } catch (std::exception& e) { PrintExceptionContinue(&e, "AppInitRPC()"); return abs(RPC_MISC_ERROR); } catch (...) { PrintExceptionContinue(NULL, "AppInitRPC()"); return abs(RPC_MISC_ERROR); } int ret = abs(RPC_MISC_ERROR); try { ret = CommandLineRPC(argc, argv); } catch (std::exception& e) { PrintExceptionContinue(&e, "CommandLineRPC()"); } catch (...) { PrintExceptionContinue(NULL, "CommandLineRPC()"); } return ret; }

void turnDeg(int deg, bool direction, int waitTime, int speed){ int distance = convertDegDist(deg); int clicks = convertDistClick(distance); int power = 0; int minimumPower = 40; int targetPower = speed; nMotorEncoder[motor_right] = 0; nMotorEncoder[motor_left] = 0; if(direction == TURN_RIGHT){ while(abs(nMotorEncoder[motor_left]) < abs(clicks) ){//&& abs(nMotorEncoder[motor_right]) < abs(clicks)){ if( abs(nMotorEncoder[motor_left]) < clicks / 2 && power < targetPower ){ power += 1; } if( abs(nMotorEncoder[motor_left]) >= clicks / 1.5 && power > minimumPower ){ power -= 1; } motor [motor_right] = -power; motor [motor_left] = power; } } else{ while(abs(nMotorEncoder[motor_right]) < abs(clicks) ){//&& abs(nMotorEncoder[motor_right]) < abs(clicks)){ if( abs(nMotorEncoder[motor_right]) < clicks / 2 && abs(power) < targetPower ){ power += 1; } if( abs(nMotorEncoder[motor_right]) > clicks / 2 && abs(power) > minimumPower ){ power -= 1; } motor [motor_right] = power; motor [motor_left] = -power; } } stops(); wait1Msec(waitTime); }

int AIHunt(TActor *actor, Vec2i targetPos) { Vec2i fullPos = Vec2iAdd( actor->Pos, GunGetMuzzleOffset(actor->weapon.Gun, actor->direction)); const int dx = abs(targetPos.x - fullPos.x); const int dy = abs(targetPos.y - fullPos.y); int cmd = 0; if (2 * dx > dy) { if (fullPos.x < targetPos.x) cmd |= CMD_RIGHT; else if (fullPos.x > targetPos.x) cmd |= CMD_LEFT; } if (2 * dy > dx) { if (fullPos.y < targetPos.y) cmd |= CMD_DOWN; else if (fullPos.y > targetPos.y) cmd |= CMD_UP; } // If it's a coward, reverse directions... if (actor->flags & FLAGS_RUNS_AWAY) { cmd = AIReverseDirection(cmd); } return cmd; }

int main(void) { int _ar_size; scanf("%d", &_ar_size); int _ar[_ar_size], _ar_i; for(_ar_i = 0; _ar_i < _ar_size; _ar_i++) { scanf("%d", &_ar[_ar_i]); } //swap(&_ar[0],&_ar[_ar_size-1]); quickSort(_ar,0,_ar_size-1,_ar_size); //printArray(_ar,_ar_size); int minDiff=INT_MAX,currentDiff; for(_ar_i=0;_ar_i<_ar_size-1;_ar_i++){ currentDiff=_ar[_ar_i+1]-_ar[_ar_i]; if(abs(currentDiff)<minDiff) minDiff=abs(currentDiff); } //printf("Min Diff is %d",minDiff); for(_ar_i=0;_ar_i<_ar_size-1;_ar_i++){ currentDiff=_ar[_ar_i+1]-_ar[_ar_i]; if(abs(currentDiff)==minDiff) printf("%d %d ",_ar[_ar_i],_ar[_ar_i+1]); } return 0; }

bool ShapeUtils::isRectangle(const ofPolyline &poly, float angle) { if (poly.size() != 4) { return false; } float delta = cos((90 - angle) * PI / 180); // Make sure it's a rectangle ofVec2f top = ofVec2f(poly[1].x - poly[0].x, poly[1].y - poly[0].y); ofVec2f right = ofVec2f(poly[2].x - poly[1].x, poly[2].y - poly[1].y); ofVec2f bottom = ofVec2f(poly[3].x - poly[2].x, poly[3].y - poly[2].y); ofVec2f left = ofVec2f(poly[0].x - poly[3].x, poly[0].y - poly[3].y); top.normalize(); right.normalize(); bottom.normalize(); left.normalize(); bool isRect = abs(top.dot(right)) < delta && abs(right.dot(bottom)) < delta && abs(bottom.dot(left)) < delta && abs(left.dot(top)) < delta; return isRect; }

int checkHold(){ int x0, y0, x1, y1; time_t start; time_t end; static int firstCall = 1; if (firstCall) { firstCall = 0; time(&start); get_cursor(&x0, &y0); return 0; } sched_yield(); get_cursor(&x1, &y1); if ( (abs(x0-x1)+abs(y0-y1)) > 3 ) { x0 = x1; y0 = y1; time(&start); return 0; } time(&end); printf("%lf\n", difftime(end, start) ); if ( difftime(end, start) > 3 ) { time(&start); get_cursor(&x0, &y0); printf("I have got the cursor\n"); return 1; } return 0; }

static void update_viewport(Ihandle* ih, cdCanvas *canvas, float posx, float posy) { int view_x, view_y, view_w, view_h; /* The CD viewport is the same area represented by the virtual space of the scrollbar, but not using the same coordinates. */ /* posy is top-bottom, CD is bottom-top. invert posy reference (YMAX-DY - POSY) */ posy = WORLD_H-IupGetFloat(ih, "DY") - posy; if (posy < 0) posy = 0; if (scale > 0) { view_w = WORLD_W*scale; view_h = WORLD_H*scale; view_x = (int)(posx*scale); view_y = (int)(posy*scale); } else { view_w = WORLD_W/abs(scale); view_h = WORLD_H/abs(scale); view_x = (int)(posx/abs(scale)); view_y = (int)(posy/abs(scale)); } wdCanvasViewport(canvas, -view_x, view_w-1 - view_x, -view_y, view_h-1 - view_y); }

bool GenParticle::PassUserID_FromDY(bool verbose){ if ( Status() != 3 ) return false; int mother_pdg_id = m_collection -> GetData() -> GenParticlePdgId -> at ( MotherIndex() ); if ( abs(mother_pdg_id) != 22 && abs(mother_pdg_id) != 23 ) return false; return true; }

bool backSubstituteSols(BivariatePolynomial * Bp1, BivariatePolynomial * Bp2, ProblemSolver * PS, ofstream & solutionsTxt)//Compute polynomials for computed solutions { int numSols = PS->getNumOfSols(); cout<<"Regular Roots"<<endl; cout<<"--------------"<<endl; for (int i = 0; i < numSols; ++i) { //For every solution Solution * sol = PS->getSolution(i); if(sol->getMultiplicity() == 1) { //if multiplicity of solution is 1 back substitute the sols and check if they nullify the polynomials double res1 = Bp1->backSubstituteXandY(sol->getX(), sol->getY()); //Compute the value of the polynomial Bp1 double res2 = Bp2->backSubstituteXandY(sol->getX(), sol->getY()); //Compute the value of the polynomial Bp2 if(abs(res1) < ERROR_MARGIN && abs(res2) < ERROR_MARGIN) //Are the values over 10^-6 { solutionsTxt << sol->getX() << " " << sol->getY() << " 0"<< endl; cout<<endl<<"SOLUTION : y = "<<sol->getY()<<" x = "<<sol->getX()<<" ACCEPTED"<<endl; } else cout<<endl<<"SOLUTION : y = "<<sol->getY()<<" x = "<<sol->getX()<<" REJECTED : "<<res1<<" , "<<res2<<endl; } else if(sol->getMultiplicity() > 1) { for (int j = 0; j < sol->getLastSet() + 1; ++j) { double res1 = Bp1->backSubstituteXandY(sol->getXat(j), sol->getY()); //Compute the value of the polynomial Bp1 double res2 = Bp2->backSubstituteXandY(sol->getXat(j), sol->getY()); //Compute the value of the polynomial Bp2 if(abs(res1) < ERROR_MARGIN && abs(res2) < ERROR_MARGIN) //Are the values over 10^-6 { solutionsTxt << sol->getXat(j) << " " << sol->getY() << " 0"<< endl; cout<<endl<<"SOLUTION : y = "<<sol->getY()<<" x = "<<sol->getXat(j)<<" ACCEPTED"<<endl; } else cout<<endl<<"SOLUTION : y = "<<sol->getY()<<" x = "<<sol->getXat(j)<<" REJECTED : "<<res1<<" , "<<res2<<endl; } } } }

void drawLine(unsigned char *imgBytes, size_t imgWidth, size_t imgHeight, int x0, int y0, int x1, int y1) { const int deltaX = abs(x0 - x1); const int deltaY = abs(y0 - y1); const int signX = x0 < x1 ? 1 : -1; const int signY = y0 < y1 ? 1 : -1; int error = deltaX - deltaY; int x = x0; int y = y0; while(x != x1 || y != y1) { drawPixel(imgBytes, imgWidth, imgHeight, x, y); const int error2 = error * 2; if(error2 > -deltaY) { error -= deltaY; x += signX; } if(error2 < deltaX) { error += deltaX; y += signY; } } drawPixel(imgBytes, imgWidth, imgHeight, x1, y1); }

int main() { long a,b,c1,c2,r1,r2,i,j,n; scanf("%ld",&n); while(n--) { scanf("%ld %ld",&a,&b); for(i=1; i<=a; i++) { scanf("%ld %ld %ld %ld",&r1,&c1,&r2,&c2); if(r1<=b&&r2<=b&&c1<=b&&c2<=b) { if(r1==r2&&c1==c2) printf("0\n"); else if(abs(r1-r2)==abs(c1-c2)) printf("1\n"); else if((abs(r1-r2)+abs(c1-c2))%2==0) printf("2\n"); else printf("no move\n"); } else printf("no move\n"); } } return 0; }

void print(int n, int d) { int numerator=n; int denominator=d; int divisor = 1; int gooddivisor=1; if(denominator!=0){ int lt = lowestTerm(abs(numerator), abs(denominator)); if ((numerator*denominator)<0) { printf("-"); } numerator=abs(numerator); denominator=abs(denominator); while (divisor <= lt) { if (((numerator % divisor) == 0) && ((denominator % divisor) == 0)) { gooddivisor = divisor; } ++divisor; } numerator/= gooddivisor; denominator/=gooddivisor; printmixedFraction(numerator, denominator);}else{ printf("Divide by zero!"); } }

int Motor::calculatePWR( uint8_t waveform, int t ) { if( t < 0 ) t = 0; else if( t > 100 ) t = 100; switch( waveform ) { // Square default: case 0: t = 100; // not this is divider in break; // Sine case 1: t /= 5; // reduce range to <0 , 20> t -= 10; // move range from <0, 20> to <-10 ,10> t = 10 - (abs( t )); // now range is 0-10-0 t = pgm_read_byte( &halfsineTable[ t ]); break; // Triangle case 2: t -= 50; // move range from <0, 100> to <-50 ,50> t = 100 - (abs( t ) * 2 ); break; // Sawtooth case 3: // return t without changes break; } return t; }

bool GameMainLayer::isCollision(CCPoint pos1, CCPoint pos2, int w1, int h1, int w2, int h2) { if (abs(pos1.x - pos2.x) < w1 + w2 && abs(pos1.y - pos2.y) < h1 + h2) { return true; } return false; }

/*************************************************************************** * Function: bits ***************************************************************************/ static int bits(LONG *chunk, int n) { int size, maxsize, i; for (i = 1, maxsize = abs(chunk[0]); i < n; ++i) maxsize = max(maxsize, abs(chunk[i])); if (maxsize == 0) size = 0; else if (maxsize < 8) size = 4 * n; else if (maxsize < 16) size = 5 * n; else if (maxsize < 32) size = 6 * n; else if (maxsize < 64) size = 7 * n; else if (maxsize < 128) size = 8 * n; else if (maxsize < 65536) size = 16 * n; else size = 32 * n; return(size); }

int threeSumClosest(vector<int>& nums, int target) { sort(nums.begin(), nums.end()); bool first = true; int closest; for (int i = 0; i < nums.size(); i++) { const int t = target - nums[i]; int j = i + 1; int k = nums.size() - 1; while (j < k) { const int sum = nums[i] + nums[j] + nums[k]; if (first || (abs(closest - target) > abs(sum - target))) { closest = sum; first = false; } if (nums[j] + nums[k] < t) { j++; } else if (nums[j] + nums[k] > t) { k--; } else { return sum; } } } return closest; }

static inline void assert_color(skiatest::Reporter* reporter, SkColor expected, SkColor actual, int tolerance) { REPORTER_ASSERT(reporter, abs((int)(SkColorGetA(expected) - SkColorGetA(actual))) <= tolerance); REPORTER_ASSERT(reporter, abs((int)(SkColorGetR(expected) - SkColorGetR(actual))) <= tolerance); REPORTER_ASSERT(reporter, abs((int)(SkColorGetG(expected) - SkColorGetG(actual))) <= tolerance); REPORTER_ASSERT(reporter, abs((int)(SkColorGetB(expected) - SkColorGetB(actual))) <= tolerance); }