broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<=0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0 or q==0 and dx==dy==0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A segment parallel to and lying exactly on a clip boundary is rejected although boundary points are inside.

Each command is [x0,y0,x1,y1,rect] with integer coordinates and an inclusive integer rectangle [left,top,right,bottom] that is first intersected with the pixel-center raster [0,size-1]x[0,size-1]. An empty rectangle returns None. Liang-Barsky tests left, right, top and bottom inequalities with exact rational parameters: parallel segments outside a boundary are rejected, points on a boundary are inside, entering parameters raise t0 and leaving parameters lower t1. The result is [t0,t1] as exact rational strings or None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    else: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Each entering boundary overwrites t0, so a later less restrictive entering plane loosens the start parameter.

Each command is [x0,y0,x1,y1,rect] with integer coordinates and an inclusive integer rectangle [left,top,right,bottom] that is first intersected with the pixel-center raster [0,size-1]x[0,size-1]. An empty rectangle returns None. Liang-Barsky tests left, right, top and bottom inequalities with exact rational parameters: parallel segments outside a boundary are rejected, points on a boundary are inside, entering parameters raise t0 and leaving parameters lower t1. The result is [t0,t1] as exact rational strings or None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,l-x0),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,abs(x0-l)),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The left boundary distance has the wrong sign, so segments starting inside acquire a spurious entering parameter.

Each command is [x0,y0,x1,y1,rect] with integer coordinates and an inclusive integer rectangle [left,top,right,bottom] that is first intersected with the pixel-center raster [0,size-1]x[0,size-1]. An empty rectangle returns None. Liang-Barsky tests left, right, top and bottom inequalities with exact rational parameters: parallel segments outside a boundary are rejected, points on a boundary are inside, entering parameters raise t0 and leaving parameters lower t1. The result is [t0,t1] as exact rational strings or None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q//p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(round(q/p*1000),1000)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Boundary parameters are floor-divided, collapsing fractional intersections to integer parameters.

Each command is [x0,y0,x1,y1,rect] with integer coordinates and an inclusive integer rectangle [left,top,right,bottom] that is first intersected with the pixel-center raster [0,size-1]x[0,size-1]. An empty rectangle returns None. Liang-Barsky tests left, right, top and bottom inequalities with exact rational parameters: parallel segments outside a boundary are rejected, points on a boundary are inside, entering parameters raise t0 and leaving parameters lower t1. The result is [t0,t1] as exact rational strings or None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-x0)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for x0,y0,x1,y1,rect in commands:
        l,t,r,b=max(rect[0],0),max(rect[1],0),min(rect[2],size-1),min(rect[3],size-1)
        if l>r or t>b:
            out.append(None)
            continue
        dx,dy=x1-x0,y1-y0
        t0,t1=Fraction(0),Fraction(1)
        ok=True
        for p,q in ((-dx,x0-l),(dx,r-x0),(-dy,y0-t),(dy,b-y1)):
            if p==0:
                if q<0: ok=False
            else:
                u=Fraction(q,p)
                if p<0:
                    if u>t1: ok=False
                    elif u>t0: t0=u
                else:
                    if u<t0: ok=False
                    elif u<t1: t1=u
        out.append([str(t0),str(t1)] if ok else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[-2, 1, 7, 3, [0, 0, 6, 6]]], 6), [['2/9', '7/9']])
    check('explicit case 1', solve([[1, 1, 11, 1, [0, 0, 11, 11]]], 6), [['0', '2/5']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 6), [None])
    check('explicit case 3', solve([[0, 2, 5, 2, [0, 2, 5, 2]]], 6), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 5, 0, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 5, 5]]], 6), [['1/2', '3/4']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 5, 5]]], 6), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 5, 5]]], 6), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 10, [0, 0, 5, 5]]], 6), [['0', '3/8']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 6]]], 6), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 5, 5]]], 6), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 5, 5]]], 6), [None])
if N == 2:
    check('explicit case 0', solve([[-2, 1, 8, 3, [0, 0, 7, 7]]], 7), [['1/5', '4/5']])
    check('explicit case 1', solve([[1, 1, 12, 1, [0, 0, 12, 12]]], 7), [['0', '5/11']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 7), [None])
    check('explicit case 3', solve([[0, 2, 6, 2, [0, 2, 6, 2]]], 7), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 6, 0, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 6, 6]]], 7), [['1/2', '7/8']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 6, 6]]], 7), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 6, 6]]], 7), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 11, [0, 0, 6, 6]]], 7), [['0', '4/9']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 7]]], 7), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 6, 6]]], 7), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 6, 6]]], 7), [None])
