diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index ece75ea..f5e7cdb 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2026-10-10 00:10:32 UTC using RuboCop version 1.91.0.
+# on 2026-12-02 05:27:22 UTC using RuboCop version 1.91.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -43,7 +43,7 @@ RSpec/ExampleLength:
RSpec/MessageSpies:
EnforcedStyle: receive
-# Offense count: 42
+# Offense count: 47
RSpec/MultipleExpectations:
Max: 4
diff --git a/app/assets/stylesheets/generator.css b/app/assets/stylesheets/generator.css
index 7f52439..7945dad 100644
--- a/app/assets/stylesheets/generator.css
+++ b/app/assets/stylesheets/generator.css
@@ -29,6 +29,7 @@
.stage .top { fill: var(--birch-light); }
.stage .left { fill: var(--birch); }
.stage .right { fill: var(--birch-dark); }
+.stage .tilted { fill: color-mix(in oklab, var(--birch-light) 55%, var(--birch)); }
.stage .inside { stroke: #2a1a0c; stroke-width: 1; }
.stage .floor { fill: #6b5231; }
.stage .far { fill: #a98a57; }
@@ -44,12 +45,19 @@
.panel {
position: relative; margin: 0;
background: var(--panel); border-top: 3px solid var(--amber); border-bottom: 1px solid var(--rule);
- display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.35fr) minmax(0, 1.2fr) minmax(0, 1.3fr) minmax(140px, 1.1fr);
+ /* The choices, the three sides, thickness, notch, Generate. */
+ display: grid; grid-template-columns: minmax(max-content, 1.3fr) repeat(3, minmax(0, 1fr)) minmax(0, 1.35fr) minmax(0, 1.2fr) minmax(140px, 1.1fr);
}
-.hint { position: absolute; left: var(--gutter); bottom: calc(100% + 10px); margin: 0; font-size: 14px; color: var(--alarm); }
+/* Why the box cannot be made: a bright red pill above the strip. */
+.hint {
+ position: absolute; left: var(--gutter); bottom: calc(100% + 10px); margin: 0; max-width: calc(100% - 2 * var(--gutter));
+ padding: 6px 16px; border-radius: 99px; background: var(--error); color: #fff; font-size: 14px; font-weight: 700; line-height: 1.35;
+ box-shadow: 0 2px 10px rgb(0 0 0 / 0.35);
+}
+.hint:empty { display: none; }
.field { position: relative; padding: 16px clamp(12px, 1.5vw, 22px) 14px; border-right: 1px solid var(--rule); display: grid; gap: 10px; align-content: start; }
-.field > label { font-size: 13px; color: var(--mute); font-stretch: 110%; cursor: ew-resize; user-select: none; touch-action: none; display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; overflow: hidden; }
+.field > label { font-size: 13px; color: var(--mute); font-stretch: 110%; cursor: move; user-select: none; touch-action: none; display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; overflow: hidden; }
.field > label i { font-style: normal; opacity: 0; transition: opacity 0.15s; white-space: nowrap; }
.field:hover > label i, .field:focus-within > label i { opacity: 0.7; }
.num { display: flex; align-items: baseline; gap: 6px; }
@@ -73,7 +81,24 @@
font-size: 13px; color: var(--soft); cursor: pointer;
}
.chips button:hover, .more:hover, .pick select:hover { border-color: var(--soft); }
-.field .restart { justify-self: start; white-space: nowrap; }
+/* Wraps to "Reset to / defaults" when the Width cell is too narrow for one line. */
+.field .restart { text-align: left; border-radius: 14px; }
+.reset { position: relative; justify-self: start; }
+/* Reset, and the Yes that carries it out, warn in red. */
+.field .restart:hover, .field .restart[aria-expanded="true"], .reset .yes:hover { color: var(--error); border-color: var(--error); }
+/* The popup sits to the right of Reset, over the next cell, with a point towards the button. */
+.reset .confirm {
+ position: absolute; z-index: 5; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
+ display: flex; align-items: center; gap: 6px; white-space: nowrap;
+ padding: 6px 8px 6px 12px; border: 1px solid var(--edge); border-radius: 12px;
+ background: var(--sheet); box-shadow: 0 4px 16px rgb(0 0 0 / 0.45); font-size: 13px; color: var(--soft);
+}
+.reset .confirm[hidden] { display: none; }
+.reset .confirm::before {
+ content: ""; position: absolute; left: -6px; top: 50%; width: 10px; height: 10px;
+ background: var(--sheet); border-left: 1px solid var(--edge); border-bottom: 1px solid var(--edge);
+ transform: translateY(-50%) rotate(45deg);
+}
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.side { padding: 14px clamp(12px, 1.5vw, 22px); border-right: 1px solid var(--rule); display: grid; gap: 8px; align-content: center; justify-items: start; }
@@ -83,8 +108,17 @@
.seg input:checked + span { background: var(--ink); color: var(--panel); }
.seg input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }
.pick select { padding: 4px 10px; max-width: 100%; }
+/* The column is as wide as its longest option; both dropdowns fill it, so they line up. */
+.side .pick { justify-self: stretch; }
+.side .pick select { width: 100%; }
.pick select option { background: var(--panel); color: var(--ink); }
-.soon { color: var(--mute); font-size: 12.5px; line-height: 1.3; }
+
+/* The slope and front height of a sloped box: a row of its own under the strip, after Generate. */
+.sloped { grid-column: 1 / -1; order: 1; display: grid; grid-template-columns: subgrid; border-top: 1px solid var(--rule); }
+.sloped[hidden] { display: none; }
+/* A text input is twenty characters wide unless told otherwise; without this the Slope input would widen the choices column. */
+.sloped > .field { contain: inline-size; }
+.sloped .note { grid-column: 3 / -1; margin: 0; padding: 16px clamp(12px, 1.5vw, 22px); align-self: center; max-width: 72ch; font-size: 13px; line-height: 1.4; color: var(--mute); }
.go {
background: var(--beam); color: #160a04; border: 0; cursor: pointer;
@@ -101,14 +135,28 @@
/* As tall as the drawing needs and no taller, so no empty band above and below it. */
.stage { height: auto; min-height: 0; margin-top: 8px; }
.stage svg { height: auto; max-height: 50vh; }
- .panel { grid-template-columns: repeat(3, 1fr); }
- .field.thickness { grid-column: span 2; }
- .side, .go { grid-column: span 3; }
- .field.thickness, .field.notch, .side, .go { border-top: 1px solid var(--rule); }
- .side { grid-auto-flow: column; justify-content: start; align-items: center; gap: 10px 14px; grid-auto-flow: row; }
+ /* Twelve columns: three sides in fourths, then thickness and notch, with slope and front height between them. */
+ .panel { grid-template-columns: repeat(12, minmax(0, 1fr)); }
+ .panel > .field { grid-column: span 4; }
+ .field.thickness { grid-column: span 8; }
+ .side, .go, .sloped .note { grid-column: 1 / -1; }
+ .sloped { display: contents; }
+ .sloped[hidden] { display: none; }
+ .sloped:not([hidden]) > .field,
+ .panel:has(.sloped:not([hidden])) .field.thickness,
+ .panel:has(.sloped:not([hidden])) .field.notch { grid-column: span 3; }
+ /* Every control comes before Generate. */
+ .field.notch { order: 1; }
+ .sloped .note { order: 2; }
+ .go { order: 3; }
+ /* The choices come first, so every row under them gets a rule. */
+ .panel > .field, .sloped > .field, .go { border-top: 1px solid var(--rule); }
+ /* Above the measurements, the choices sit in one line beside the units pill, wrapping only when there is no room. */
+ .side { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
+ .side .pick select { width: auto; }
.go { padding: 18px; }
- .hint { position: static; grid-column: span 3; padding: 8px var(--gutter) 0; }
- .hint:empty { display: none; }
+ .hint { position: static; grid-column: 1 / -1; justify-self: start; margin: 10px var(--gutter) 0; max-width: none; border-radius: 18px; }
+ .sloped .note { grid-column: 1 / -1; padding-top: 0; }
}
/* A phone-width Width cell only has room for "Reset". */
@@ -116,8 +164,8 @@
.field .restart .wide { display: none; }
}
-/* On a phone, a slim Generate bar sits above the controls instead of below them. */
+/* On a phone, Generate is a slim bar under the controls. */
@media (max-width: 640px) {
- .go { order: -1; padding: 9px 14px; font-size: 18px; border-top: 0; }
+ .go { padding: 9px 14px; font-size: 18px; }
.go small { display: none; }
}
diff --git a/app/assets/stylesheets/tokens.css b/app/assets/stylesheets/tokens.css
index 7e6c9bc..a519fb7 100644
--- a/app/assets/stylesheets/tokens.css
+++ b/app/assets/stylesheets/tokens.css
@@ -37,7 +37,7 @@
--beam: #ff5a2b; /* the laser */
--amber: #ffb53d; /* the accent: headings, edges, whatever is being edited */
--alarm: #ff7a6b;
- --error: #ff2020;
+ --error: #ff2020; /* the error pill */
--birch: #e2c48f; /* plywood */
--birch-light: #efd9aa;
--birch-dark: #c4a269;
diff --git a/app/controllers/boxes_controller.rb b/app/controllers/boxes_controller.rb
index 96cf90d..be8d450 100644
--- a/app/controllers/boxes_controller.rb
+++ b/app/controllers/boxes_controller.rb
@@ -12,7 +12,7 @@ class BoxesController < ApplicationController
# ActionController::Live's own thread, which Rack::Timeout never interrupts.
RENDER_SECONDS = 20
- PERMITTED = (BoxRequest::DIMENSIONS + BoxRequest::OPTIONAL + %i[units page_size page_layout metadata lid]).freeze
+ PERMITTED = (BoxRequest::DIMENSIONS + BoxRequest::OPTIONAL + BoxRequest::SLOPED + %i[units page_size page_layout metadata lid]).freeze
# Draws the SVG, reporting progress as it goes and sending the drawing last.
def stream
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 6885f0d..ebea567 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -3,9 +3,8 @@
class HomeController < ApplicationController
def index
@settings = {
- defaults: BoxRequest.defaults,
- pageSizes: BoxRequest.page_sizes,
- lidsSupported: BoxRequest.lids_supported?
+ defaults: BoxRequest.defaults,
+ pageSizes: BoxRequest.page_sizes
}
end
end
diff --git a/app/javascript/controllers/generator_controller.js b/app/javascript/controllers/generator_controller.js
index 6e2133c..6056d03 100644
--- a/app/javascript/controllers/generator_controller.js
+++ b/app/javascript/controllers/generator_controller.js
@@ -1,5 +1,7 @@
import { Controller } from "@hotwired/stimulus"
import { isoBox, tabCount } from "lib/iso_box"
+import { isoSlopedBox } from "lib/iso_sloped_box"
+import { slopedProfile, slopeProblem } from "lib/sloped_profile"
import { load, trace } from "lib/laser_trace"
const STORAGE_KEY = "makeabox:settings:v1"
@@ -10,7 +12,10 @@ const STOCK = {
in: [["1/8″", 0.125], ["3/16″", 0.1875], ["1/4″", 0.25]],
mm: [["3 mm", 3], ["4.5 mm", 4.5], ["6 mm", 6]]
}
-const STEP = { in: { side: 0.25, thickness: 0.005, notch: 0.05 }, mm: { side: 5, thickness: 0.1, notch: 1 } }
+const STEP = { in: { side: 0.25, thickness: 0.005, notch: 0.05, slope: 1 }, mm: { side: 5, thickness: 0.1, notch: 1, slope: 1 } }
+// A sloped box starts at 45° from a front this share of the height. A sloped
+// box has no lid with tabs along the back (BoxRequest::SLOPED_LIDS).
+const SLOPE_START = { slope: 45, front: 0.4 }
// The narrowest notch worth cutting. The widest is a third of the shortest
// side; on a box too small for both, the narrowest is half the widest. Both
// ends are rounded down to NOTCH_SCALE, exactly as BoxRequest does.
@@ -27,8 +32,8 @@ const KERF_FIT = {
green: ["About just right", "About just right"]
}
const KERF_STEP = { in: 0.0005, mm: 0.01 }
-// What "Reset to defaults" under Width puts back, in inches.
-const STARTING_BOX = { width: 5, height: 4, depth: 3, thickness: 0.125, kerf: 0.026 }
+// What "Reset to defaults" under Width puts back, in inches, with a closed upright box.
+const STARTING_BOX = { width: 5, height: 4, depth: 3, thickness: 0.25, kerf: 0.026 }
const TRACE_MS = 1500
const clean = (number) => Number(number.toFixed(4))
@@ -49,7 +54,8 @@ const label = (key) => (key === "thickness" ? "Thickness" : key[0].toUpperCase()
export default class extends Controller {
static targets = ["preview", "form", "hint", "number", "unit", "chips", "range", "units", "lid", "settings", "optional", "pageSize",
"go", "cut", "cutTitle", "cutMaterial", "drawing", "specs", "phase", "count", "bar", "download",
- "kerfSlider", "kerfFit", "metadata"]
+ "kerfSlider", "kerfFit", "metadata", "shape", "sloped", "slope", "frontHeight",
+ "restart", "confirm"]
static values = { settings: Object, streamUrl: String, downloadUrl: String, countUrl: String }
connect() {
@@ -88,15 +94,32 @@ export default class extends Controller {
return query.toString()
}
+ get sloped() {
+ return this.shapeTarget.value === "sloped"
+ }
+
problem() {
for (const key of [...SIDES, "thickness"]) if (!(this.number(key) > 0)) return `${label(key)} needs a number above zero.`
if (this.number("thickness") >= Math.min(...SIDES.map((key) => this.number(key)))) return "Thickness has to be smaller than the shortest side of the box."
+ const slope = this.slopeProblem()
+ if (slope) return slope
if (this.notchProblem()) return `Notch length has to be between ${this.notchRange().join(" and ")} ${this.unit}, or blank to let makeabox choose.`
const notches = tabCount(Math.max(...SIDES.map((key) => this.number(key))), this.number("notch") || 3 * this.number("thickness"))
if (notches > MAX_NOTCHES) return `That is ${notches} notches along the longest side, and ${MAX_NOTCHES} is the most we draw. Use thicker material or a longer notch.`
return ""
}
+ slopeProblem() {
+ if (!this.sloped) return ""
+ return slopeProblem({ height: this.number("height"), depth: this.number("depth"), thickness: this.number("thickness"), slope: parse(this.fields.slope),
+ frontHeight: parse(this.fields.front_height), lid: this.lidTarget.value, unit: this.unit })
+ }
+
+ get profile() {
+ return slopedProfile({ depth: this.number("depth"), height: this.number("height"), frontHeight: parse(this.fields.front_height),
+ slope: parse(this.fields.slope), thickness: this.number("thickness") })
+ }
+
// [narrowest, widest] notch, the same numbers as BoxRequest#notch_range.
notchRange() {
const scale = NOTCH_SCALE[this.unit], down = (value) => Math.floor(value * scale + 1e-6) / scale
@@ -116,7 +139,8 @@ export default class extends Controller {
}
clamp(key, value) {
- const [low, high] = key === "notch" ? this.notchRange() : [this.step(key), Infinity]
+ const bounds = { notch: () => this.notchRange(), slope: () => [1, 89], front_height: () => [0, Math.max(0, this.number("height") - this.step(key))] }
+ const [low, high] = bounds[key]?.() ?? [this.step(key), Infinity]
return clean(Math.min(high, Math.max(low, value)))
}
@@ -126,6 +150,17 @@ export default class extends Controller {
this.refresh()
}
+ // Upright or sloped. A sloped box starts from SLOPE_START, and swaps the
+ // lid with tabs along the back, which it cannot have, for the closed box.
+ reshape() {
+ if (this.sloped) {
+ if (this.slopeTarget.value === "") this.slopeTarget.value = SLOPE_START.slope
+ if (this.frontHeightTarget.value === "") this.frontHeightTarget.value = clean(this.number("height") * SLOPE_START.front)
+ if (this.lidTarget.value === "back") this.lidTarget.value = "full"
+ }
+ this.refresh()
+ }
+
focus(event) {
this.hot = event.target.closest("[data-key]").dataset.key
event.target.select()
@@ -146,15 +181,17 @@ export default class extends Controller {
this.refresh()
}
- // Dragging a label left or right changes its number.
+ // Dragging a label changes its number: right or up for more, left or down
+ // for less, by whichever way the pointer has moved further.
scrub(event) {
const label = event.currentTarget, key = label.closest("[data-key]").dataset.key, input = this.input(key)
- const from = event.clientX, base = this.start(key)
+ const [fromX, fromY] = [event.clientX, event.clientY], base = this.start(key)
event.preventDefault()
label.setPointerCapture(event.pointerId)
this.hot = key
const move = (drag) => {
- input.value = this.clamp(key, base + Math.round((drag.clientX - from) / 6) * this.step(key))
+ const [dx, dy] = [drag.clientX - fromX, fromY - drag.clientY]
+ input.value = this.clamp(key, base + Math.round((Math.abs(dy) > Math.abs(dx) ? dy : dx) / 6) * this.step(key))
this.refresh()
}
label.addEventListener("pointermove", move)
@@ -171,12 +208,41 @@ export default class extends Controller {
this.refresh()
}
- // Back to a 5 × 4 × 3 in box of 1/8″ material with the default kerf.
- // Everything else on the form is left as it is.
+ // Reset opens a popup that asks before the box is thrown away; a second click closes it.
+ ask() {
+ this.confirming(this.confirmTarget.hidden)
+ }
+
+ // No, or Escape: close the popup and go back to Reset.
+ keep() {
+ if (this.confirmTarget.hidden) return
+ this.confirming(false)
+ this.restartTarget.focus()
+ }
+
+ // A click anywhere outside Reset and its popup closes the popup.
+ dismiss(event) {
+ if (!this.confirmTarget.hidden && !event.target.closest(".reset")) this.confirming(false)
+ }
+
+ // Opens or closes the popup. Open, No has the focus, so a stray Enter keeps the box.
+ confirming(open) {
+ this.confirmTarget.hidden = !open
+ this.restartTarget.setAttribute("aria-expanded", String(open))
+ if (open) this.confirmTarget.querySelector(".no").focus()
+ }
+
+ // Back to a closed, upright 5 × 4 × 3 in box of 1/4″ material with the default kerf.
+ // The slope fields are emptied, so a sloped front starts afresh. Everything
+ // else on the form is left as it is.
restart() {
+ this.confirming(false)
if (this.unit !== "in") this.pageSizeTarget.value = "" // a page size in mm has no match in inches
this.unitsTargets.forEach((radio) => { radio.checked = radio.value === "in" })
for (const [key, value] of Object.entries(STARTING_BOX)) this.input(key).value = value
+ this.lidTarget.value = "full"
+ this.shapeTarget.value = "upright"
+ this.slopeTarget.value = this.frontHeightTarget.value = ""
this.refresh()
}
@@ -191,7 +257,7 @@ export default class extends Controller {
const to = event.target.value
if (to === this.unit) return
const factor = to === "mm" ? MM_PER_INCH : 1 / MM_PER_INCH, digits = to === "mm" ? 2 : 4
- for (const input of [...this.numberTargets, ...this.optionalTargets]) {
+ for (const input of [...this.numberTargets, ...this.optionalTargets, this.frontHeightTarget]) {
const value = parse(input.value)
if (Number.isFinite(value)) input.value = Number((value * factor).toFixed(digits))
}
@@ -222,6 +288,7 @@ export default class extends Controller {
reset() {
try { localStorage.removeItem(STORAGE_KEY) } catch (error) { /* storage is optional */ }
this.formTarget.reset()
+ this.slopeTarget.value = this.frontHeightTarget.value = ""
this.unit = "in"
this.refresh()
}
@@ -245,6 +312,7 @@ export default class extends Controller {
})
this.pageSizes(unit)
this.kerf(unit)
+ this.shapeFields()
this.numberTargets.forEach((input) => input.closest(".field").classList.toggle("bad", !(parse(input.value) > 0)))
this.rangeTarget.textContent = this.notchRange()[1] > 0 ? `${this.notchRange().join(" to ")} ${unit}` : ""
this.rangeTarget.closest(".field").classList.toggle("bad", this.notchProblem())
@@ -290,6 +358,17 @@ export default class extends Controller {
this.kerfFitTarget.dataset.zone = zone
}
+ // Disabled fields are left out of the form, so an upright box sends no slope.
+ shapeFields() {
+ const sloped = this.sloped
+ this.slopedTarget.hidden = !sloped
+ this.slopeTarget.disabled = this.frontHeightTarget.disabled = !sloped
+ this.lidTarget.querySelector('option[value="back"]').disabled = sloped
+ const bad = (input) => input.closest(".field").classList.toggle("bad", sloped && !(parse(input.value) >= 0))
+ bad(this.slopeTarget)
+ bad(this.frontHeightTarget)
+ }
+
pageSizes(unit) {
const select = this.pageSizeTarget
if (select.dataset.unit === unit) return
@@ -303,10 +382,14 @@ export default class extends Controller {
// so many notches that building the preview stalls the page.
draw() {
if (this.problem()) return
- const { viewBox, markup } = isoBox({
+ const box = {
width: this.number("width"), height: this.number("height"), depth: this.number("depth"), thickness: this.number("thickness"),
- notch: this.number("notch"), units: this.unit, lid: this.lidTarget.value, hot: this.hot
- })
+ notch: this.number("notch"), units: this.unit, lid: this.lidTarget.value, hot: this.hot === "front_height" ? "frontHeight" : this.hot
+ }
+ const profile = this.sloped && this.profile
+ const { viewBox, markup } = profile
+ ? isoSlopedBox({ ...box, frontHeight: parse(this.fields.front_height), slope: parse(this.fields.slope) }, profile, tabCount)
+ : isoBox(box)
this.previewTarget.setAttribute("viewBox", viewBox)
this.previewTarget.classList.toggle("hot-thickness", this.hot === "thickness" || this.hot === "notch")
this.previewTarget.innerHTML = markup // numbers and fixed class names only, see iso_box.js
@@ -323,6 +406,11 @@ export default class extends Controller {
const unit = saved.units === "mm" ? "mm" : "in"
this.unitsTargets.forEach((radio) => { radio.checked = radio.value === unit })
this.pageSizes(unit) // the saved page size needs its option to exist first
+ // Only a sloped box saves a slope: an upright one leaves the fields disabled.
+ if (saved.slope !== undefined) {
+ this.shapeTarget.value = "sloped"
+ this.shapeFields()
+ }
for (const [key, value] of Object.entries(saved)) {
if (key === "metadata") { this.metadataTarget.checked = value !== "0"; continue }
const field = this.input(key)
@@ -383,6 +471,7 @@ export default class extends Controller {
this.cutMaterialTarget.textContent = `${this.number("thickness")} ${unit} material`
const rows = [["Inside", `${sides} ${unit}`], ["Material", `${this.number("thickness")} ${unit}`], ["Notch length", tab],
["Top", this.lidTarget.selectedOptions[0].textContent], ["Page", this.pageSizeTarget.value || "fits the box"]]
+ if (this.sloped) rows.splice(1, 0, ["Front", `${parse(this.fields.front_height)} ${unit}, sloping back at ${parse(this.fields.slope)}°`])
this.specsTarget.replaceChildren(...rows.flatMap(([term, detail]) => {
const dt = document.createElement("dt"), dd = document.createElement("dd")
dt.textContent = term
diff --git a/app/javascript/lib/iso_sloped_box.js b/app/javascript/lib/iso_sloped_box.js
new file mode 100644
index 0000000..292f02a
--- /dev/null
+++ b/app/javascript/lib/iso_sloped_box.js
@@ -0,0 +1,125 @@
+// Draws the isometric preview of a box whose front slopes back: the right
+// side wall, the front strip, the tilted panel and the top strip, with finger
+// joints and the dimensions. For a lid that lifts off, the tilted panel floats
+// up off the box. Pure geometry, no state.
+//
+// Library modules here import nothing (importmap pins them by bare name, which
+// the test bundler cannot resolve), so the caller passes in the profile from
+// slopedProfile() and tabCount from iso_box.js. The projection matches
+// iso_box.js, so both boxes draw at the same scale.
+
+const COS30 = Math.cos(Math.PI / 6)
+const SCALE = 100
+
+const project = (x, y, z) => [(x - y) * COS30 * SCALE, ((x + y) * 0.5 - z) * SCALE]
+const pair = (point) => point.map((n) => n.toFixed(1)).join(",")
+
+// box: { width, height, depth, frontHeight, slope, thickness, notch, units, lid, hot }
+// profile: slopedProfile() of the same box, in the same units
+// Returns { viewBox, markup } for an
diff --git a/lib/makeabox/svg_renderer.rb b/lib/makeabox/svg_renderer.rb
index 1ff63ee..c73dc71 100644
--- a/lib/makeabox/svg_renderer.rb
+++ b/lib/makeabox/svg_renderer.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Makeabox
- # laser-cutter (2.0.0 and 2.0.1) works out the size of the page again for every line it
+ # laser-cutter (2.x and 3.0) works out the size of the page again for every line it
# writes to an SVG, which makes a 10 inch box take eight seconds instead of
# a twentieth of one. The size cannot change while rendering, so it is kept.
#
diff --git a/spec/models/box_request_sloped_spec.rb b/spec/models/box_request_sloped_spec.rb
new file mode 100644
index 0000000..57d7ec2
--- /dev/null
+++ b/spec/models/box_request_sloped_spec.rb
@@ -0,0 +1,85 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# A front that slopes back: BoxRequest's slope and front_height.
+RSpec.describe BoxRequest do
+ subject(:box) { described_class.new(params) }
+
+ let(:params) do
+ { 'width' => '4', 'height' => '3', 'depth' => '5', 'thickness' => '0.125', 'units' => 'in', 'slope' => '45', 'front_height' => '1' }
+ end
+
+ def errors_for(changes)
+ described_class.new(params.merge(changes)).tap(&:valid?).errors
+ end
+
+ it { is_expected.to be_valid }
+ it { is_expected.to be_sloped }
+
+ it 'is upright when both slope fields are blank' do
+ expect(described_class.new(params.merge('slope' => '', 'front_height' => ''))).not_to be_sloped
+ end
+
+ it 'starts the slope at the bottom with a front height of zero' do
+ expect(errors_for('front_height' => '0', 'slope' => '60')).to be_empty
+ end
+
+ it 'refuses an angle that is flat, upright or not a number' do
+ %w[0 90 steep].each do |slope|
+ expect(errors_for('slope' => slope)).to eq ['Slope needs an angle above 0 and below 90 degrees.']
+ end
+ end
+
+ it 'refuses a front height that is missing, negative or reaches the top' do
+ expect(errors_for('front_height' => '')).to eq ['Front height needs a number, zero or more.']
+ expect(errors_for('front_height' => '-1')).to eq ['Front height needs a number, zero or more.']
+ expect(errors_for('front_height' => '3')).to eq ['Front height has to be lower than the height of the box.']
+ end
+
+ it 'refuses the lid with tabs along the back' do
+ expect(errors_for('lid' => 'back')).to eq ['A sloped box cannot have the lid with tabs along the back.']
+ expect(errors_for('lid' => 'plain')).to be_empty
+ end
+
+ it 'refuses a slope that runs deeper than the box' do
+ expect(errors_for('slope' => '20')).to eq [
+ 'At 20° the slope runs 5.49 in back, deeper than the box. Make the slope steeper, the front taller, or the box deeper.'
+ ]
+ end
+
+ it 'rounds the angle it names to two places' do
+ expect(errors_for('slope' => '20.12345').first).to start_with 'At 20.12° the slope runs'
+ end
+
+ # The strips cut the sloped panel short at both ends; laser-cutter refuses a panel with nothing left.
+ describe 'a slope that leaves nothing of the sloped panel' do
+ let(:tight) { { 'height' => '3', 'depth' => '4', 'thickness' => '0.245', 'slope' => '45', 'front_height' => '2.75' } }
+
+ it 'is refused, and a lower front is not' do
+ expect(errors_for(tight)).to eq [
+ 'At 45° from a front of 2.75 in, nothing is left of the sloped panel in this material. Make the front lower.'
+ ]
+ expect(errors_for(tight.merge('front_height' => '2'))).to be_empty
+ end
+
+ it 'is what laser-cutter refuses too' do
+ expect { Laser::Cutter::Sloped::Profile.new(depth: 4, height: 3, front_height: 2.75, slope: 45, thickness: 0.245) }
+ .to raise_error(Laser::Cutter::InvalidOption, /no tilted panel/)
+ end
+ end
+
+ it 'names the angle in the file name' do
+ expect(box.filename('svg')).to eq 'makeabox-4x3x5in-0.125t-45deg.svg'
+ end
+
+ it 'hands laser-cutter the slope and the front height' do
+ config = box.configuration(File::NULL)
+ expect([config[:slope], config[:front_height]]).to eq [45.0, 1.0]
+ end
+
+ it 'draws the box in both formats' do
+ expect(box.render('svg')).to include('