Encode which side of a clipping rectangle each segment endpoint lies
on.
Example
Encode which side of the viewport each endpoint lies on.
highlighted = computed this step
Step 1 — Set up
Set up the exact input values.
rect and segment({’xmin’: Fraction(1, 1), ’xmax’: Fraction(5, 1), ’ymin’: Fraction(1, 1), ’ymax’: Fraction(4, 1)}, (0, 5), (6, 2))
Step 2 — Endpoint A
Compute the highlighted value.
A outcode1001
Step 3 — Endpoint B
Compute the highlighted value.
B outcode0010
Step 4 — Result
State the structural verdict.
OR, AND, verdict(1011, 0000, clip)
cohen-sutherland-outcodesAn outcode records top, bottom, right, and left tests as bits, making trivial accept, trivial reject, and clipping cases structural.