indicatrix-editor 0.7.2

GUI-free faceting-design editor logic shared by the desktop editor and the wasm web app: the EditorSession (design, undo/redo with caller-supplied coalescing timestamps, selection, dirty tracking), tier/preform/material form parsing, plain-struct view models, the cutting sheet, Retarget, the guided walkthrough and the solve policy. No GUI toolkit, no threads, no clock, no filesystem.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//! Meets and targets: named facets, millimetre targets, adopting imported meets, and pinning
//! a solved depth.

#![allow(
    clippy::too_many_lines,
    reason = "a tutorial is its step text; splitting it would only scatter the wording"
)]

use super::{FORM, FORM_ADVANCED, TABLE_ADVANCED, check, meets_named, position, tier_called};
use crate::guide::{
    Goal, GoalContext, Group, Guide, GuideCategory, GuideStep, MeetKind, StartingState,
};
use indicatrix_cut_core::{ConstraintTier, Design, TierTarget};

/// The lessons of this file, in browser order.
pub fn guides() -> Vec<Guide> {
    vec![
        meets_named_facets(),
        meets_in_millimetres(),
        adopt_imported_meets(),
        pin_to_mast(),
    ]
}

/// The millimetre target of the tier called `name`.
fn target_of(design: &Design, name: &str) -> Option<TierTarget> {
    position(design, name).and_then(|at| design.tier_target(at))
}

/// Whether a tier still holds a meet instruction its file stated that it has not adopted.
fn is_adoptable(tier: &ConstraintTier) -> bool {
    tier.imported_meet
        .as_ref()
        .is_some_and(|stated| *stated != tier.constraint)
}

/// Whether a tier has adopted the meet instruction its file stated.
fn is_adopted(tier: &ConstraintTier) -> bool {
    tier.imported_meet
        .as_ref()
        .is_some_and(|stated| *stated == tier.constraint)
}

/// Some tier has an imported meet to adopt.
fn has_adoptable(ctx: &GoalContext<'_>) -> bool {
    ctx.design.tiers.iter().any(is_adoptable)
}

/// Some tier has adopted its imported meet.
fn has_adopted(ctx: &GoalContext<'_>) -> bool {
    ctx.design.tiers.iter().any(is_adopted)
}

/// Every imported meet has been adopted, and there was at least one.
fn all_adopted(ctx: &GoalContext<'_>) -> bool {
    has_adopted(ctx) && !has_adoptable(ctx)
}

/// The stone the Meets lessons that let the solver find a depth start from: the Standard
/// Round Brilliant (card 1).
///
/// The Rich Teaching Design does not do. It has one tier in its pavilion, so naming a facet for
/// that tier leaves the pavilion without an exact scale value and the design stops solving. Its
/// crown has no star facets, so an unspecified vertex sinks the table onto the girdle's top
/// edge and cuts the crown away. The Standard Round Brilliant keeps an exact scale value in
/// every block after each step of the lessons, and its table stays near its old height.
const SOLVER_STONE: usize = 1;

fn meets_named_facets() -> Guide {
    Guide::new(
        "tiers-meets-named-facets",
        "Meets: named facets",
        "Choose how a tier finds its depth: an unspecified vertex, named facets, or an exact scale value.",
        GuideCategory::Tiers,
    )
    .starting(StartingState::Template(SOLVER_STONE))
    .step(
        GuideStep::new(
            "Three ways to set a depth",
            "The Meets setting of a tier decides how its depth is found.",
        )
        .actions([
            "Unspecified vertex: the tier closes against whatever vertex the solver finds.",
            "Named facet(s): the tier closes against the facets you name.",
            "Exact scale value: you state the depth outright.",
        ])
        .why("To solve, each block of the stone (the crown, the pavilion and the girdle) needs one tier with an exact scale value. The other tiers of that block can then meet facets or a vertex instead.")
        .highlight("inspector_tier")
        .allow(FORM),
    )
    .step(
        GuideStep::new(
            "Meet a named facet",
            "Naming the facet a tier meets lets the solver find the depth for you.",
        )
        .actions([
            "Click the Upper Girdle row.",
            "Set Meets to Named facet(s).",
            "Facet names: Lower Girdle",
            "Click Save Tier.",
        ])
        .check("Upper Girdle's Meets column reads meets Lower Girdle.")
        .why("Several names are separated by commas. The solver puts the depth where this tier's facets cut the named facets: here, where the upper girdle facets touch the lower girdle facets. The crown still has other tiers with an exact scale value, so the stone keeps solving.")
        .goal(
            check("Upper Girdle meets Lower Girdle", |ctx| {
                meets_named(ctx.design, "Upper Girdle", "Lower Girdle")
            }),
            "Upper Girdle meeting Lower Girdle",
        )
        .highlight("inspector_tier")
        .allow(FORM),
    )
    .step(
        GuideStep::new(
            "Let the solver choose",
            "An unspecified vertex names nothing: the tier closes against whichever vertex the solver finds.",
        )
        .actions([
            "Click the Table row.",
            "Set Meets to Unspecified vertex.",
            "Click Save Tier.",
        ])
        .check("the Table row's Meets column reads meet.")
        .why("The solver cuts the table down to a vertex of the facets already there, and this crown, with its star facets, gives it one close to where the table was. Use it for a table you do not want to size by hand, and look at the result: on a crown of main facets only, with no star facets, the next vertex below the point where they meet is the girdle, so the table would sink there and cut the crown away. Undo (Ctrl+Z) brings the table back.")
        .goal(
            Goal::tier("Table", 0.0).with_meet(MeetKind::Unspecified),
            "Table on an unspecified vertex",
        )
        .highlight("inspector_tier")
        .allow(FORM),
    )
    .step(
        GuideStep::new(
            "Rename a facet others meet",
            "Upper Girdle now meets Lower Girdle by name. See what happens when Lower Girdle changes its name.",
        )
        .actions([
            "Click the Lower Girdle row.",
            "Change Name to LG1.",
            "Click Save Tier.",
        ])
        .check("Upper Girdle's Meets column now reads meets LG1.")
        .why("Renaming a tier updates every tier that meets it by name, in the same Undo step.")
        .goal(
            check("Upper Girdle meets LG1", |ctx| {
                tier_called(ctx.design, "LG1").is_some()
                    && meets_named(ctx.design, "Upper Girdle", "LG1")
            }),
            "Upper Girdle meeting LG1",
        )
        .highlight("inspector_tier")
        .allow(FORM),
    )
    .step(
        GuideStep::new(
            "Names must stay unique",
            "A name is how other tiers find a tier, so two tiers may not share one.",
        )
        .actions([
            "A tier cannot be left unnamed while another tier meets it.",
            "Join several names with / to give one tier more than one name, for example P1/P2.",
        ])
        .why("Every control is unlocked again."),
    )
}

