 
    
Fichier source : Cohen-Sutherland.cpp
  
Fichier source : Segment2D.cpp
  
/* Abscisse correspondant a une ordonnee        */
    
    double Segment2D::abscisse(double ordonnee) {
      if ( p1->c[0] == p2->c[0] )
        return(p1->c[0]);
      double a = (p1->c[1]-p2->c[1])/(p1->c[0]-p2->c[0]);
      double b = p1->c[1]-a*p1->c[0];
      return((ordonnee-b)/a);
    }
    
    /* Ordonnee correspondant a une abscisse        */
    
    double Segment2D::ordonnee(double abscisse) {
      double a = (p1->c[1]-p2->c[1])/(p1->c[0]-p2->c[0]);
      double b = p1->c[1]-a*p1->c[0];
      return(a*abscisse+b);
    }
    
    /* Clipping de Cohen-Sutherland                 */
    int Segment2D::clip(Rectangle2D *r){
      int c1 = r->code(p1);
      int c2 = r->code(p2);
      while ( ( ( c1 != 0 ) || ( c2 != 0 ) ) &&
              ( (c1&c2) == 0 ) ) {
        if ( c1 == 0 ) {
          { Position2D *aux = p1;
            p1 = p2;
            p2 = aux; }
          { int aux = c1;
            c1 = c2;
            c2 = aux; } }
        if ( (c1&1) != 0 ) {
          p1->c[1] = ordonnee(r->ig->c[0]);
          p1->c[0] = r->ig->c[0]; }
          else
          if ( (c1&2) != 0 ) {
            p1->c[1] = ordonnee(r->sd->c[0]);
            p1->c[0] = r->sd->c[0]; }
            else
            if ( (c1&4) != 0 ) {
              p1->c[0] = abscisse(r->ig->c[1]);
              p1->c[1] = r->ig->c[1]; }
              else {
              p1->c[0] = abscisse(r->sd->c[1]);
              p1->c[1] = r->sd->c[1]; }
        c1 = r->code(p1); }
      return(( c1 == 0 ) && ( c2 == 0 ));
    }
Fichier source : Rectangle2D.h
  
Fichier source : Rectangle2D.cpp
  
/* Code de Cohen-Sutherland d'une Position2D    */
    
    int Rectangle2D::code(Position2D *p) {
      int cd = 0;
      if ( p->c[0] < ig->c[0] )
        cd += 1;
      if ( p->c[0] > sd->c[0] )
        cd += 2;
      if ( p->c[1] < ig->c[1] )
        cd += 4;
      if ( p->c[1] > sd->c[1] )
        cd += 8;
      return(cd);
    }
Fichier source : TraceSegment.h
  
Fichier source : TraceSegment.cpp