broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.floor(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 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([[[1, 1], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', 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
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.floor(max(xs))+1,size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 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([[[1, 1], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', 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 exclusive right bound floors the maximum x, dropping the final partially covered column.

Each command is a triangle of three exact vertices in continuous raster coordinates. The viewport is [0,size]x[0,size] and the guard band extends one viewport size beyond each side. A triangle is rejected when all vertices lie strictly beyond the same viewport edge; accepted when all vertices are inside the closed viewport; guard-banded when all vertices are inside the closed guard band; otherwise it requires geometric clipping. Accepted and guard-banded triangles report the pixel bounding box [floor(min x),floor(min y),ceil(max x),ceil(max y)) clamped to the viewport, or None if empty.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=math.floor(min(xs))
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 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([[[1, 1], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', 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
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0) if kind=='accept' else math.floor(min(xs))
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 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([[[1, 1], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', 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:
Guard-band triangles report bounding boxes starting left of the viewport.

Each command is a triangle of three exact vertices in continuous raster coordinates. The viewport is [0,size]x[0,size] and the guard band extends one viewport size beyond each side. A triangle is rejected when all vertices lie strictly beyond the same viewport edge; accepted when all vertices are inside the closed viewport; guard-banded when all vertices are inside the closed guard band; otherwise it requires geometric clipping. Accepted and guard-banded triangles report the pixel bounding box [floor(min x),floor(min y),ceil(max x),ceil(max y)) clamped to the viewport, or None if empty.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=0
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 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([[[1, 1], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', 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
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size//2
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 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([[[1, 1], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', 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 zero-width guard band sends every triangle that extends past the viewport to geometric clipping.

Each command is a triangle of three exact vertices in continuous raster coordinates. The viewport is [0,size]x[0,size] and the guard band extends one viewport size beyond each side. A triangle is rejected when all vertices lie strictly beyond the same viewport edge; accepted when all vertices are inside the closed viewport; guard-banded when all vertices are inside the closed guard band; otherwise it requires geometric clipping. Accepted and guard-banded triangles report the pixel bounding box [floor(min x),floor(min y),ceil(max x),ceil(max y)) clamped to the viewport, or None if empty.

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 seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    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], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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 seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1][1]==a[1]:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    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], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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 part that re-enters the window at a different point is appended to the previous piece, drawing a false connector along the boundary.

Each command is [points,closed]. Consecutive vertices (plus the closing edge when closed and at least three points) are clipped against the closed pixel-center window [0,size-1]x[0,size-1] with exact parametric clipping. Visible parts that start where the current piece ends extend it (skipping zero-length repeats); any other visible part starts a new piece; a fully rejected edge ends the current piece. For closed paths, a last piece ending where the first piece begins is merged in front of it without repeating the joint. Pieces with fewer than two vertices are dropped. Vertices are exact rational strings.

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 seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                current.extend([a,b])
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    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], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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 seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    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], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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:
Continuing a piece appends the shared joint again, duplicating every interior vertex.

Each command is [points,closed]. Consecutive vertices (plus the closing edge when closed and at least three points) are clipped against the closed pixel-center window [0,size-1]x[0,size-1] with exact parametric clipping. Visible parts that start where the current piece ends extend it (skipping zero-length repeats); any other visible part starts a new piece; a fully rejected edge ends the current piece. For closed paths, a last piece ending where the first piece begins is merged in front of it without repeating the joint. Pieces with fewer than two vertices are dropped. Vertices are exact rational strings.

split: open-access