# Changelog

Hornfolding development phase 0.x, goal: 1.0. Newest version first.
Older entries use the identifier names of that time (German names such as `baue()`, `bogen_hand`, `bogenweg()`).

## 0.69
Model change (baseline renewed: baseline_v069.json, 37 cases; previous: baseline_v068.json)
- Hornresp S1: no longer the specified value in every case. With a kink (Kink = y) it stays the specified S1 (the real S1 is solved so that the volume S1-S2 matches). Without a kink S1_HR = 2*V12/L12 - S2 from the built volume; a specified S1 then has no effect (console note). With S1 = auto the value is practically unchanged (standard input: 390.09 vs 390.1). S1 is not part of the regression keys.
- Hornresp S5: mean of the volume-equal S5 (2*V45/L45 - S4) and the inertance-equal S5 (same integral ds/A as the built chamber, with the kink cross-section at K_up). The old no-kink formula S5_real - S1_HR + s1_eff is gone. Console line shows both values; note if they differ by more than 2 %. Change in the regression set: S5 in 35 of 37 cases, -3.4 ... +29.9 % (large only where S5 is small, e.g. in_b40).
- S4 in bend 6 (all cases): S4 = Ax + (Ax - S5_real) * L2 / Lk, no coupling to the Hornresp S5 (removes the pole at Lk = L2 of 0.68). Test file A (Kink = y, S1 = 800, S4 in bend 6) is solvable again (S4 = 2443.2 as in 0.67). Changed in the set: S4 in 4 cases (-3.4 ... +4.5 %), L45 -3.4 ... +2.6 %, total path -0.6 ... +0.5 %.
- Message "None of the S3 positions can be calculated" now names the reason (one common reason, or reasons per position); S4 <= 0 and S5 <= 0 rejections have texts.
- Input order follows Hornresp: S1, S2, S3 (or slope), L23, S4, S5, DriverOffset ("distance of S2 + S4 (the driver centre) from the left outer edge"); also in the saved input file. S1 'auto' is resolved after DriverOffset is known.
Review of 0.68 (two findings, both valid, no result change in the set)
- Kink detection: tolerance 1e-3 scaled with CM**2 (area unit).
- DriverDepth check, S4 in bend 6: the extended underside of d is intersected only in front of U4 (parallel lines and intersections behind U4 are discarded).
- Comment in kink_check() (0.68, no code change).
Not validated: whether the 50/50 mean of volume and inertance is the better S5 for Hornresp (no measurement); the claim "< 1 % apart at moderate kinks" was NOT reproduced (0.02 % without a kink, 0.4 ... 7 % in typical kink cases, 38 % in in_b40, 76 % in test file A).

## 0.68
Stage 1 (cleanup, no change of results; 34 regression cases: 0 differences against the true 0.67 baseline)
- cone_data: duplicate assignment of actual["S1"]/["S5"] removed; s4_bend6_level uses geo["s4_in_bend"] (one threshold); parameter `bn` renamed to `b_after`.
- Docstring: DriverOffset (defines the driver position, path S4-S5 comes from the geometry), S3Position auto (fallback: closest calculable position), licence file name `License.md`.
- Console: volume sentence neutral (fan profile usually closer, linear interpolation for strongly widening bends).
- Table "S3 positions compared": new column dL23 % = (L23_calc - L23_wanted) / L23_wanted (only with a desired L23) and a footnote with the selection rule.

Stage 2 (geometry / logic; baseline renewed: baseline_v068.json, 37 cases = 34 old + 3 new bend-6 cases; old values: baseline_v067.json)
1. DriverDepth check: free depth from the driver centre U4 along the board normal en to the nearest opposite wall (ray cast: underside of d, behind its end the end face or the ceiling). In the bend-6 case the smaller of the real wall and the extended underside of d is checked (labelled). New optional input MagnetDiameter (auto = 0.5 x DriverDiameter): free depth also at U4 +- r*ex; sign of delta from the geometry: tan(delta) = -dh/du (u along board a), delta > 0 = walls converge towards +ex; warning if a magnet edge leaves the channel under d. Console only; no effect on the numbers.
2. Chamber path S4-S5 with a kink in board a: polyline - bisector of (a2 top, d) up to the cross-section through K_up, then straight to the mouth centre S5c. Changes only the kink cases: L45 -0.43 ... +1.98 % (typically +0.5 ... +1 %), total path -0.09 ... +0.17 %; S5 (derived from the volume equality 2*V45/L45 - S4) changes by -0.3 ... -19 % (large only where S5 is small).
3. Theoretical S4 with S4 in bend 6 uses the output Hornresp S5 (S5_HR): without a kink S4 = Ax + (Ax - S5_HR)*L2/Lk with S5_HR = S5_real - S1_HR + s1_eff (identical to before if S1 = auto); with a kink S4 = (Ax*(L2+Lk) - 2*(V45/L45)*L2)/(Lk - L2). Guard: rejection if |Lk - L2| <= 0.1 % of L45 (algebraic ill-conditioning: X0 is then the middle of the segment), note in the console if the amplification (L2+Lk)/|Lk-L2| exceeds 10. Changed case in the set: in_k3t80 (S4 +1.4 %). New cases: in_s4b_kink300, in_s4b_kink300_55, in_s4b_nokink500.
4. Fan volume / inertance integrate piece by piece (fan_pieces); gaps are counted and reported in the console (none in 29,387 samples of the review).
Known behaviour change: Kink = y, S1 = 800, S4 in bend 6 (test file A): 0.67 returned a result (S3 pos. 4), 0.68 does not; cause (ill-conditioned S4 formula near Lk = L2 for pos. 2-4, b' > B_MAX for pos. 6/7) is documented in TODO.md.

## 0.67
- D1 and D2 are bevelled at the mouth: the slopes of board a (a1 with a kink) and of board d now continue to the outer face of the front wall (before: horizontal over the wall thickness, i.e. a kink of the chamber wall).
  S5 is the vertical distance between the bevelled edges at the outer face. The mouth volume, the S4-S5 chamber polygon, the drawing and the cut list (D1/D2 with end angles and long face "outer"/"inner") follow.
  New rejection message if the bevelled edge would leave the box at the outer face.
- Effect (34 regression cases, baseline renewed, see baseline_v067.json): S1, S2, L12 unchanged; S5, L45 and the total path change (S5 up to 6 %, typically 0.1-3 %; L45 up to 0.5 %).
  In the 3 cases with S4 in bend 6 or a special S4 target (in_k3t80, in_s4_im_bogen45, in_s4_im_bogen55) S4, S3 and L23 change by at most 0.12 %.
- Leftover German key `"bogen"` in cone_data/cone_svg renamed to `"bend"` (no effect).
- Docstring: mouth note; version names current.

## 0.66
Renaming release (internal names in English), plus small fixes. The calculation is unchanged.
- All German identifiers, function names and internal dictionary keys are now English (full list: RENAMES_v0.66.md). Examples: `baue` -> `build`, `rechne` -> `compute`, `bogen_hand` -> `bend_hand`, `finde_nullstellen` -> `find_roots`, `FaltungsFehler` -> `FoldingError`, `EINHEIT` -> `UNIT`.
- Input names: the former German names (Breite, Hoehe, Tiefe, Holzstaerke, Verstrebungsbreite, Anfangslaenge, Modus, Steigung, Steigung2, Knick, Treiberdurchmesser, Treibertiefe, Con) are still accepted. The word `frei` is still accepted for S4 ("free").
- An error for a missing required value in a batch run now names the English internal key (e.g. 'depth' instead of 'tiefe').
- Console: the table "S3 positions compared" has a new column "S3/input" (calculated S3 area relative to the desired S3, mode 1 only). The column "Undershoot" is unchanged.
- Docstring: usage line names the current script name; author contact line added to the licence header.
- Verification against 0.65: 45 test inputs (31 solved, 14 with an error message), German and English input files, aliases, Hornresp import, interactive mode: SVG, cut list CSV, saved input file and Hornresp output byte-identical; console output identical except the new column and the error text above. Regression set (34 cases): 0 differences.
- SVG style names (CSS classes such as "luft", "quer", "faecher") are unchanged.

## 0.65
Cleanup release for the community test. The calculation is unchanged: on 45 test inputs (31 solved, 14 with an error message), a Hornresp import and the interactive mode, the console output (apart from the version number and the removed forum quote), SVG, cut list CSV, saved input file and Hornresp output were identical to 0.64.2. These are my own test inputs, not the regression set.
- Docstring corrected: current script name, command-line options added, input names completed (S5, DriverDiameter, DriverDepth, HornrespFile), L23 instead of Con.
- Version history moved to this file; the licence text is a separate comment header at the top of the script.
- Removed the unused function `_runde_pfad` and the unused entry `treiber_t` in the parameter dictionary `P`.
- German comment translated; the console note on the bend approximation no longer quotes a forum post.

## 0.64.2
Air-volume check and SVG now include the mouth aperture through the front wall (S5 at x=0).

## 0.64.1
Guard: a bend whose hand construction runs backwards (E0->A or B->X0 against the flow) is rejected; note texts corrected.

## 0.64
Adopts the reviewed improvements of the external audit "0.63" (root search with bracketing and residual check, stable inertance integral, validated Hornresp values, duplicate input keys rejected, missing required values in a batch run give an error, atomic file writing, cm/mm scaling of the search constants, actual-profile fix) on top of 0.62.1. Command line: input file, --batch, --output-dir, --no-save-input. Par model note; input Con renamed L23 (alias Con).

## 0.62.1
Robustness for the community test: input file may be UTF-8 or ANSI (cp1252); the console output no longer crashes with a narrow code page (Windows pipes); "lambda/4" instead of the Greek letter in the console text.

## 0.62
Cleanup: tuning constants collected in one block (search steps, margins, tolerances, warning threshold), unused variables and f-strings without placeholders removed. No change of results (regression test: 0 differences).

## 0.61
S1..S5 are cross-sections, no longer waypoints: the centreline runs S1c - (kink Kc) - S2c - A/B of the bends - B6 - S5c (the drawing shows the kink and no detour via S4c). S4 inside bend 6: cross-section = fan ray from C6 through the driver centre, path position = its crossing with the bend path, S4 for Hornresp = theoretical value (chamber line S4-S5 extended back through the built exit area of bend 6); volume S4-S5 built vs Hornresp is printed. The purple S4 line in the drawing starts at the driver centre, runs towards C6 and has the length of the calculated S4 (area / width). Volumes via liter(). Regression test in tests/ (34 inputs with reference values).

## 0.60
Slope guard (wedge angle <= ~80 deg, search limits capped); board ends (a, d) and the mouth are checked to lie inside the box (no more negative lengths); S5 and the Hornresp lengths L12/L34/L45 are comparison values like S4 (input 'S5' = number or auto; import from Hornresp fills them). Volume/inertance check also with the fan profile of the plot. Strong warning if S4 lies before B6 (note if inside bend 6); inertance/volume estimate for a kinked board a.

## 0.59.1
Cone plot with a kink: the actual curve uses the built S1/S5 and the kink as a support point (idealised/reference cone: Hornresp values); driver check on both sides of the driver on both faces of board a; Hornresp values converted if EINHEIT = "mm"; dead code removed.

## 0.59
Board a drawn as two boards a1/a2 with separate labels; clearer messages for kinked-board failures and when no driver diameter is given (kink then at the driver centre).

## 0.58
Hornresp text files: an exported single simulation (file argument or input 'HornrespFile') supplies S1-S5 and Con; the result is written to '<name>_Hornfolding.txt' with only S1-S5 and the four lengths replaced.

## 0.57
Board a with a kink as two boards a1/a2: kink half a driver diameter left of the driver centre; S1 is the Hornresp value, the real S1 follows from volume equality with a linear segment, S5 for Hornresp likewise from the volume S4-S5. New optional inputs DriverDiameter and DriverDepth (fit checks). Cut list with a1/a2.

## 0.56
Script renamed Hornfolding (input file Hornfolding_Input.txt; older names still found). SVG: box drawing across the full width (scale from the box depth), text below it, cone plots last.

## 0.55
Output names English (Hornfaltung_Input.txt, horn_folding.svg, horn_cutlist.csv; the old input file name is still found). S4 target: 'auto' = none ('free'/'frei' still accepted). Long face left empty when both ends are square. Slopes b and b' (and area gradients) as a separate block. Note on the driver volume corrected (Vtc is in front of the driver, S4/S5 behind it). SVG layout: box with results beside it, cone plot below, remaining text last.

## 0.54
Bend 6 gets the same validation as bends 1-5 (w1, w2 > 0; E0, A, B, X0, C, Ci, Cx, Q inside the box). If S4 lies before B6, the path S4 -> S5 is taken via B6 instead of as a chord.

## 0.53
Cosmetics (cut_a, docstring, y default). In-box check of bends now includes the cross-section ends and the outer corner. Diagnostic line 'S4 relative to the exit of bend 6' and a warning if S4 lies before B6.

## 0.52
Script language switched to English; input file names are English (German names are still accepted). S3 positions renumbered in flow order and extended to 7 (new: exit of bend 3). The right end of board d is now cut automatically so that the descent between d and b opens with the slope b' (positions 1-6), removing the area undershoot at the start of S3->S4. Cut list: gross length of the longest face plus end angles of every board (90 = square cut) instead of 'top / bottom' lengths.

## 0.51
S3 position 6 new (entry of bend 6, before the chamber). Selection 'auto': among the positions with Con within 10 % of the desired Con, the one with the smallest shortfall of the actual cone below the idealised cone is chosen (new column Shortf. in the position comparison). Bend points outside the box are discarded (no more spurious solutions), S3 must lie before S4.

## 0.50
New calculation core: no vertical heights and no calculation chain any more. The channel width (chord perpendicular to the centreline) follows the law W(s) = W2 + b*s along the centreline (after S3: b'); boards are exact rectangles with wedge angle 2*atan(b/2); bends are closed in turn. Mode 1: b = (S3/b1 - W2)/Con exactly. Drawing, cutting list and cone plot come from the same geometry. Boards c and d: with slanted ends cutting length 'top / bottom'. Fixes the width deviations of the chain for S3 positions 1-3 (up to 3.8 %). Compared with 0.29 (default input, position 5): S3, S4, path length, Con within 0.01 %, S5 -0.3 %.

## 0.30
New: unrolled horn profile (area over path along the centreline) below the box SVG: a) target (input/Hornresp; if a desired value is missing, the script value is used), b) idealised (calculated S1-S5 at the drawing stations), c) actual (straight sections: cross-section perpendicular to the centreline; bends: fan around the inner corner, one value per 1 cm of bend path, straight line from C through the path point to the outer wall), deviation c versus b. Pure evaluation, calculation unchanged.

## 0.29
Display only: smaller font for the labels in the SVG (fewer overlaps, readable in the vector graphic by zooming); markers S1-S5 slightly smaller. Calculation unchanged compared with 0.28.

## 0.28
Cross-sections and areas from the geometry. S2, S3, S4 are perpendicular to the centreline (bisector of the channel walls); S2/S4 pass through the driver centre on board a (x = length s4-s5), S3 always lies on the cross-section line of a bend (entry/exit, positions 1-7). The areas S2-S4 output are length of the line x net width from the drawing; S2 matches the input exactly (vertical starting height = S2/b1 * cos of half the inclination angle). S1/S5 (openings) vertical. Bend 4/5 from the geometry: inner corner C4 is the lower left corner of board c (end face inclined by the slope), bend 5 is solved via the position of the end of board d; the former approximation for the width of the right-hand rising channel is dropped (exit width of bend 5 was 1.5 % too small; now all bend widths model/drawing agree to 0.01 cm). New: distance of driver centre from D1 along board a (top/bottom side), volume check and inertia along the centreline, warning for cross-section ratio > 1.33 in the bend (Brian Steele: approximation uncertain there). Bend path: the hand construction (bogen_hand, used in chain and drawing) gives, for equal widths and every angle, centreline * (1 + cos(theta/2)) / 2 (re-calculated for 20-160 degrees); at 90 degrees that is the 25/75 scheme of the F20 data, for other angles an own generalisation not empirically confirmed. bogen_teile() (until 0.27 a closed formula that agreed with the hand construction only at 90 degrees and failed below 60 degrees) now calls the same hand construction. S2/S4: the driver centre lies on the median plane of board a at x = length s4-s5; S2 and S4 pass through opposite points of the board's underside/top side (one board thickness along the board normal, not on the same vertical). winkel4 with exact formula 90 + atan(b - b_mid)/2. The table of path parts is now called "Drawing / calculation chain". Cleaned up: dead parameters, duplicate assignments, faecher_punkte() removed. Litre figures also for mm. Note on λ/4 (largest bend cross-section). Note: driver/bracing volume is not subtracted. If no b' solution exists, boundary values.

## 0.27
Clean-up: the path allowance between bend 4 and 5 is calculated once (the former loop has been superfluous since the geometric widths). _schnitt() reports (almost) parallel lines as an error instead of huge coordinates. Results unchanged.

## 0.26
Board d has thickness a perpendicular to the board (in the calculation: vertical height a/cos of the inclination; chamber height S4 and mouth S5 thus agree with the drawing). The path between bend 4 and bend 5 is calculated as in the drawing along the centreline from cross-section centre to cross-section centre (the slanted cross-sections make it longer than the horizontal distance); this affects the channel widths from bend 5 onwards. B6-S4 in the section table from the geometry.

## 0.25
Calculation and drawing are now the same construction: the bend lengths in the folding chain (bends 1-5) come from the hand construction (cross-sections perpendicular to the bisector of the channel walls, also with inclined d). The path lengths output (S1-S2, Con S2-S3, S3-S4, S4-S5, total) are the lengths of the drawn centreline; bend 6 comes from the drawing. Check line: Con calculation chain versus Con of the drawing. b' consistency uses the drawn path length S3-S4.

## 0.24
SVG: bends drawn according to the hand construction: cross-sections in each bend perpendicular to the bisector of the two channel walls (centreline), fan auxiliary lines C-O1/C-O2 with O = midpoint between cross-section end and outer corner, centreline A-B from the intersection points. Board d is a true rectangle (end sawn at a right angle, thickness measured perpendicular); C6 therefore lies to the left of C5 when d is inclined. New table: path parts per bend, hand construction versus formula. The calculation (formulas, S1-S5, path lengths) is unchanged.

## 0.23
Input: always the same file Hornfaltung_Eingabe.txt (overwritten on every run), confirm each value from it with Enter or overwrite it; input errors (also y/n) are asked for again. b' is calculated from the box (S4 = S3 + b1*b'*Path S3-S4) instead of guessed; S4 from Hornresp is now only a comparison value; negative slopes allowed. Root finding ignores invalid geometries (no sign changes across gaps). S4 is measured exactly at the driver centre (previously at the board edge; small change). SVG: fan construction of each bend at the right place in the folding drawing (no separate bend file any more), path as polyline A-B, cross-sections S1-S5 dashed, board a optionally with a kink at S2 (switch Kink). Path lengths S1-S2 and S4-S5 are now lengths of the centreline between the cross-section centres (hypot of length and height difference) instead of the axis-parallel length; the centreline in the SVG runs through the centres of all five cross-sections.

## 0.22
Slope change at S3: five selectable S3 positions, slope b' after S3, S4 target (solves b' for position 1/2), comparison table of the positions, choice according to desired Con. Angle in bend 4 (D2 -> d) from the board inclinations (90 degrees - (atan b' - atan b)/2 with slope change). Path parts per bend and total path in console and SVG; additional file horn_boegen.svg with the bend construction of each bend. With S3 position 5 and any b' the following holds: results unchanged compared with 0.21.

## 0.21
Boards labelled (capital letters = outer walls, lower-case letters = inner boards, in flow direction; a = baffle) and cutting list (console, SVG, CSV next to the script). Board a runs through without a kink at S2 in the drawing (S1 applies only to the simulation). Outer walls drawn butt-jointed (floor/ceiling continuous, B/D in between).

## 0.20
bogenweg(): generalisation to other angles now as the fan construction of the comparison graphic (A/B = centres of the cross-sections through the inner corner) instead of the bisection assumption from 0.19. Unchanged at 90 degrees, results equal.

## 0.19
Bend path as its own function bogenweg(w_ein, w_aus, winkel) with arbitrary bend angle (prepared for non-right-angled bends). At 90 degrees exactly the same formula as before, results are unchanged (checked). All three places with the bend formula (fold, x6 step, path S3-S4) use it.

## 0.18
CALCULATION CHANGED (folds 1 and 2): The corner area of a bend is a rectangle of channel width BEFORE the bend x channel width AFTER the bend. The following straight section therefore starts at the height/width before the bend (previously: after the bend). The channel keeps growing in the bend, the width after the bend is unchanged: width before + b x bend path. Consequence (example 55x100x72.3, b=0.1): S3 +0.7 %, S4 -0.8 %, S5 -0.7 %. SVG: inner boards stand perpendicular to each other at every bend and are built butt-jointed (no overlap); offset marks A/B dropped.

## 0.17
Input from file; last inputs are saved automatically; version number is displayed; SVG: offsets A/B marked and explained at bends 1 and 2. The calculation is unchanged.

## 0.16
Check for finite numbers in zahl() (user).

## 0.15
SVG drawing (self-contained section 'SVG-AUSGABE', needs only the dictionary g); S1 is asked for after the slope (suggestion from S2 and slope, overridable); drawing is saved next to the script.

## 0.14
Root finding instead of grid, error messages, units in the dialogue (details below).

## 0.13
Initial version (grid with tolerance).
