Optimization Constraints (assert)
Left completely to itself, an optimizer only cares about the optical score. Occasionally, it will discover a "clever" shortcut that boosts brightness on paper but ruins the physical stone—for instance, shrinking the table to a tiny dot, stretching the pavilion until it looks like an icicle, or twisting the girdle out of level.
You can prevent this by adding assert statements to your script.
An assert is a simple rule that must stay true. While the Optimizer is testing thousands of angle combinations, any candidate stone that breaks one of your assert rules is immediately thrown out.
How stone() and assert() Work Together
Calling stone() anywhere in your recipe takes a live measurement of the gem as it stands at that line. Place your assert checks at the very bottom of your file so they measure the finished stone:
// Syntax: assert(condition_that_must_be_true, "Error message if broken")
assert(stone().isGirdleOK, "Girdle is no longer level!")
assert(stone().tablePercentage >= 45, "Table got too small!")
When you run the design normally in the studio, an assert that fails will stop and display your message below the editor so you know which rule was broken. When you run the Optimizer, failed candidates are silently skipped so the search stays strictly inside your boundaries.
Summary of stone() Measurements
| Property | What It Measures |
|---|---|
stone().isGirdleOK | Returns true only if all vertical girdle facets have the same height and sit at the same Z level. |
stone().tablePercentage | Width of the table divided by the total width of the stone (0 to 100). |
stone().depthPercentage | Total height of the stone (culet to table) as a percentage of its width. |
stone().crownHeight | Height of the crown (above the girdle) as a percentage of total stone height. |
stone().pavilionDepth | Depth of the pavilion (below the girdle) as a percentage of total stone height. |
stone().girdleThickness | Average thickness of the girdle facets as a percentage of stone width. |
stone().facetCount | Total number of facets currently on the stone. |
stone().lengthWidthRatio | Longest horizontal dimension divided by the shortest (1.0 for rounds and squares). |
Ready-to-Use Guardrails
Copy any of these snippets to the bottom of your design before starting an optimization run:
1. Keep the Girdle Level (isGirdleOK)
When you float multiple pavilion or crown tiers on a fancy shape, some angle combinations can make adjacent girdle segments uneven. This one-liner forbids uneven girdles:
assert(stone().isGirdleOK, "Girdle issue!")
assert(stone().isGirdleOK, "Girdle issue!")
2. Keep the Table in a Classic Range (50% – 60%)
Stop the crown angles from pinching the table too narrow or opening it too wide:
assert(stone().tablePercentage >= 50, "Table too small!")
assert(stone().tablePercentage <= 60, "Table too big!")
assert(stone().tablePercentage >= 50, "Table too small!")
assert(stone().tablePercentage <= 60, "Table too big!")
3. Control Total Depth & Girdle Thickness
Useful when cutting shallow rough or when you need the finished stone to fit a standard commercial setting:
// Keep total depth within 2% of 60%
assert(Math.abs(stone().depthPercentage - 60) < 2, "Depth out of range!")
// Keep girdle thickness between 3% and 5% of stone width
assert(stone().girdleThickness >= 3, "Girdle too thin!")
assert(stone().girdleThickness <= 5, "Girdle too thick!")
-- Keep total depth within 2% of 60%
assert(math.abs(stone().depthPercentage - 60) < 2, "Depth out of range!")
-- Keep girdle thickness between 3% and 5% of stone width
assert(stone().girdleThickness >= 3, "Girdle too thin!")
assert(stone().girdleThickness <= 5, "Girdle too thick!")
4. Make Sure No Tier Gets Over-Cut (facetCount)
If one tier's angle moves too far during optimization, it can completely swallow a neighboring tier of small star or break facets. Locking the facet count ensures every tier in your diagram survives on the finished stone:
assert(stone().facetCount == 57, "A facet tier was cut away!")
assert(stone().facetCount == 57, "A facet tier was cut away!")