skills/tabular/hierarchical-collision-cascade/SKILL.md
Three-level polygon overlap test — AABB early exit, then point-in-polygon ray casting, then segment intersection — for fast non-convex collision detection
npx skillsauth add wenmin-wu/ds-skills tabular-hierarchical-collision-cascadeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Full polygon intersection is expensive for complex shapes. A three-level cascade tests cheapest first: (1) axis-aligned bounding box overlap — rejects most non-colliding pairs instantly, (2) point-in-polygon via ray casting — catches containment cases, (3) edge-edge segment intersection — catches crossing edges. Each level filters candidates for the next, achieving near-O(1) for well-separated objects.
import numpy as np
def aabb_overlap(a_bounds, b_bounds):
ax0, ay0, ax1, ay1 = a_bounds
bx0, by0, bx1, by1 = b_bounds
return not (ax1 < bx0 or bx1 < ax0 or ay1 < by0 or by1 < ay0)
def point_in_polygon(px, py, polygon):
n = len(polygon)
inside = False
j = n - 1
for i in range(n):
xi, yi = polygon[i]
xj, yj = polygon[j]
if ((yi > py) != (yj > py)) and \
(px < (xj - xi) * (py - yi) / (yj - yi) + xi):
inside = not inside
j = i
return inside
def segments_intersect(a1, a2, b1, b2):
d1 = cross2d(b2 - b1, a1 - b1)
d2 = cross2d(b2 - b1, a2 - b1)
d3 = cross2d(a2 - a1, b1 - a1)
d4 = cross2d(a2 - a1, b2 - a1)
return (d1 * d2 < 0) and (d3 * d4 < 0)
def polygons_overlap(poly_a, poly_b):
if not aabb_overlap(bounds(poly_a), bounds(poly_b)):
return False
for pt in poly_a:
if point_in_polygon(pt[0], pt[1], poly_b):
return True
for pt in poly_b:
if point_in_polygon(pt[0], pt[1], poly_a):
return True
for i in range(len(poly_a)):
for j in range(len(poly_b)):
if segments_intersect(
poly_a[i], poly_a[(i+1) % len(poly_a)],
poly_b[j], poly_b[(j+1) % len(poly_b)]):
return True
return False
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF