brokkr_reference.pair: a point with no fitting crossing is skipped and named, the kink gate is gone; PLANAR between 0.041 and 0.36

aetheria-release:ruling:lift-skips-points-not-strokes. The global choice may give a point
that met line b more than once no crossing, at SKIP (2.8) times the crease's median turn,
the median never under TURN (0.061 rad), the turn read across the gap. "skipped" names the
points; a lift that skips more than SHARE (0.24) of the points that met line b is refused,
and no more than that are skipped in a row. KINK and "kink" are deleted. One _bend.

189 exact doubled-back strokes: 0 wrong, 0 refused, 15 skip their last point (was 15 refused).
A cornered crease lifts 24 of 24 at each view (was refused at one).
PLANAR 0.057 to 0.12, claimed by a panel reading 0.041; DECIDED's one-step separation is
recorded as an exception to lodur:ruling:deterministic-bound-margin; S1 claimed by a direct
_bend test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-03 00:30:34 +01:00
commit 3b19e8c816
3 changed files with 165 additions and 81 deletions

View file

@ -83,7 +83,7 @@
},
{
"name": "brokkr_reference.lift_pair",
"doc": "Lift two traced lines that are one crease and its mirror image, on a part symmetric about its frame's x = 0, through a camera into the frame. The result is the crease, the cage column whose level-1 crease is built through it, the counts of ambiguous and unmatched points, and how far the built crease draws from each line (docs/reference.md).",
"doc": "Lift two traced lines that are one crease and its mirror image, on a part symmetric about its frame's x = 0, through a camera into the frame. The result is the crease, the cage column whose level-1 crease is built through it, the counts of ambiguous and unmatched points, the points skipped, and how far the built crease draws from each line (docs/reference.md).",
"changesScene": true,
"editModeSafe": false,
"result": "brokkr_mesh_polish_result",

View file

@ -48,9 +48,11 @@ LENS_MM = (4.0, 4000.0) # the focal length never leaves this: past 4000 mm a vi
BAND = 1.1 # lens_band: the lenses whose refitted rms is within this multiple of the best
STEP = 0.1 # the band is walked in steps of this in log f
FINE = 1.0 # pixels: no mark is placed truer than this, so the band is never judged against a smaller error (exact marks fit every lens of a flat view to 1e-6 px and would call one of them best)
PLANAR = 0.057 # marks thinner than this share of their spread (their planarity) are near a plane: a band of theirs that is open at one end of LENS_MM is reported open at both. The geometric mean of 0.009, a panel with relief whose band does open at one end, and 0.36, marks with depth (tests/test_reference.py)
KINK = 3.1 # pair refuses a lift whose worst turn at a chosen crossing is more than this many times the crease's median turn (tests/test_reference.py holds the readings either side)
DECIDED = 1.57 # a lens is determined when its band is inside LENS_MM and spans no more than this factor. A band's span is a whole number of STEPs: this is the geometric mean of four steps (1.49, the widest that marks with depth 3 px off read) and five (1.65)
PLANAR = 0.12 # marks thinner than this share of their spread (their planarity) are near a plane: a band of theirs that is open at one end of LENS_MM is reported open at both. The geometric mean of 0.041, a panel with relief whose band does open at one end, and 0.36, marks with depth: separation 2.9 each side (tests/test_reference.py)
SKIP = 2.8 # pair: a point that met line b more than once may be given no crossing, at the cost of this many times the crease's median turn. On 189 exact doubled-back strokes 1.25 to 7 lift every one exactly with one point skipped in 15; 1.0 and 8 lift some wrong: the geometric mean, 2.8 each side (read with TURN out of the way, tests/test_reference.py)
TURN = 0.061 # radians: the median turn is never read as less than this, so a crease of straight runs (median turn 0) does not skip for nothing. The geometric mean of 0.0496, under which a cornered crease drops the points between two of its corners, and 0.0749, over which a wrong crossing of a gentle crease (median turn 0.025) is cheaper than its skip: separation 1.23 each side
SHARE = 0.24 # pair refuses a lift that skips more than this share of the points that met line b, and never skips more than this share in a row. The geometric mean of 4 of 23, the most skipped on 11340 noisy doubled-back strokes, and 8 of 24, a scribbled line b: separation 1.38 each side
DECIDED = 1.57 # a lens is determined when its band is inside LENS_MM and spans no more than this factor. A band's span is a whole number of STEPs: this is the geometric mean of four steps (1.49, the widest that marks with depth 3 px off read) and five (1.65). An exception to lodur:ruling:deterministic-bound-margin: the two readings are one STEP apart, 1.105, and readings quantised in STEPs have no pair 1.2 apart with nothing between; a host that moves a band by a step fails the span assertion in tests/test_reference.py
MODELS = {"upright": (), "rolled": ("roll",), "free": ("roll", "centre"), "square": ("square",)} # what a model solves beyond place, yaw, pitch and focal length; "square" holds the yaw at a quarter turn instead
QUARTER = math.pi / 2
@ -404,37 +406,49 @@ def extended(points, by):
def _bend(X0, X1, X2):
"""The turn, in radians, of a crease that runs X0, X1, X2; a half turn where it stands still."""
u, v = X1 - X0, X2 - X1
along = np.linalg.norm(u) * np.linalg.norm(v)
return float(np.arccos(np.clip(u @ v / along, -1, 1))) if along > 1e-24 else math.pi
"""The turn, in radians, of a crease that runs X0, X1, X2 (three numbers each); a half turn where it stands
still. Plain arithmetic: _smoothest reads it a million times on a long fold."""
u, v = (X1[0] - X0[0], X1[1] - X0[1], X1[2] - X0[2]), (X2[0] - X1[0], X2[1] - X1[1], X2[2] - X1[2])
along = math.sqrt((u[0] * u[0] + u[1] * u[1] + u[2] * u[2]) * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]))
return math.acos(max(-1.0, min(1.0, (u[0] * v[0] + u[1] * v[1] + u[2] * v[2]) / along))) if along > 1e-24 else math.pi
def _smoothest(candidates):
def _smoothest(candidates, skip=None, run=0):
"""One candidate per point, chosen together: the choice whose curve turns least in all (the sum of _bend over
every three points in a row), found by dynamic programming over pairs of neighbouring choices, so no point is
settled before the points after it are read. Returns the index taken at each point; ties go to the earlier
candidate."""
every three taken points in a row), found by dynamic programming over pairs of neighbouring taken points, so
no point is settled before the points after it are read. With `skip` (radians) a point that has more than one
candidate may take none, at that cost, up to `run` such points in a row: the turn is then read across the gap,
over the points that are taken, so a skip cannot hide a turn. Returns the index taken at each point, None where it is skipped; ties go to the
earlier candidate and to the choice reached first."""
m = len(candidates)
if m < 3:
return [0] * m
cost = {(j, k): 0.0 for j in range(len(candidates[0])) for k in range(len(candidates[1]))}
back = []
for t in range(2, m):
new, via = {}, {}
for (h, j), c in cost.items():
for k, X in enumerate(candidates[t]):
total = c + _bend(candidates[t - 2][h], candidates[t - 1][j], X)
if (j, k) not in new or total < new[j, k]:
new[j, k], via[j, k] = total, h
cost = new
back.append(via)
j, k = min(cost, key=lambda s: (cost[s], s))
taken = [k, j]
for via in reversed(back):
j, k = via[j, k], j
taken.append(j)
return taken[::-1]
C = [[tuple(float(v) for v in X) for X in options] for options in candidates]
free = [skip is not None and len(options) > 1 for options in C]
best = {} # (t, k, the taken point before it, its candidate) -> (cost, the state before)
for t in range(min(m, run + 1)):
for k in range(len(C[t])):
best[t, k, -1, -1] = (skip * t if t else 0.0, None)
if not free[t]:
break
end, least = None, math.inf
for t in range(m):
for state in [s for s in best if s[0] == t]:
cost, _ = best[state]
_, k, tp, kp = state
if m - 1 - t <= run and all(free[t + 1:]) and cost + (skip or 0.0) * (m - 1 - t) < least:
end, least = state, cost + (skip or 0.0) * (m - 1 - t)
for t2 in range(t + 1, min(m, t + run + 2)):
for k2, X in enumerate(C[t2]):
total = cost + (skip * (t2 - t - 1) if t2 > t + 1 else 0.0) + (_bend(C[tp][kp], C[t][k], X) if tp >= 0 else 0.0)
if (t2, k2, t, k) not in best or total < best[t2, k2, t, k][0]:
best[t2, k2, t, k] = (total, state)
if not free[t2]:
break
taken = [None] * m
while end is not None:
taken[end[0]] = end[1]
end = best[end][1]
return taken
def pair(cam, frame, a, b, n=24, extend=0.2):
@ -446,13 +460,15 @@ def pair(cam, frame, a, b, n=24, extend=0.2):
Returns {"crease": [[x, y, z], ...] in the frame, x >= 0, in the order of `a`; "side": the side of the frame
`a` is on, +1 or -1; "unmatched": points of `a` whose line to the vanishing point never meets `b`, left out;
"ambiguous": points whose line meets `b` more than once; "kink": the worst turn (_bend) at a point that had
a crossing to choose, over the crease's median turn}. Every crossing of such a line triangulates to a point
that draws back onto both lines, so the drawing cannot say which is meant; the crease can: the crossings are
chosen together, as the choice whose crease turns least in all (_smoothest). That is the true crease wherever
every point's true crossing is among its crossings. Where one is not (the end of `a` mirrors the very end of
`b`, and only the doubled strokes are met) the smoothest crease still kinks there, and a kink over KINK is
refused.
"ambiguous": points whose line meets `b` more than once; "skipped": the points of `a` (their indices among
its n) that met `b` more than once and were given no crossing, left out}. Every crossing of such a line
triangulates to a point that draws back onto both lines, so the drawing cannot say which is meant; the crease
can: the crossings are chosen together, as the choice whose crease turns least in all (_smoothest). That is
the true crease wherever every point's true crossing is among its crossings. Where one is not (the end of `a`
mirrors the very end of `b`, and only the doubled strokes are met) every crossing of that point kinks the
crease, and the point is skipped instead: a skip costs SKIP times the crease's median turn (the median of the
choice with no skips, never under TURN), and only a point with a choice can be skipped. A lift that skips more
than SHARE of the points it had crossings for is refused, and the choice never skips more than that in a row.
The lift is as sure as the frame's turn to the camera: seen nearly along the mirror plane the two sight lines
are nearly parallel, and a degree of turn moves the crease a long way in depth."""
@ -474,13 +490,18 @@ def pair(cam, frame, a, b, n=24, extend=0.2):
found.append(lifts)
fold = lambda X: np.array([abs(X[0]), X[1], X[2]]) # noqa: E731
at = [i for i, lifts in enumerate(found) if lifts]
lifted = [found[i][k] for i, k in zip(at, _smoothest([[fold(X) for X in found[i]] for i in at]))]
bends = [(_bend(fold(lifted[t - 2]), fold(lifted[t - 1]), fold(lifted[t])), any(len(found[i]) > 1 for i in at[t - 2:t + 1])) for t in range(2, len(at))]
kink = max((bend for bend, chose in bends if chose), default=0.0) / max(float(np.median([bend for bend, _ in bends])), 1e-12) if bends else 0.0
if kink > KINK:
raise ReferenceFitError(f"line b doubles back and the smoothest crease through its crossings still turns {kink:.1f} times its usual turn where a crossing was chosen (over {KINK} is refused): a point of line a has no true mirror among its crossings, most often at an end. Draw line b as one stroke that does not run beside itself")
folded = [[fold(X) for X in found[i]] for i in at]
taken = _smoothest(folded)
if any(len(options) > 1 for options in folded) and len(at) > 2:
whole = [folded[t][k] for t, k in enumerate(taken)]
usual = float(np.median([_bend(*whole[t - 2:t + 1]) for t in range(2, len(whole))]))
taken = _smoothest(folded, SKIP * max(usual, TURN), int(SHARE * len(at)))
skipped = [i for i, k in zip(at, taken) if k is None]
if len(skipped) > SHARE * len(at):
raise ReferenceFitError(f"line b doubles back and {len(skipped)} of the {len(at)} points of line a that meet it have no crossing that fits the crease (points {skipped}; over {SHARE:g} of them is refused). Draw line b as one stroke that does not run beside itself")
lifted = [found[i][k] for i, k in zip(at, taken) if k is not None]
return {"crease": [[float(v) for v in fold(X)] for X in lifted], "side": 1 if sum(np.sign(X[0]) for X in lifted) >= 0 else -1,
"ambiguous": sum(1 for lifts in found if len(lifts) > 1), "kink": float(kink), "unmatched": sum(1 for lifts in found if not lifts)}
"ambiguous": sum(1 for lifts in found if len(lifts) > 1), "skipped": skipped, "unmatched": sum(1 for lifts in found if not lifts)}
def on_plane(cam, frame, line, point, normal, n=24):

View file

@ -27,6 +27,7 @@ import re
import sys
import types
import unittest
import unittest.mock
from pathlib import Path
SURFACE = Path(__file__).resolve().parents[1]
@ -291,12 +292,13 @@ class SolveTests(unittest.TestCase):
85 mm, 3 px off, read a band of four steps, 1.4918 times, the widest of 48 such solves, and are called
determined; the same marks 5 px off read five steps, 1.6487, and are not. DECIDED 1.57 is the geometric
mean, 1.05 from each: the readings are one step apart, 1.105, under the ruling's 1.2, and no nearer pair
exists. Mutants DECIDED 1.4 and 1.7 die here by which call flips; 2.5 too. PLANAR: a panel with relief
(planarity 0.009) seen square-on reads a band open at 4000 mm and so is reported open at both ends; marks
with depth read 0.36. PLANAR 0.057 is the geometric mean, 6.3 from each: PLANAR 0.001 and 0.008 leave the
panel's band at [38.6, 4000] and die here, PLANAR 1.0 dies at the oblique view. Unclaimed, no reading
between: mutants from 0.009 to 0.36 (0.03 and 0.3 pass every test); panels of planarity 0.03 and 0.06
read closed bands 1.5 to 4 times wide, where PLANAR does nothing."""
exists: an exception to the ruling, recorded at core.DECIDED (a band moved one step by a host fails the span
assertion here, loudly). Mutants DECIDED 1.4 and 1.7 die here by which call flips; 2.5 too; 1.5 and 1.6 are
unclaimed, inside the step. PLANAR: a panel with relief (planarity 0.041) seen square-on through 85 mm,
3 px off, reads a band open at 4000 mm and so is reported open at both ends; marks with depth read 0.36.
PLANAR 0.12 is the geometric mean, 2.9 from each: PLANAR 0.03 leaves the panel's band at [84.4, 4000] and
dies here, as 0.001 and 0.008 do on the flatter panel (0.009); PLANAR 1.0 dies at the oblique view.
Unclaimed: PLANAR 0.3, which differs from shipped in none of 192 solves of panels 0.009 to 0.277 thick."""
for noise, span, determined in ((3.0, 1.4918, True), (5.0, 1.6487, False)):
drawn = core.project(camera(self.points, 35, 20, 85), self.points) + np.random.default_rng(3).normal(0, noise, (13, 2))
s = core.solve(dict(zip(NAMES, self.points.tolist())), dict(zip(NAMES, drawn.tolist())), BOX)
@ -304,11 +306,12 @@ class SolveTests(unittest.TestCase):
self.assertIs(s["lens_determined"], determined)
self.assertAlmostEqual(s["planarity"], 0.3615, delta=1e-3)
relief = np.random.default_rng(77).uniform(-1, 1, 13)
panel = np.c_[self.points[:, :2], relief / np.ptp(relief) * 0.01 * np.ptp(self.points[:, :2], axis=0).max()]
drawn = core.project(camera(panel, 35, 90.0, 50), panel) + np.random.default_rng(0).normal(0, 1.0, (13, 2))
s = core.solve(dict(zip(NAMES, panel.tolist())), dict(zip(NAMES, drawn.tolist())), BOX)
self.assertAlmostEqual(s["planarity"], 0.009, delta=5e-4)
self.assertEqual((s["lens_band"], s["lens_determined"]), (list(core.LENS_MM), False))
for depth, lens, noise, planarity in ((0.01, 50, 1.0, 0.009), (0.045, 85, 3.0, 0.041)):
panel = np.c_[self.points[:, :2], relief / np.ptp(relief) * depth * np.ptp(self.points[:, :2], axis=0).max()]
drawn = core.project(camera(panel, 35, 90.0, lens), panel) + np.random.default_rng(0).normal(0, noise, (13, 2))
s = core.solve(dict(zip(NAMES, panel.tolist())), dict(zip(NAMES, drawn.tolist())), BOX)
self.assertAlmostEqual(s["planarity"], planarity, delta=5e-4)
self.assertEqual((s["lens_band"], s["lens_determined"]), (list(core.LENS_MM), False))
def test_the_exact_gates_sit_at_a_billionth_of_the_marks_extent(self):
"""exact-gate: each of _decidable's three tests reads a ratio (the marks' thinnest extent over their
@ -353,10 +356,13 @@ class LiftTests(unittest.TestCase):
"""Traced lines lifted into a frame, the cage through a crease, and the flow score. Mutants, each run once:
N1 the mirror camera without MIRROR test_a_mirrored_pair_lifts_back_to_its_crease
N2 the first crossing kept test_a_folded_line_takes_the_smoothest_crossing, and the two after it
G1 each crossing chosen as it is reached (greedy) test_strokes_doubled_back_lift_exactly_or_are_refused
K1 no refusal; K2, K3 KINK 1.2 and 8 the same
Unclaimed: S1, a crease that stands still costs no turn (_bend's half turn read as 0), passes every test: no
fixture lifts two points to one place.
K1 no point skipped test_strokes_doubled_back_lift_exactly_with_a_point_skipped
K2, K3 SKIP 1.0 and 8 the same, where TURN is set to 0
K5 a skip's turn not read across the gap the same
K4 a point with one crossing may be skipped test_a_cornered_crease_lifts_whole
T1, T2 TURN 0.04 and 0.09 the same; the doubled strokes
R1, R2 SHARE 0.15 and 0.4 test_a_scribbled_line_is_refused_by_its_share_of_skips
S1 a crease that stands still costs no turn test_a_crease_that_stands_still_is_a_half_turn
H1 a crossing snapped to line b's point before it test_a_hand_traced_pair_lifts_within_a_bound
N3 crease_run without the limit step test_crease_run_is_one_level_of_subdivision
N3b its first step weighs (1, 4, 1) / 6 the same
@ -429,18 +435,10 @@ class LiftTests(unittest.TestCase):
self.assertEqual((out["ambiguous"], out["unmatched"], len(out["crease"])), (10, 2, 22))
self.assertLess(self.off(out["crease"]), 4.7e-9)
def test_strokes_doubled_back_lift_exactly_or_are_refused(self):
"""pair-global-choice: 189 strokes of line b doubled back beside themselves (seven stretches of the crease,
three offsets, the true stroke first, between or last, three views), `extend` 0. The crossings are chosen
together, so every stroke whose points all have their true crossing lifts exactly: 174, worst 9.7e-16 m.
In the other 15, all on the view 10 degrees above the crease, the last point of `a` meets only the doubled
strokes (its mirror is line b's very end), and they are refused by the kink that leaves: the worst turn
at a chosen crossing over the crease's median turn reads 7.7 to 66 on the 15 and at most 1.245 on the 174.
KINK 3.1 is the geometric mean of 1.245 and 7.71, separation 2.5 each side. G1 (each crossing
settled as it is reached) refuses strokes of the first view; K1 lifts the 15 wrong, 0.018 to 0.21 m off;
K2 (KINK 1.2) refuses strokes that lift exactly; K3 (KINK 8) lifts the strokes that read 7.7, 0.018 m off.
The lift bound is the folded-line test's."""
n, wrong, refused = len(self.truth), [], []
def doubled(self):
"""189 strokes of line b doubled back beside themselves: seven stretches of the crease, three offsets, the
true stroke first, between or last, three views."""
n = len(self.truth)
for view, cam in enumerate(self.cams):
a, b = self.traced(cam), self.traced(cam, -1)
for start, end in ((0.1, 0.3), (0.3, 0.5), (0.3, 0.7), (0.1, 0.9), (0.5, 0.8), (0.0, 0.4), (0.6, 1.0)):
@ -451,16 +449,81 @@ class LiftTests(unittest.TestCase):
d = np.array([-v[1], v[0]]) / np.linalg.norm(v) * offset * np.ptp(b, axis=0).max()
for which, line in (("first", np.vstack([b[:i1 + 1], back + d, out + 2 * d, b[i1 + 1:]])), ("last", np.vstack([b[:i0], out + d, back + 2 * d, b[i0:]])),
("between", np.vstack([b[:i0], out + d, back + 2 * d, out, b[i1 + 1:]]))):
try:
lifted = core.pair(cam, FRAME, a, line, extend=0.0)
except core.ReferenceFitError as refusal:
self.assertIn("doubles back", str(refusal))
refused.append(view)
continue
if self.off(lifted["crease"]) > 2.8e-9:
wrong.append((view, start, end, offset, which, self.off(lifted["crease"]), lifted["kink"]))
self.assertEqual(wrong, [])
self.assertEqual(refused, [2] * 15)
yield (view, start, end, offset, which), cam, a, line
def test_strokes_doubled_back_lift_exactly_with_a_point_skipped(self):
"""pair-global-choice, aetheria-release:ruling:lift-skips-points-not-strokes: `extend` 0. The crossings are
chosen together, so every stroke whose points all have their true crossing lifts exactly with nothing
skipped: 174. In the other 15, all on the view 10 degrees above the crease, the last point of `a` meets
only the doubled strokes (its mirror is line b's very end); that point is skipped, it alone, and the other
23 lift exactly: worst of the 189, 9.7e-16 m, none refused. Read twice: as shipped, where the crease's
median turn (0.025) is under TURN and a skip costs SKIP x TURN, 6.8 medians; and with TURN at 0, where it
costs SKIP medians and SKIP's own readings show: 1.25 to 7 read the same, 1.0 (K2) skips points that had
their true crossing and lifts strokes wrong, 0.008 m off, 8 (K3) keeps a wrong crossing, 0.018 m off: 2.8
is the geometric mean, 2.8 each side. As shipped, TURN up to 0.0749 reads the same and 0.09 (T2) lifts
strokes wrong, 0.018 m off. K1 (no skip) lifts the 15 wrong; K5 (the turn not read across a skipped
point) skips where nothing is wrong. The lift bound is the folded-line test's."""
for turn in (core.TURN, 0.0):
with unittest.mock.patch.object(core, "TURN", turn):
wrong, skipped = [], []
for key, cam, a, line in self.doubled():
lifted = core.pair(cam, FRAME, a, line, extend=0.0)
if self.off(lifted["crease"]) > 2.8e-9 or len(lifted["crease"]) + len(lifted["skipped"]) + lifted["unmatched"] != 24:
wrong.append((key, self.off(lifted["crease"]), lifted["skipped"]))
if lifted["skipped"]:
skipped.append((key[0], lifted["skipped"]))
self.assertEqual(wrong, [], turn)
self.assertEqual(skipped, [(2, [23])] * 15, turn)
CORNERS = [[0.4, -1.0, 0.5], [0.7, -0.35, 0.55], [0.35, 0.15, 0.75], [0.6, 0.6, 0.7], [0.4, 1.0, 0.8]]
def test_a_cornered_crease_lifts_whole(self):
"""kink-refuses-exact-cornered-crease: a crease of four straight runs, corners of 1.0 to 1.2 radians, traced
exactly, no fold. Its median turn is 0 (1.5e-8), and at the first view three points between two corners
meet line b twice. All 24 lift at each view, 1.2e-15 m off, nothing skipped: the median is read as TURN.
With TURN under 0.0496 (T1 0.04) the three are skipped, which saves the 0.35 radians of the stretch
between the corners; K4 (a point with one crossing may be skipped) skips here too."""
V = np.array(self.CORNERS)
truth = np.vstack([np.linspace(V[i], V[i + 1], 500, endpoint=False) for i in range(4)] + [V[-1:]])
for cam, ambiguous in zip(self.cams, (3, 0, 0)):
out = core.pair(cam, FRAME, core.seen(cam, FRAME, truth), core.seen(cam, FRAME, truth * [-1, 1, 1]))
self.assertEqual((len(out["crease"]), out["ambiguous"], out["skipped"], out["unmatched"]), (24, ambiguous, [], 0))
self.assertLess(float(core._off(np.array(out["crease"]), truth).max()), 1e-6)
def test_a_scribbled_line_is_refused_by_its_share_of_skips(self):
"""SHARE: line b scribbled over (six loops, 12% of its extent across) on the second view. Over the middle
two fifths 4 of the 23 points that meet it are skipped, 0.174, and the lift is given, with the four named;
over the whole line 8 of 24, 0.333, and it is refused. 4 of 23 is also the most skipped in 11340 noisy
doubled-back strokes (cut_report h4). SHARE 0.24 is the geometric mean, 1.38 each side: R1 (0.15) refuses
the first, R2 (0.4) gives the second. The share says how much of the stroke was left out, not that what
was kept is right: the first lift is 0.066 m off, the scribble's own width."""
cam, n = self.cams[1], len(self.truth)
a, b = self.traced(cam), self.traced(cam, -1)
def scribbled(start, end):
i0, i1 = int(start * (n - 1)), int(end * (n - 1))
t = np.linspace(0, 1, i1 - i0 + 1)
d = np.gradient(b, axis=0)[i0:i1 + 1]
d /= np.linalg.norm(d, axis=1)[:, None]
wide = 0.12 * np.ptp(b, axis=0).max()
line = b.copy()
line[i0:i1 + 1] += np.stack([-d[:, 1], d[:, 0]], 1) * ((2 * np.abs((t * 6) % 1 - 0.5) - 0.5) * wide)[:, None] + d * (np.sin(12 * np.pi * t) * wide)[:, None]
return line
out = core.pair(cam, FRAME, a, scribbled(0.3, 0.7), extend=0.0)
self.assertEqual((len(out["skipped"]), len(out["crease"]), out["unmatched"]), (4, 19, 1))
with self.assertRaises(core.ReferenceFitError) as caught:
core.pair(cam, FRAME, a, scribbled(0.0, 1.0), extend=0.0)
self.assertIn("8 of the 24 points", str(caught.exception))
def test_a_crease_that_stands_still_is_a_half_turn(self):
"""S1: two crossings that lift to one place are not a straight run. A retraced line a does lift a point
twice."""
X, Y = np.array([0.4, 0.0, 0.5]), np.array([0.5, 0.2, 0.5])
self.assertEqual(core._bend(X, X, Y), math.pi)
self.assertEqual(core._bend(X, Y, Y), math.pi)
self.assertAlmostEqual(core._bend(X, Y, 2 * Y - X), 0.0, delta=1e-7)
self.assertAlmostEqual(core._bend(X, Y, X), math.pi, delta=1e-7)
def test_a_line_that_repeats_an_end_point_is_refused(self):
"""A doubled click at an end of line b leaves that end no direction to run on in: refused by name (it was a