G
Gr
I am not an expert C or C++ programmer but know enough to get by.
Currently studying some graphics algorithms as a part of CAD.
In the Cohen Sutherland Algorithm of line clipping, a code/flag is using
for denoting where an endpoint of the line lies as compared to the
clipping rectangle.
This code consists of 4 flags (1 each for left, right, below & above).
type code = 0;
if(point lies to the left of clipping window)
code = code & 1;
if(point lies to right)
code = code & 2;
if(point lies below)
code = code & 4;
if(point lies above)
code = code & 8;
Now in some books the type of code is declared
as
unsigned char code;
In others, it's
int code;
which is better?
unsigned char code saves space
(is the unsigned really necessary anyway?)
but I think int is probably faster.
Can someone explain what's a better way to do this if you were
writing a graphics library?
Currently studying some graphics algorithms as a part of CAD.
In the Cohen Sutherland Algorithm of line clipping, a code/flag is using
for denoting where an endpoint of the line lies as compared to the
clipping rectangle.
This code consists of 4 flags (1 each for left, right, below & above).
type code = 0;
if(point lies to the left of clipping window)
code = code & 1;
if(point lies to right)
code = code & 2;
if(point lies below)
code = code & 4;
if(point lies above)
code = code & 8;
Now in some books the type of code is declared
as
unsigned char code;
In others, it's
int code;
which is better?
unsigned char code saves space
(is the unsigned really necessary anyway?)
but I think int is probably faster.
Can someone explain what's a better way to do this if you were
writing a graphics library?