fn meets_in_millimetres() -> Guide {
    Guide::new(
        "tiers-meets-mm-targets",
        "Meets in millimetres",
        "State a depth, a girdle thickness or a table width in millimetres instead of scale units.",
        GuideCategory::Tiers,
    )
    .starting(StartingState::Template(5))
    .step(
        GuideStep::new(
            "Give the stone a size",
            "Millimetre targets are converted through the girdle diameter, so the design needs one first.",
        )
        .actions([
            "Open the Preform tab in the inspector.",
            "Girdle Diameter (mm): 6.5",
            "Click Apply Yield Inputs.",
        ])
        .check("the Preform tab shows the yield figures after the next solve.")
        .why("The girdle diameter is the stone's real width. It turns the design's own units into millimetres; without it these targets cannot be solved.")
        .goal(Goal::YieldApplied, "the yield inputs to be applied")
        .highlight("preform_tab")
        .allow(&[Group::PreformTab, Group::History]),
    )
    .step(
        GuideStep::new(
            "Cut to a depth",
            "Cut to depth (mm) states how deep a facet's plane sits, measured the way the MAST column's millimetre tooltip measures it.",
        )
        .actions([
            "Open the Tier tab and click the Pavilion Main row.",
            "Set Meets to Cut to depth (mm).",
            "Value (mm): 2.2",
            "Click Save Tier.",
        ])
        .check("the Pavilion Main row's Meets column reads 2.20 mm depth.")
        .why("The value is turned into a scale value just before each solve, so it follows the girdle diameter if you change it.")
        .goal(
            check("Pavilion Main has a depth target", |ctx| {
                matches!(
                    target_of(ctx.design, "Pavilion Main"),
                    Some(TierTarget::DepthMm(_))
                )
            }),
            "a depth in millimetres on Pavilion Main",
        )
        .highlight("inspector_tier")
        .allow(FORM_ADVANCED),
    )
    .step(
        GuideStep::new(
            "Set the table width",
            "Table width (mm) searches the tier's depth until the finished table is that wide.",
        )
        .actions([
            "Click the Table row.",
            "Set Meets to Table width (mm).",
            "Value (mm): 3.2",
            "Click Save Tier.",
        ])
        .check("the Table row's Meets column reads table 3.20 mm.")
        .why("This costs several solves rather than one, so the status strip may take a moment to settle.")
        .goal(
            check("Table has a width target", |ctx| {
                matches!(
                    target_of(ctx.design, "Table"),
                    Some(TierTarget::TableWidthMm(_))
                )
            }),
            "a width in millimetres on Table",
        )
        .highlight("inspector_tier")
        .allow(FORM_ADVANCED),
    )
    .step(
        GuideStep::new(
            "Set the girdle thickness",
            "Girdle thickness (mm) searches the tier's depth until the girdle band is that thick.",
        )
        .actions([
            "Click the Girdle row.",
            "Set Meets to Girdle thickness (mm).",
            "Value (mm): 0.3",
            "Click Save Tier.",
        ])
        .check("the Girdle row's Meets column reads girdle 0.30 mm.")
        .why("Put it on the tier that makes the girdle: the girdle row itself.")
        .goal(
            check("Girdle has a thickness target", |ctx| {
                matches!(
                    target_of(ctx.design, "Girdle"),
                    Some(TierTarget::GirdleThicknessMm(_))
                )
            }),
            "a thickness in millimetres on Girdle",
        )
        .highlight("inspector_tier")
        .allow(FORM_ADVANCED),
    )
    .step(
        GuideStep::new(
            "When a target cannot be met",
            "A search needs a width it can reach. A table wider than the stone, for instance, has no answer.",
        )
        .actions([
            "If the status strip says a target could not be bracketed, widen or remove it.",
            "Choose Exact scale value or Named facet(s) again in Meets to remove a target; saving does it for you.",
        ])
        .why("Every control is unlocked again."),
    )
}

