Good day, I came across the following code, I do not quite understand what it does. The program is about the intersection of lines.

enum { TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8 }; void cut(float x0,float y0,float x1,float y1){ int outcode0,outcode1,outcodeOut; if(outcodeOut==outcode0){ x0 = x; y0 = y; outcode0 = CompOutCode(x0,y0); } else{ x1 = x; y1 = y; outcode1 = CompOutCode(x1,y1); } } int CompOutCode(float x,float y){ int code = 0; if(y>ymax) code|=TOP; else if(y<ymin) code|=BOTTOM; if(x>xmax) code|=RIGHT; else if(x<xmin) code|=LEFT; return code; 
  • Do not stumble on the code, write your own. - MihailPw
  • Just wondering what the CompOutCode function is for. - nivok
  • one
    Go through each line and see for yourself. - MihailPw
  • Sets and returns bit flags, based on the position of the point relative to the rectangle (xmin, ymin) - (xmax, ymax) . - ߊߚߤߘ

1 answer 1

The CompOutCode function implements the restriction of moving an object within specified limits.