lietzsche;flynn

updated 2026-11-26·4 min read

Topological Set Verification

Archived design specification for Cattell CFIT Scale 3 Subtest 4 planar boolean conditions, Jordan curve winding-number ray casting, and anchor-envelope AIG.

Archived / Unshipped Spec: This page documents the planned geometric verifier for Cattell’s Culture Fair Intelligence Test (CFIT Scale 3, Subtest 4). No CFIT Scale 3 module or interactive Venn sandbox is wired into the live Flynn app (modules currently ships ist-battery, ist-battery-unpad-1973, and utbk-snbt).

I originally planned Cattell’s CFIT Scale 3 alongside IST and UTBK, got as far as writing the geometric verifier spec, and then shelved it so I would actually finish the active batteries instead of leaving half-baked modules everywhere.

My first validator prototype also broke immediately. Each CFIT Subtest 4 item shows overlapping closed curves (circles, squares, triangles) with control dots and asks which of 5 candidate figures lets you place dots in the exact same inside-and-outside combination. To check clicks fast, I rasterized each shape in a unique solid color onto an offscreen <canvas> and called ctx.getImageData(x, y, 1, 1). Retina scaling and subpixel antialiasing blended border RGB values near edges, browsers smoothed paths slightly differently across OSes, and getImageData() forced synchronous GPU-to-CPU readbacks that tanked frame rates on phones.

Winding-Number Ray Casting

The replacement spec drops pixel sampling and checks polygon vertices directly using winding-number ray casting: cast a horizontal ray to the right from click point P0(x0,y0)P_0(x_0, y_0) and count net upward vs. downward edge crossings.

export interface TopologicalCondition {
  includedShapes: ShapeId[]
  excludedShapes: ShapeId[]
}

When a horizontal ray along y=pyy = py hits a polygon corner directly, a naive crossing test double-counts the vertex and flips the result from inside (1) to outside (2 or 0). Enforcing half-open vertical bounds prevents that:

  • Upward edges qualify only if y1≤py<y2y_1 \le py < y_2 and P0P_0 sits strictly left of the edge.
  • Downward edges qualify only if y2≤py<y1y_2 \le py < y_1 and P0P_0 sits strictly right of the edge.
  • Strictly horizontal edges (y1=y2=pyy_1 = y_2 = py) satisfy neither inequality and are skipped automatically.
Math & Reference Sketch: Jordan Curves & computeWindingNumber

Let a stimulus consist of kk simple closed Jordan curves {∂S1,…,∂Sk}\{\partial S_1, \dots, \partial S_k\} in R2\mathbb{R}^2. For any point P(x,y)∈R2P(x, y) \in \mathbb{R}^2, its membership signature σ⃗(P)∈{0,1}k\vec{\sigma}(P) \in \{0, 1\}^k is σi(P)=1\sigma_i(P) = 1 if P∈int⁡(Si)P \in \operatorname{int}(S_i) and 00 otherwise. A candidate figure {∂S1′,…,∂Sk′}\{\partial S'_1, \dots, \partial S'_k\} matches σ⃗target\vec{\sigma}_{\text{target}} iff:

Rvalid=(⋂i:σi=1int⁡(Si′))∖(⋃j:σj=0int⁡(Sj′))≠∅\mathcal{R}_{\text{valid}} = \left( \bigcap_{i: \sigma_i = 1} \operatorname{int}(S'_i) \right) \setminus \left( \bigcup_{j: \sigma_j = 0} \operatorname{int}(S'_j) \right) \neq \emptyset

For a closed curve γ(t)=(x(t),y(t))\gamma(t) = (x(t), y(t)) and P0(x0,y0)∉γP_0(x_0, y_0) \notin \gamma, the winding number is:

wn⁡(P0,γ)=12π∮γ(x−x0) dy−(y−y0) dx(x−x0)2+(y−y0)2\operatorname{wn}(P_0, \gamma) = \frac{1}{2\pi} \oint_\gamma \frac{(x - x_0) \, dy - (y - y_0) \, dx}{(x - x_0)^2 + (y - y_0)^2}

By the Jordan curve theorem, P0∈int⁡(γ)  ⟺  wn⁡(P0,γ)≠0P_0 \in \operatorname{int}(\gamma) \iff \operatorname{wn}(P_0, \gamma) \neq 0.

export function computeWindingNumber(
  point: [number, number],
  vertices: [number, number][],
  epsilon: number = 1e-6
): number {
  const [px, py] = point
  let wn = 0

  for (let i = 0; i < vertices.length - 1; i++) {
    const [x1, y1] = vertices[i]
    const [x2, y2] = vertices[i + 1]

    if (y1 <= py) {
      if (y2 > py) {
        const cross = (x2 - x1) * (py - y1) - (px - x1) * (y2 - y1)
        if (cross > epsilon) wn++
      }
    } else {
      if (y2 <= py) {
        const cross = (x2 - x1) * (py - y1) - (px - x1) * (y2 - y1)
        if (cross < -epsilon) wn--
      }
    }
  }

  return wn
}

Constrained Anchor Envelopes in AIG

Randomizing shape coordinates inside a 200×200200 \times 200 bounding box produces impossible layouts over 30% of the time: for example, requiring a dot inside Circle and Square but outside Triangle when a giant Triangle covers both. Sampling shapes from constrained anchor envelopes guarantees a non-empty valid region before rendering, while rejecting points placed within ϵ≤10−6\epsilon \le 10^{-6} of an outline stroke as ambiguous.

For the live planar geometry verification currently shipped on 2D figure dissections, see Amthauer IST-70.

Search wiki and portfolio

type to search across all entries.