if N == 3:
    check('explicit case 0', solve([[-2, 1, 9, 3, [0, 0, 8, 8]]], 8), [['2/11', '9/11']])
    check('explicit case 1', solve([[1, 1, 13, 1, [0, 0, 13, 13]]], 8), [['0', '1/2']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 8), [None])
    check('explicit case 3', solve([[0, 2, 7, 2, [0, 2, 7, 2]]], 8), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 7, 0, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 7, 7]]], 8), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 7, 7]]], 8), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 7, 7]]], 8), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 12, [0, 0, 7, 7]]], 8), [['0', '1/2']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 8]]], 8), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 7, 7]]], 8), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 7, 7]]], 8), [None])
if N == 4:
    check('explicit case 0', solve([[-2, 1, 10, 3, [0, 0, 9, 9]]], 9), [['1/6', '5/6']])
    check('explicit case 1', solve([[1, 1, 14, 1, [0, 0, 14, 14]]], 9), [['0', '7/13']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 9), [None])
    check('explicit case 3', solve([[0, 2, 8, 2, [0, 2, 8, 2]]], 9), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 8, 0, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 8, 8]]], 9), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 8, 8]]], 9), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 8, 8]]], 9), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 13, [0, 0, 8, 8]]], 9), [['0', '6/11']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 9]]], 9), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 8, 8]]], 9), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 8, 8]]], 9), [None])
if N == 5:
    check('explicit case 0', solve([[-2, 1, 11, 3, [0, 0, 10, 10]]], 10), [['2/13', '11/13']])
    check('explicit case 1', solve([[1, 1, 15, 1, [0, 0, 15, 15]]], 10), [['0', '4/7']])
    check('explicit case 2', solve([[0, 0, 1, 1, [3, 3, 2, 5]]], 10), [None])
    check('explicit case 3', solve([[0, 2, 9, 2, [0, 2, 9, 2]]], 10), [['0', '1']])
    check('explicit case 4', solve([[0, 0, 9, 0, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 5', solve([[0, 2, 0, 2, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 6', solve([[-4, -1, 4, 7, [0, 0, 9, 9]]], 10), [['1/2', '1']])
    check('explicit case 7', solve([[1, 1, 3, 1, [0, 0, 9, 9]]], 10), [['0', '1']])
    check('explicit case 8', solve([[-1, 1, 2, 1, [0, 0, 9, 9]]], 10), [['1/3', '1']])
    check('explicit case 9', solve([[1, 2, 1, 14, [0, 0, 9, 9]]], 10), [['0', '7/12']])
    check('explicit case 10', solve([[2, -3, 5, 5, [1, 1, 4, 10]]], 10), [['1/2', '2/3']])
    check('explicit case 11', solve([[-3, -3, -1, 4, [0, 0, 9, 9]]], 10), [None])
    check('explicit case 12', solve([[-3, -2, 4, -3, [0, 0, 9, 9]]], 10), [None])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The bottom inequality measures from the start x coordinate instead of the start y coordinate.

Each command is [x0,y0,x1,y1,rect] with integer coordinates and an inclusive integer rectangle [left,top,right,bottom] that is first intersected with the pixel-center raster [0,size-1]x[0,size-1]. An empty rectangle returns None. Liang-Barsky tests left, right, top and bottom inequalities with exact rational parameters: parallel segments outside a boundary are rejected, points on a boundary are inside, entering parameters raise t0 and leaving parameters lower t1. The result is [t0,t1] as exact rational strings or None.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def stage(poly,inside,cross):
        res=[]
        for i in range(len(poly)):
            cur=poly[i]
            prev=poly[(i+1)%len(poly)]
            if inside(cur):
                if not inside(prev): res.append(cross(prev,cur))
                res.append(cur)
            elif inside(prev):
                res.append(cross(prev,cur))
        return res
    def at_x(k):
        return lambda p,c: (Fraction(k),p[1]+(c[1]-p[1])*(k-p[0])/(c[0]-p[0]))
    def at_y(k):
        return lambda p,c: (p[0]+(c[0]-p[0])*(k-p[1])/(c[1]-p[1]),Fraction(k))
    out=[]
    for poly in commands:
        src=[(Fraction(x),Fraction(y)) for x,y in poly]
        pts=stage(src,lambda p:p[0]>=0,at_x(0))
        pts=stage(pts,lambda p:p[0]<=size,at_x(size))
        pts=stage(pts,lambda p:p[1]>=0,at_y(0))
        pts=stage(pts,lambda p:p[1]<=size,at_y(size))
        clean=[p for i,p in enumerate(pts) if p!=pts[i-1]]
        if len(clean)<3: clean=[]
        out.append([[str(x),str(y)] for x,y in clean])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[1, 1], [5, 1], [5, 5], [1, 5]]], 6), [[['1', '1'], ['5', '1'], ['5', '5'], ['1', '5']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 6), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [8, 2], [2, 4]]], 6), [[['1', '1'], ['6', '12/7'], ['6', '8/3'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [8, -2], [8, 8], [-2, 8]]], 6), [[['0', '6'], ['0', '0'], ['6', '0'], ['6', '6']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 6), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 6), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 6), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 6), [[]])
    check('explicit case 8', solve([[[1, 1], [7, 1], [1, 9]]], 6), [[['1', '6'], ['1', '1'], ['6', '1'], ['6', '7/3'], ['13/4', '6']]])
    check('explicit case 9', solve([[['1/2', 2], [6, 2], [6, 5]]], 6), [[['1/2', '2'], ['6', '2'], ['6', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 6), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [8, 3], [6, 4], [5, 1]]], 6), [[['3', '1'], ['6', '11/5'], ['6', '4'], ['5', '1']]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [6, 6], [1, 6]]], 7), [[['1', '1'], ['6', '1'], ['6', '6'], ['1', '6']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 7), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [9, 2], [2, 4]]], 7), [[['1', '1'], ['7', '7/4'], ['7', '18/7'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [9, -2], [9, 9], [-2, 9]]], 7), [[['0', '7'], ['0', '0'], ['7', '0'], ['7', '7']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 7), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 7), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 7), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 7), [[]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [1, 10]]], 7), [[['1', '7'], ['1', '1'], ['7', '1'], ['7', '16/7'], ['10/3', '7']]])
    check('explicit case 9', solve([[['1/2', 2], [7, 2], [7, 5]]], 7), [[['1/2', '2'], ['7', '2'], ['7', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 7), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [9, 3], [7, 4], [6, 1]]], 7), [[['3', '1'], ['7', '7/3'], ['7', '4'], ['6', '1']]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [7, 7], [1, 7]]], 8), [[['1', '1'], ['7', '1'], ['7', '7'], ['1', '7']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 8), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [10, 2], [2, 4]]], 8), [[['1', '1'], ['8', '16/9'], ['8', '5/2'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [10, -2], [10, 10], [-2, 10]]], 8), [[['0', '8'], ['0', '0'], ['8', '0'], ['8', '8']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 8), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 8), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 8), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 8), [[]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [1, 11]]], 8), [[['1', '8'], ['1', '1'], ['8', '1'], ['8', '9/4'], ['17/5', '8']]])
    check('explicit case 9', solve([[['1/2', 2], [8, 2], [8, 5]]], 8), [[['1/2', '2'], ['8', '2'], ['8', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 8), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [10, 3], [8, 4], [7, 1]]], 8), [[['3', '1'], ['8', '17/7'], ['8', '4'], ['7', '1']]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [8, 8], [1, 8]]], 9), [[['1', '1'], ['8', '1'], ['8', '8'], ['1', '8']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 9), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [11, 2], [2, 4]]], 9), [[['1', '1'], ['9', '9/5'], ['9', '22/9'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [11, -2], [11, 11], [-2, 11]]], 9), [[['0', '9'], ['0', '0'], ['9', '0'], ['9', '9']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 9), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 9), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 9), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 9), [[]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [1, 12]]], 9), [[['1', '9'], ['1', '1'], ['9', '1'], ['9', '20/9'], ['38/11', '9']]])
    check('explicit case 9', solve([[['1/2', 2], [9, 2], [9, 5]]], 9), [[['1/2', '2'], ['9', '2'], ['9', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 9), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [11, 3], [9, 4], [8, 1]]], 9), [[['3', '1'], ['9', '5/2'], ['9', '4'], ['8', '1']]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [9, 9], [1, 9]]], 10), [[['1', '1'], ['9', '1'], ['9', '9'], ['1', '9']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 10), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [12, 2], [2, 4]]], 10), [[['1', '1'], ['10', '20/11'], ['10', '12/5'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [12, -2], [12, 12], [-2, 12]]], 10), [[['0', '10'], ['0', '0'], ['10', '0'], ['10', '10']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 10), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 10), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 10), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 10), [[]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [1, 13]]], 10), [[['1', '10'], ['1', '1'], ['10', '1'], ['10', '11/5'], ['7/2', '10']]])
    check('explicit case 9', solve([[['1/2', 2], [10, 2], [10, 5]]], 10), [[['1/2', '2'], ['10', '2'], ['10', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 10), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [12, 3], [10, 4], [9, 1]]], 10), [[['3', '1'], ['10', '23/9'], ['10', '4'], ['9', '1']]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def stage(poly,inside,cross):
        res=[]
        for i in range(len(poly)):
            cur=poly[i]
            prev=poly[i-1] if i else cur
            if inside(cur):
                if not inside(prev): res.append(cross(prev,cur))
                res.append(cur)
            elif inside(prev):
                res.append(cross(prev,cur))
        return res
    def at_x(k):
        return lambda p,c: (Fraction(k),p[1]+(c[1]-p[1])*(k-p[0])/(c[0]-p[0]))
    def at_y(k):
        return lambda p,c: (p[0]+(c[0]-p[0])*(k-p[1])/(c[1]-p[1]),Fraction(k))
    out=[]
    for poly in commands:
        src=[(Fraction(x),Fraction(y)) for x,y in poly]
        pts=stage(src,lambda p:p[0]>=0,at_x(0))
        pts=stage(pts,lambda p:p[0]<=size,at_x(size))
        pts=stage(pts,lambda p:p[1]>=0,at_y(0))
        pts=stage(pts,lambda p:p[1]<=size,at_y(size))
        clean=[p for i,p in enumerate(pts) if p!=pts[i-1]]
        if len(clean)<3: clean=[]
        out.append([[str(x),str(y)] for x,y in clean])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[1, 1], [5, 1], [5, 5], [1, 5]]], 6), [[['1', '1'], ['5', '1'], ['5', '5'], ['1', '5']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 6), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [8, 2], [2, 4]]], 6), [[['1', '1'], ['6', '12/7'], ['6', '8/3'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [8, -2], [8, 8], [-2, 8]]], 6), [[['0', '6'], ['0', '0'], ['6', '0'], ['6', '6']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 6), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 6), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 6), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 6), [[]])
    check('explicit case 8', solve([[[1, 1], [7, 1], [1, 9]]], 6), [[['1', '6'], ['1', '1'], ['6', '1'], ['6', '7/3'], ['13/4', '6']]])
    check('explicit case 9', solve([[['1/2', 2], [6, 2], [6, 5]]], 6), [[['1/2', '2'], ['6', '2'], ['6', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 6), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [8, 3], [6, 4], [5, 1]]], 6), [[['3', '1'], ['6', '11/5'], ['6', '4'], ['5', '1']]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [6, 6], [1, 6]]], 7), [[['1', '1'], ['6', '1'], ['6', '6'], ['1', '6']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 7), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [9, 2], [2, 4]]], 7), [[['1', '1'], ['7', '7/4'], ['7', '18/7'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [9, -2], [9, 9], [-2, 9]]], 7), [[['0', '7'], ['0', '0'], ['7', '0'], ['7', '7']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 7), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 7), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 7), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 7), [[]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [1, 10]]], 7), [[['1', '7'], ['1', '1'], ['7', '1'], ['7', '16/7'], ['10/3', '7']]])
    check('explicit case 9', solve([[['1/2', 2], [7, 2], [7, 5]]], 7), [[['1/2', '2'], ['7', '2'], ['7', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 7), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [9, 3], [7, 4], [6, 1]]], 7), [[['3', '1'], ['7', '7/3'], ['7', '4'], ['6', '1']]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [7, 7], [1, 7]]], 8), [[['1', '1'], ['7', '1'], ['7', '7'], ['1', '7']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 8), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [10, 2], [2, 4]]], 8), [[['1', '1'], ['8', '16/9'], ['8', '5/2'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [10, -2], [10, 10], [-2, 10]]], 8), [[['0', '8'], ['0', '0'], ['8', '0'], ['8', '8']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 8), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 8), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 8), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 8), [[]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [1, 11]]], 8), [[['1', '8'], ['1', '1'], ['8', '1'], ['8', '9/4'], ['17/5', '8']]])
    check('explicit case 9', solve([[['1/2', 2], [8, 2], [8, 5]]], 8), [[['1/2', '2'], ['8', '2'], ['8', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 8), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [10, 3], [8, 4], [7, 1]]], 8), [[['3', '1'], ['8', '17/7'], ['8', '4'], ['7', '1']]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [8, 8], [1, 8]]], 9), [[['1', '1'], ['8', '1'], ['8', '8'], ['1', '8']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 9), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [11, 2], [2, 4]]], 9), [[['1', '1'], ['9', '9/5'], ['9', '22/9'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [11, -2], [11, 11], [-2, 11]]], 9), [[['0', '9'], ['0', '0'], ['9', '0'], ['9', '9']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 9), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 9), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 9), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 9), [[]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [1, 12]]], 9), [[['1', '9'], ['1', '1'], ['9', '1'], ['9', '20/9'], ['38/11', '9']]])
    check('explicit case 9', solve([[['1/2', 2], [9, 2], [9, 5]]], 9), [[['1/2', '2'], ['9', '2'], ['9', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 9), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [11, 3], [9, 4], [8, 1]]], 9), [[['3', '1'], ['9', '5/2'], ['9', '4'], ['8', '1']]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [9, 9], [1, 9]]], 10), [[['1', '1'], ['9', '1'], ['9', '9'], ['1', '9']]])
    check('explicit case 1', solve([[[-2, 1], [3, 1], [3, 4]]], 10), [[['0', '11/5'], ['0', '1'], ['3', '1'], ['3', '4']]])
    check('explicit case 2', solve([[[1, 1], [12, 2], [2, 4]]], 10), [[['1', '1'], ['10', '20/11'], ['10', '12/5'], ['2', '4']]])
    check('explicit case 3', solve([[[-2, -2], [12, -2], [12, 12], [-2, 12]]], 10), [[['0', '10'], ['0', '0'], ['10', '0'], ['10', '10']]])
    check('explicit case 4', solve([[[2, -3], [4, 2], [1, 3]]], 10), [[['3/2', '0'], ['16/5', '0'], ['4', '2'], ['1', '3']]])
    check('explicit case 5', solve([[[-3, 1], [-1, 1], [-2, 3]]], 10), [[]])
    check('explicit case 6', solve([[[0, 1], [0, 3], [-2, 2]]], 10), [[]])
    check('explicit case 7', solve([[[0, 0], [-1, -2], [-2, -1]]], 10), [[]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [1, 13]]], 10), [[['1', '10'], ['1', '1'], ['10', '1'], ['10', '11/5'], ['7/2', '10']]])
    check('explicit case 9', solve([[['1/2', 2], [10, 2], [10, 5]]], 10), [[['1/2', '2'], ['10', '2'], ['10', '5']]])
    check('explicit case 10', solve([[[-2, 2], [2, 1], [0, 3]]], 10), [[['0', '3/2'], ['2', '1'], ['0', '3']]])
    check('explicit case 11', solve([[[3, 1], [12, 3], [10, 4], [9, 1]]], 10), [[['3', '1'], ['10', '23/9'], ['10', '4'], ['9', '1']]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Each stage pairs a vertex with its successor instead of its predecessor, emitting intersections in reversed edge order.

Each command is a polygon vertex list with exact coordinates. It is clipped in continuous raster coordinates against x>=0, x<=size, y>=0 and y<=size in that order with Sutherland-Hodgman: each stage walks edges from the previous vertex to the current vertex, emits the boundary intersection when entering before the inside vertex, emits the intersection when leaving, and chains its output into the next stage. Boundary points are inside. Cyclically repeated consecutive vertices are then removed; fewer than three remaining vertices yields an empty polygon. Vertices are returned as exact rational strings.

split: open-access