main() { // open in both input and append mode // ios is preStandard class name // fstream inOut( "moby_dick.copy", ios_base::in|ios_base::app ); fstream inOut( "moby_dick.copy", ios::in|ios::app ); if ( ! inOut ) { cerr << "oops! unable to open file ``copy.out''\n"; return -1; } int cnt = 0; // byte count char ch; while ( inOut.get( ch )) { cout.put( ch ); // echo on terminal ++cnt; if ( ch == '\n' ) { inOut << cnt ; inOut.put( ' ' ); // blank space } } // write out final byte count inOut << cnt << endl; cout << "[ " << cnt << " ]" << endl; return 0; }
void Design::animate(int type){ switch(type){ case 1: inOut(2); break; case 2: outIn(2); break; case 3: //blink on(); delay(50); off(); delay(100); on(); delay(50); off(); break; case 4: //wave on(1); delay(50); on(2); off(1); delay(50); on(3); off(2); delay(50); on(4); off(3); delay(50); on(5); off(4); delay(50); on(6); off(5); delay(50); off(6); break; } }
float Terrain::potentiel(const glm::vec3& p) const { return inOut(p) ? 1.f : 0.f; }
static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, int m, Point2f* result, float* _area ) { Point2f* result0 = result; // P has n vertices, Q has m vertices. int a=0, b=0; // indices on P and Q (resp.) Point2f Origin(0,0); tInFlag inflag=Unknown; // {Pin, Qin, Unknown}: which inside int aa=0, ba=0; // # advances on a & b indices (after 1st inter.) bool FirstPoint=true;// Is this the first point? (used to initialize). Point2f p0; // The first point. *result++ = Point2f(FLT_MAX, FLT_MAX); do { // Computations of key variables. int a1 = (a + n - 1) % n; // a-1, b-1 (resp.) int b1 = (b + m - 1) % m; Point2f A = P[a] - P[a1], B = Q[b] - Q[b1]; // directed edges on P and Q (resp.) int cross = areaSign( Origin, A, B ); // sign of z-component of A x B int aHB = areaSign( Q[b1], Q[b], P[a] ); // a in H(b). int bHA = areaSign( P[a1], P[a], Q[b] ); // b in H(A); // If A & B intersect, update inflag. Point2f p, q; int code = segSegInt( P[a1], P[a], Q[b1], Q[b], p, q ); if( code == '1' || code == 'v' ) { if( inflag == Unknown && FirstPoint ) { aa = ba = 0; FirstPoint = false; p0 = p; *result++ = p; } inflag = inOut( p, inflag, aHB, bHA, result ); } //-----Advance rules----- // Special case: A & B overlap and oppositely oriented. if( code == 'e' && A.ddot(B) < 0 ) { addSharedSeg( p, q, result ); return (int)(result - result0); } // Special case: A & B parallel and separated. if( cross == 0 && aHB < 0 && bHA < 0 ) return (int)(result - result0); // Special case: A & B collinear. else if ( cross == 0 && aHB == 0 && bHA == 0 ) { // Advance but do not output point. if ( inflag == Pin ) b = advance( b, &ba, m, inflag == Qin, Q[b], result ); else a = advance( a, &aa, n, inflag == Pin, P[a], result ); } // Generic cases. else if( cross >= 0 ) { if( bHA > 0) a = advance( a, &aa, n, inflag == Pin, P[a], result ); else b = advance( b, &ba, m, inflag == Qin, Q[b], result ); } else { if( aHB > 0) b = advance( b, &ba, m, inflag == Qin, Q[b], result ); else a = advance( a, &aa, n, inflag == Pin, P[a], result ); } // Quit when both adv. indices have cycled, or one has cycled twice. } while ( ((aa < n) || (ba < m)) && (aa < 2*n) && (ba < 2*m) ); // Deal with special cases: not implemented. if( inflag == Unknown ) { // The boundaries of P and Q do not cross. // ... } int i, nr = (int)(result - result0); double area = 0; Point2f prev = result0[nr-1]; for( i = 1; i < nr; i++ ) { result0[i-1] = result0[i]; area += (double)prev.x*result0[i].y - (double)prev.y*result0[i].x; prev = result0[i]; } *_area = (float)(area*0.5); if( result0[nr-2] == result0[0] && nr > 1 ) nr--; return nr-1; }
float CSG_Primitive::potentiel(const Vector3D& p) const { return inOut(p) ? 1.f : 0.f; }
InOut<T> inOut(InOut<T>& i) { return inOut(i.get()); }