/* Rectangle en 2D */ /* */ /* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Novembre 2012 */ #include #include #include #include #include #include #include "Rectangle2D.h" #include "Position2D.h" #include "TraceSegment.h" /* Constructeurs */ Rectangle2D::Rectangle2D(void) { ig = new Position2D(); sd = new Position2D(); } Rectangle2D::Rectangle2D(Position2D *p1,Position2D *p2) { this->ig = new Position2D(min(p1->c[0],p2->c[0]),min(p1->c[1],p2->c[1])); this->sd = new Position2D(max(p1->c[0],p2->c[0]),max(p1->c[1],p2->c[1])); } Rectangle2D::Rectangle2D(Rectangle2D *r) { ig = new Position2D(r->ig); sd = new Position2D(r->sd); } /* Destructeur */ Rectangle2D::~Rectangle2D(void) { delete(sd); delete(ig); } /* Dessin OpenGL */ void Rectangle2D::draw(void) { trace(ig->c[0],ig->c[1],ig->c[0],sd->c[1]); trace(ig->c[0],ig->c[1],sd->c[0],ig->c[1]); trace(sd->c[0],sd->c[1],ig->c[0],sd->c[1]); trace(sd->c[0],sd->c[1],sd->c[0],ig->c[1]); } ////////////////////////////////////////////////// /* 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); } //////////////////////////////////////////////////