fn adopt_imported_meets() -> Guide {
    Guide::new(
        "tiers-adopt-imported-meets",
        "Adopt imported meets",
        "Switch the tiers of an imported design from pinned depths to the meets its file stated.",
        GuideCategory::Tiers,
    )
    .starting(StartingState::RequiresOpenDesign)
    .step(
        GuideStep::new(
            "Open an imported design",
            "Adopt works on a design imported from a GemCad .asc file. Import pins every tier to its depth and keeps the file's own meet instruction aside.",
        )
        .actions([
            "Open a .asc file with File > Open, or load an imported design from the library.",
            "Look for Adopt buttons in the tier table, and for a cyan line starting File says under Solved in the Tier tab.",
        ])
        .check("an Adopt button in the tier table.")
        .why("A design you built yourself has nothing to adopt. Use Back to leave this lesson.")
        .goal(
            check("a tier has an imported meet to adopt", has_adoptable),
            "an imported design with meets to adopt",
        )
        .highlight("tier_table")
        .allow(&[
            Group::FileOps,
            Group::TierTable,
            Group::Advanced,
            Group::History,
        ]),
    )
    .step(
        GuideStep::new(
            "Adopt one tier",
            "Adopt switches a tier from a fixed number to the instruction its file stated.",
        )
        .actions(["Click Adopt on one row of the tier table."])
        .check("that row's Meets column changes from a pinned value to a meet, and its Adopt button goes.")
        .why("A tier that meets other facets can be moved by Solve and Optimize; a pinned tier cannot.")
        .goal(
            check("a tier has adopted its imported meet", has_adopted),
            "one tier adopted",
        )
        .highlight("tier_table")
        .allow(TABLE_ADVANCED),
    )
    .step(
        GuideStep::new(
            "Adopt the rest at once",
            "Adopt all does every remaining tier in one go.",
        )
        .actions(["Click Adopt all above the tier table."])
        .check("no Adopt button is left in the tier table.")
        .why("Adopt all is one Undo step, so a single Ctrl+Z brings every pinned value back.")
        .goal(
            check("every imported meet is adopted", all_adopted),
            "every imported meet adopted",
        )
        .highlight("tier_table")
        .allow(TABLE_ADVANCED),
    )
    .step(
        GuideStep::new(
            "Adopt and Pin",
            "Adopt and Pin are opposites: Adopt trades a pinned depth for a meet, Pin trades a meet for a pinned depth.",
        )
        .actions([
            "Adopt sel. in the multi-select bar adopts only the ticked tiers.",
            "Continue with Pin to mast.",
        ])
        .why("Every control is unlocked again."),
    )
}

fn pin_to_mast() -> Guide {
    Guide::new(
        "tiers-pin-to-mast",
        "Pin to mast",
        "Freeze the depth the solver found for a tier as an exact scale value.",
        GuideCategory::Tiers,
    )
    .starting(StartingState::Template(SOLVER_STONE))
    .step(
        GuideStep::new(
            "Let the solver decide a depth",
            "Pin needs a tier whose depth the solver decides, so first make Upper Girdle meet the lower girdle.",
        )
        .actions([
            "Click the Upper Girdle row.",
            "Set Meets to Named facet(s).",
            "Facet names: Lower Girdle",
            "Click Save Tier.",
        ])
        .check("the Upper Girdle row's Meets column reads meets Lower Girdle.")
        .why("The stone keeps solving because the crown still has other tiers with an exact scale value.")
        .goal(
            Goal::tier("Upper Girdle", 41.0).with_meet(MeetKind::Named),
            "Upper Girdle meeting a named facet",
        )
        .highlight("inspector_tier")
        .allow(FORM_ADVANCED),
    )
    .step(
        GuideStep::new(
            "Pin the solved depth",
            "Pin takes the depth the solver found and writes it back as an exact scale value.",
        )
        .actions([
            "Wait until the status strip says the stone is solved.",
            "In the Upper Girdle row, click Pin in the PIN column.",
        ])
        .check("the Meets column shows a pinned scale value, and the Pin button goes.")
        .why("Pin a tier before Optimize to hold it where it is while the other tiers move. There is no Pin button while a tier is unsolved or already pinned.")
        .goal(
            Goal::tier("Upper Girdle", 41.0).with_meet(MeetKind::ExactScale),
            "Upper Girdle pinned to its solved depth",
        )
        .highlight("tier_table")
        .allow(TABLE_ADVANCED),
    )
    .step(
        GuideStep::new(
            "Pin and Adopt",
            "Pin turns a meet into a number. Adopt turns an imported number back into a meet.",
        )
        .actions([
            "Press Ctrl+Z to undo the pin and meet the lower girdle again.",
            "Use Adopt on an imported design to switch to the meets its file stated.",
        ])
        .why("Every control is unlocked again."),
    )
}