📄 outcode2.c
字号:
/* Direct calculation of 2D outcodes, C code fragment *//* number of bits in a word */#define NUMBITS sizeof(long)*8/* get the integral form of a floating point number */#define v(x) *(long *) &(x)/* get the sign bit of an integer as a value 0 or 1 */#define s(x) (((unsigned long)(x)) >> (NUMBITS-1))/* get the absolute value of a floating point number in integral form */#define a(x) ((x) & ~(1 << (NUMBITS-1))) /* these values typically would be calculated once and cached */ ixmin = v(xmin); ixmax = v(xmax); iymin = v(ymin); iymax = v(ymax); /* get the bits and absolute value */ ix = v(x); ax = a(ix); /* put the sign bit in bit 0 */ outcode = s(ix | (ax - ixmin)); /* put the sign bit in bit 1 */ outcode |= s(~ix & (ixmax - ax)) << 1; /* do the same for y */ iy = v(y); ay = a(iy); outcode |= s(iy | (ay - iymin)) << 2; outcode |= s(~iy & (iymax - ay)) << 3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -