From a706a610f7171dcb9d6409fa1b25f50227a6fa59 Mon Sep 17 00:00:00 2001 From: Cameron Brooks <95648474+CameronBrooks11@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:44:07 -0500 Subject: [PATCH 1/2] fix: fit the tower section labels to their faces The temperature, retraction and flow towers sized each section label from the section height alone, so every label in their examples was wider than the face it is carved into: 9.1 to 11.6 mm on faces of 8.0 and 8.4 mm. A printed tower lost the label's first and last strokes off the edges ("180C" read as "80C"). Each label now shrinks, when it has to, until it spans at most 90% of its face, measured with textmetrics(). An assert stops the render if a label still overruns, so just test catches a regression: with the fit disabled it fails on "220C". OpenSCAD 2021.01, which has no textmetrics(), keeps the old size. --- src/flowtower.scad | 14 +++++++++++++- src/retracttower.scad | 14 +++++++++++++- src/temptower.scad | 14 +++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/flowtower.scad b/src/flowtower.scad index 1805b7a..e92fb3e 100644 --- a/src/flowtower.scad +++ b/src/flowtower.scad @@ -132,6 +132,12 @@ module generate_section( } // Generate the text that will be carved into the square section column +// The font size, at most `size`, at which `txt` is no wider than `width`. Where +// textmetrics() is missing (OpenSCAD 2021.01) it returns `size` unchanged. +function flow_label_size(txt, size, font, width) = + let (w = textmetrics(text=txt, size=size, font=font).size[0]) + is_undef(w) || w <= width ? size : size * width / w; + module generate_section_label( label, section_size, @@ -144,6 +150,12 @@ module generate_section_label( section_label_font_size ) { full_label = str(section_label_prefix, label, section_label_suffix); + // The label may span 90% of the face it is carved into. + label_width = section_size * 0.9; + label_size = flow_label_size(full_label, section_label_font_size, font, label_width); + fitted_width = textmetrics(text=full_label, size=label_size, font=font).size[0]; + assert(is_undef(fitted_width) || fitted_width <= label_width + 1e-3, + str("section label \"", full_label, "\" is wider than its face")); translate([-section_size / 2, -section_size, section_size / 2]) rotate([90, 0, 0]) translate([0, 0, -label_depth]) @@ -151,7 +163,7 @@ module generate_section_label( text( text=full_label, font=font, - size=section_label_font_size, + size=label_size, halign="center", valign="center" ); diff --git a/src/retracttower.scad b/src/retracttower.scad index 3bdcc7c..e3d7a1e 100644 --- a/src/retracttower.scad +++ b/src/retracttower.scad @@ -123,6 +123,12 @@ module generate_retract_round_column(cube_size, cap_size, cap_height, wall_thick } // Generate the section label carved into the square column +// The font size, at most `size`, at which `txt` is no wider than `width`. Where +// textmetrics() is missing (OpenSCAD 2021.01) it returns `size` unchanged. +function retract_label_size(txt, size, font, width) = + let (w = textmetrics(text=txt, size=size, font=font).size[0]) + is_undef(w) || w <= width ? size : size * width / w; + module generate_retract_section_label( label, section_label_prefix, @@ -135,6 +141,12 @@ module generate_retract_section_label( iota ) { full_label = str(section_label_prefix, label, section_label_suffix); + // The label may span 90% of the face it is carved into. + label_width = cube_size * 0.9; + label_size = retract_label_size(full_label, section_label_font_size, font, label_width); + fitted_width = textmetrics(text=full_label, size=label_size, font=font).size[0]; + assert(is_undef(fitted_width) || fitted_width <= label_width + 1e-3, + str("section label \"", full_label, "\" is wider than its face")); translate([-tower_width / 2 + cube_size / 2, -cube_size / 2 - iota, cube_size / 2]) rotate([90, 0, 0]) translate([0, 0, -label_depth]) @@ -142,7 +154,7 @@ module generate_retract_section_label( text( text=full_label, font=font, - size=section_label_font_size, + size=label_size, halign="center", valign="center" ); diff --git a/src/temptower.scad b/src/temptower.scad index eff92e2..c6dcb51 100644 --- a/src/temptower.scad +++ b/src/temptower.scad @@ -152,6 +152,12 @@ module generate_temp_right_bridge_support( } // Generate the section label carved into the left column +// The font size, at most `size`, at which `txt` is no wider than `width`. Where +// textmetrics() is missing (OpenSCAD 2021.01) it returns `size` unchanged. +function temp_label_size(txt, size, font, width) = + let (w = textmetrics(text=txt, size=size, font=font).size[0]) + is_undef(w) || w <= width ? size : size * width / w; + module generate_temp_section_label( label, section_label_prefix, @@ -164,6 +170,12 @@ module generate_temp_section_label( iota ) { full_label = str(section_label_prefix, label, section_label_suffix); + // The label may span 90% of the face it is carved into. + label_width = cube_size * 0.9; + label_size = temp_label_size(full_label, section_label_font_size, font, label_width); + fitted_width = textmetrics(text=full_label, size=label_size, font=font).size[0]; + assert(is_undef(fitted_width) || fitted_width <= label_width + 1e-3, + str("section label \"", full_label, "\" is wider than its face")); translate([-tower_width / 2 + cube_size / 2, -cube_size / 2 - iota, cube_size / 2]) rotate([90, 0, 0]) translate([0, 0, -label_depth]) @@ -171,7 +183,7 @@ module generate_temp_section_label( text( text=full_label, font=font, - size=section_label_font_size, + size=label_size, halign="center", valign="center" ); From b77f58325502c0f4305e81f254ba86713378cbf6 Mon Sep 17 00:00:00 2001 From: Cameron Brooks <95648474+CameronBrooks11@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:46:27 -0500 Subject: [PATCH 2/2] ci: check on OpenSCAD 2026.10.15, where textmetrics() is built in The label fit uses textmetrics(), which the 2026.08.19 snapshot still treats as experimental: CI's --hardwarnings render stopped on that warning. CI now pins 2026.10.15, the snapshot the docs engine uses. On 2026.08.19 without --hardwarnings the flow tower example still renders (exit 0): textmetrics() warns, the fit returns the full font size (3.3688), and the labels keep their old size. The README says so. --- .github/workflows/ci.yml | 7 ++++--- README.md | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8594760..6b7858a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,12 +21,13 @@ jobs: steps: - uses: actions/checkout@v7 - # A pinned snapshot, the OpenSCAD these examples are checked on. + # A pinned snapshot, the OpenSCAD these examples are checked on: 2026.10.15 or + # later, where textmetrics() is no longer experimental. - name: Install OpenSCAD snapshot and just # The AppImage and its checksum; update both together. env: - OPENSCAD_SNAPSHOT: OpenSCAD-2026.08.19-x86_64.AppImage - OPENSCAD_SHA256: fdd818025e890f465ffacffbe7d0c6fa3ebeb3f7c18ee860a909ab41396be643 + OPENSCAD_SNAPSHOT: OpenSCAD-2026.10.15-x86_64.AppImage + OPENSCAD_SHA256: 9d26e390d3a5c94f2e304d94d7b2eff77fb11fcd25829f2814de147ba92ac363 run: | set -euo pipefail sudo apt-get update -qq diff --git a/README.md b/README.md index 6ec95e2..aca943e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,13 @@ examples/ torture_test_examples/ -- torture test example ``` +## OpenSCAD version + +The towers fit each section label to its face with `textmetrics()`, built in +from the OpenSCAD 2026.10.15 development snapshot. Earlier versions warn that +the function is missing or experimental and carve the labels at their full +size, which can run off the face. + ## Quality / rendering All examples set `$fn` based on `$preview`: