Cohen–Sutherland clipping algorithm clips a line from P0 = (x0, y0) to P1 = (x1, y1) against a rectangle with diagonal from (xmin, ymin) to (xmax, ymax).
Returns true if the line segment is intersecting with the rectangle, false otherwise.
46 if (!(outcode0 | outcode1)) {
49 }
else if (outcode0 & outcode1) {
57 OutCode outcodeOut = outcode0 ? outcode0 : outcode1;
61 if (outcodeOut &
TOP) {
62 x = x0 + (x1 - x0) * (ymax - y0) / (y1 - y0);
64 }
else if (outcodeOut &
BOTTOM) {
65 x = x0 + (x1 - x0) * (ymin - y0) / (y1 - y0);
67 }
else if (outcodeOut &
RIGHT) {
68 y = y0 + (y1 - y0) * (xmax - x0) / (x1 - x0);
70 }
else if (outcodeOut &
LEFT) {
71 y = y0 + (y1 - y0) * (xmin - x0) / (x1 - x0);
77 if (outcodeOut == outcode0) {
static const int LEFT
Definition: InstrumentUtil.h:26
static const int RIGHT
Definition: InstrumentUtil.h:27
int OutCode
Definition: InstrumentUtil.h:23
static const int BOTTOM
Definition: InstrumentUtil.h:28
static const int TOP
Definition: InstrumentUtil.h:29
static OutCode ComputeOutCode(double x, double y, double xmin, double xmax, double ymin, double ymax)
Definition: InstrumentUtil.cc:20