FA-70396 / GIS polygon topology / Open access
Point classification against a polygon with holes: hole boundaries · case 01
Points on a hole edge are classified as interior or exterior depending on the ray.
ROOT CAUSE
The boundary test runs on the exterior ring only.
VERIFIED REPAIR
At the hole boundaries step restore `for ring in rings: for a, b in zip(ring, ring[1:]):`, leaving the rest of the model unchanged.
Unsuccessful approach: The boundary test now runs on holes only and misses the exterior edge.
Case contract
Input [point, rings]: exterior ring then hole rings, closed, integer coordinates. A point on any ring edge (exact cross product 0 and inside the closed segment bounding box) is "boundary". Otherwise a crossing-number test with the half-open rule (a.y > py) != (b.y > py) and ray toward +x decides containment: outside the exterior or inside any hole is "exterior", else "interior".
Why this case matters
Parcel lookup, geofencing and spatial joins classify points against polygons with holes; lakes and courtyards must not count as inside.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
pt, rings = x
px, py = pt
def on_seg(a, b):
cross = (b[0] - a[0]) * (py - a[1]) - (b[1] - a[1]) * (px - a[0])
if cross != 0:
return False
return min(a[0], b[0]) <= px <= max(a[0], b[0]) and min(a[1], b[1]) <= py <= max(a[1], b[1])
def inside(ring):
c = False
for a, b in zip(ring, ring[1:]):
if (a[1] > py) != (b[1] > py):
xi = a[0] + (py - a[1]) * (b[0] - a[0]) / (b[1] - a[1])
if px < xi:
c = not c
return c
for ring in rings[:1]:
for a, b in zip(ring, ring[1:]):
if on_seg(a, b):
return 'boundary'
if not inside(rings[0]):
return 'exterior'
for hole in rings[1:]:
if inside(hole):
return 'exterior'
return 'interior'
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control #0', [[1, 1], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #1', [[3, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #2', [[8, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #3', [[6, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #4', [[12, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #5', [[0, 0], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #3', [[6, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #4', [[12, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #5', [[0, 0], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #8', [[8, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior')], [('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #8', [[8, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #11', [[-1, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #11', [[-1, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #14', [[4, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #15', [[6, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #17', [[10, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #14', [[4, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #15', [[6, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #16', [[9, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #18', [[12, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #21', [[8, 1], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #24', [[9, 3], [[[0, 0], [8, 0], [4, 6], [0, 0]]]], 'exterior')]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control #0 | interior | interior | Passed |
| control #1 | exterior | exterior | Passed |
| control #2 | exterior | exterior | Passed |
| control #3 | interior | interior | Passed |
| control #4 | boundary | boundary | Passed |
| control #5 | boundary | boundary | Passed |
| control #6 | exterior | boundary | Failed |
| control #7 | interior | boundary | Failed |
SHA-256 / 8e5dce23f8ef82268b675c43780c8822e549804a1dfded2a478f2b7f1219bab7
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
pt, rings = x
px, py = pt
def on_seg(a, b):
cross = (b[0] - a[0]) * (py - a[1]) - (b[1] - a[1]) * (px - a[0])
if cross != 0:
return False
return min(a[0], b[0]) <= px <= max(a[0], b[0]) and min(a[1], b[1]) <= py <= max(a[1], b[1])
def inside(ring):
c = False
for a, b in zip(ring, ring[1:]):
if (a[1] > py) != (b[1] > py):
xi = a[0] + (py - a[1]) * (b[0] - a[0]) / (b[1] - a[1])
if px < xi:
c = not c
return c
for ring in rings[1:]:
for a, b in zip(ring, ring[1:]):
if on_seg(a, b):
return 'boundary'
if not inside(rings[0]):
return 'exterior'
for hole in rings[1:]:
if inside(hole):
return 'exterior'
return 'interior'
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control #0', [[1, 1], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #1', [[3, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #2', [[8, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #3', [[6, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #4', [[12, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #5', [[0, 0], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #3', [[6, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #4', [[12, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #5', [[0, 0], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #8', [[8, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior')], [('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #8', [[8, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #11', [[-1, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #11', [[-1, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #14', [[4, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #15', [[6, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #17', [[10, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #14', [[4, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #15', [[6, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #16', [[9, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #18', [[12, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #21', [[8, 1], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #24', [[9, 3], [[[0, 0], [8, 0], [4, 6], [0, 0]]]], 'exterior')]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control #0 | interior | interior | Passed |
| control #1 | exterior | exterior | Passed |
| control #2 | exterior | exterior | Passed |
| control #3 | interior | interior | Passed |
| control #4 | exterior | boundary | Failed |
| control #5 | interior | boundary | Failed |
| control #6 | boundary | boundary | Passed |
| control #7 | boundary | boundary | Passed |
SHA-256 / 4d408bc898db6176854b77fd3be48274239c04e5781e1e79e38a2e5d71b9f3bc
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
pt, rings = x
px, py = pt
def on_seg(a, b):
cross = (b[0] - a[0]) * (py - a[1]) - (b[1] - a[1]) * (px - a[0])
if cross != 0:
return False
return min(a[0], b[0]) <= px <= max(a[0], b[0]) and min(a[1], b[1]) <= py <= max(a[1], b[1])
def inside(ring):
c = False
for a, b in zip(ring, ring[1:]):
if (a[1] > py) != (b[1] > py):
xi = a[0] + (py - a[1]) * (b[0] - a[0]) / (b[1] - a[1])
if px < xi:
c = not c
return c
for ring in rings:
for a, b in zip(ring, ring[1:]):
if on_seg(a, b):
return 'boundary'
if not inside(rings[0]):
return 'exterior'
for hole in rings[1:]:
if inside(hole):
return 'exterior'
return 'interior'
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('control #0', [[1, 1], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #1', [[3, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #2', [[8, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #3', [[6, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #4', [[12, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #5', [[0, 0], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #3', [[6, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #4', [[12, 6], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #5', [[0, 0], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #8', [[8, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior')], [('control #6', [[2, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #7', [[7, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #8', [[8, 9], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #11', [[-1, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #9', [[11, 11], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #10', [[13, 5], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #11', [[-1, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'exterior'), ('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #14', [[4, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #15', [[6, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #17', [[10, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary')], [('control #12', [[6, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #13', [[5, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #14', [[4, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #15', [[6, 2], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #16', [[9, 3], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #18', [[12, 12], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'boundary'), ('control #21', [[8, 1], [[[0, 0], [12, 0], [12, 12], [0, 12], [0, 0]], [[2, 2], [2, 5], [5, 5], [5, 2], [2, 2]], [[7, 3], [7, 9], [10, 9], [10, 3], [7, 3]]]], 'interior'), ('control #24', [[9, 3], [[[0, 0], [8, 0], [4, 6], [0, 0]]]], 'exterior')]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control #0 | interior | interior | Passed |
| control #1 | exterior | exterior | Passed |
| control #2 | exterior | exterior | Passed |
| control #3 | interior | interior | Passed |
| control #4 | boundary | boundary | Passed |
| control #5 | boundary | boundary | Passed |
| control #6 | boundary | boundary | Passed |
| control #7 | boundary | boundary | Passed |
SHA-256 / 2095ae7054dc8ecd14956f67180fc7acac0d8ff983ff9a38de6d3063b7dd2e59
Verification & scope
Stipulated deterministic toy contract on a bounded input domain; results are rounded as stated and no conformance with any published standard or library is claimed. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:48:20.418468+00:00.
Case digest / 904225801fb2c5a7b3873568079375617ec187ab857d3efb0ebda5efefe2bd85