line Badness(width: Length<Pt>, target: Length<Pt>, char Count: int, spaces: int, kind: Break Kind, is Last: bool, justification B: int, hyphen Advance: Length<Pt>) - > Result<int, Typeset Error>- Module
- std.
typeset - Receiver
- Not applicable
- Minimum arity
- 8
- Maximum arity
- 8
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.typeset in language mode 5.21.
The current compiler selects std/typeset.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 40
Receiver
Parameter constraints
Public measurement fields use Length<Pt>. Widths, advances, tracking, stretch, shrink, physical targets, insets, font sizes, and optional width limits keep that type across input and output records. Explicit Length conversion functions remain the integer interchange boundary.
Box., Box., Glue., Glue., Glue., Glue., and Penalty. have type Length<Pt>.
Break, Break, Break, and Break have type Length<Pt>.
Latin, Justification, and Justification have type Length<Pt>.
Line, Line, and Line have type Length<Pt>.
Plan, Plan, Plan, Plan, and Plan have type Length<Pt>. Plan has type Option<Length<Pt>>.
An int, a float, or a Length with another unit marker is not an implicit point-length argument. Convert physical units explicitly with toPt() before constructing a typesetting record.
Indices, counts, penalties, costs, and dimensionless ratios retain their declared types. LatinSpacing.maxLetterSpacingEm is a relative Length<Em>. Resolve it to Length<Pt> with fontSizePt before selecting the computation grid.
Paragraph. selects quantization at the computation boundary. ScaledPoint uses the exact scaled-point integer. MilliPoint uses the existing nearest-even conversion to millipoints. The selected grid never changes the physical interpretation of a public Length<Pt> value.
Returned distances are converted from the computation grid into Length<Pt> at the output boundary. Paragraph reports the computation policy and is not needed to interpret its distances.
The public type change preserves the selected cost model. FixedPoint retains its MilliPoint computation requirement. Word-space and CJK ratio calculations keep their independent floor rules. The relative letter-spacing distance is resolved and quantized through the shared Length conversions before it contributes to capacity.
The public line-badness entry point also receives width, target, and hyphen advance as Length<Pt>. It converts those distances to millipoints at entry and preserves its existing integer cost calculation.
line is the public entry point. lineBadnessMpt is absent and importing it is rejected with TPZ3009.
The three distances require Length<Pt>. A raw scalar or another unit marker is rejected with TPZ5001. Width and hyphen advance may be negative. justificationB accepts every int and can make the resulting cost negative.
Evaluate all eight argument expressions once in source order before entering the function. Convert width, target, and hyphenAdvance to millipoints in that order with the shared nearest-even rule.
The converted target must be positive. charCount and spaces must each be nonnegative and need not satisfy a relation to each other. Invalid inputs return Err containing TypesetError.InvalidInput before cost arithmetic. The explanatory message text is not fixed.
Let w, t, and h be the converted distances, c the character count, s the space count, and j the supplied justification cost. Let B be 1,000,000 and R be 100,000,000.
For a nonnegative n and positive d, H gives n divided by d rounded to the nearest integer with ties upward. H describes cost rounding. Physical Length conversion keeps its separate nearest-even rule.
The following sequence uses checked int operations in the stated order. A failing intermediate operation stops with runtime diagnostic TPZ4004. It does not return TypesetError or replace overflow with a bounded cost.
Set effective to w + h for LatinSoftHyphen and to w for every other kind. Set slack to t - effective and absolute to the absolute value of slack.
Set raw to 4 R when absolute is at least 4 t. Otherwise set raw to absolute * R / with integer division. This explicit ratio cap does not change a supplied length.
Set capacity to 100 + s * 45 when slack is nonnegative and to 100 + s * 25 otherwise. Set ratio = H(raw * 100, capacity), then q = H(ratio * ratio, R), then cost = H(q * (1000 * B), R).
If isLast is true, replace cost with H(cost * 2, 5). Add 500 B when isLast is true and `w 100 < t * 52`. The strict comparison uses the original converted width and also applies when charCount is zero.
If slack is negative, add 20000 * B + H(20000 * B * ratio, R). Add 65 B for LatinHyphen or LatinSoftHyphen. Add 50000 B for HardFallback. The other break kinds add no break penalty.
If c is at most two, add 275 B. Then add 10 B and j in that order and return the result in Ok. The hyphenAdvance input affects width for LatinSoftHyphen and is ignored for the other kinds.
An exact fit with more than two characters, no special break penalty, and zero justification cost returns 10000000. The documented 90 point line against a 100 point target with nine characters and two spaces returns 12770080.
The function performs no I/O, changes no input, and reads no font, paragraph, or global grid state. Effects from argument evaluation remain visible on InvalidInput or a later arithmetic fault.
An arithmetic fault identifies the public lineBadness call as its primary source location. Argument effects already performed remain visible and later expressions do not run.
Related rule: Compute fixed-point line badness from point lengthsResult
The declared result type is Result<int, Typeset.
Effects
Failures
Result and effects
LinkConvert the three point distances to nearest-even millipoints and compute the specified checked fixed-point cost. A nonpositive converted target or negative count returns TypesetError.InvalidInput. Arithmetic overflow raises TPZ4004.
Why
LinkA function name describes the computation while Length<Pt> carries its physical unit. One typed entry point avoids a second millipoint API for the same line-badness calculation.
Related entries
LinkGive public typesetting distances a point-length type
LinkGive public typesetting distances a point-length type
Public measurement fields use Length<Pt>. Widths, advances, tracking, stretch, shrink, physical targets, insets, font sizes, and optional width limits keep that type across input and output records. Explicit Length conversion functions remain the integer interchange boundary.
Box., Box., Glue., Glue., Glue., Glue., and Penalty. have type Length<Pt>.
Break, Break, Break, and Break have type Length<Pt>.
Latin, Justification, and Justification have type Length<Pt>.
Line, Line, and Line have type Length<Pt>.
Plan, Plan, Plan, Plan, and Plan have type Length<Pt>. Plan has type Option<Length<Pt>>.
An int, a float, or a Length with another unit marker is not an implicit point-length argument. Convert physical units explicitly with toPt() before constructing a typesetting record.
Indices, counts, penalties, costs, and dimensionless ratios retain their declared types. LatinSpacing.maxLetterSpacingEm is a relative Length<Em>. Resolve it to Length<Pt> with fontSizePt before selecting the computation grid.
Paragraph. selects quantization at the computation boundary. ScaledPoint uses the exact scaled-point integer. MilliPoint uses the existing nearest-even conversion to millipoints. The selected grid never changes the physical interpretation of a public Length<Pt> value.
Returned distances are converted from the computation grid into Length<Pt> at the output boundary. Paragraph reports the computation policy and is not needed to interpret its distances.
The public type change preserves the selected cost model. FixedPoint retains its MilliPoint computation requirement. Word-space and CJK ratio calculations keep their independent floor rules. The relative letter-spacing distance is resolved and quantized through the shared Length conversions before it contributes to capacity.
The public line-badness entry point also receives width, target, and hyphen advance as Length<Pt>. It converts those distances to millipoints at entry and preserves its existing integer cost calculation.
Why
A physical distance carries the same Length<Pt> type in application geometry and paragraph planning. The type prevents a grid selector or an unlabelled scalar from silently changing the distance.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in Box
Linkimport std.typeset as tslet value: ts.Box = ts.Box {unitIndex: 0,text: "A",width: 12pt,trackingAfter: 0pt}let distance: Length<Pt> = value.width
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in Box
Linkimport std.typeset as tslet value: ts.Box = ts.Box {unitIndex: 0,text: "A",width: 12,trackingAfter: 0}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:5:10
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in Glue
Linkimport std.typeset as tslet value: ts.Glue = ts.Glue {unitIndex: 1,text: " ",width: 3pt,trackingAfter: 0pt,stretch: 1pt,shrink: 1pt}let distance: Length<Pt> = value.width
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in Glue
Linkimport std.typeset as tslet value: ts.Glue = ts.Glue {unitIndex: 1,text: " ",width: 3,trackingAfter: 0,stretch: 1,shrink: 1}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:5:10
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in Penalty
Linkimport std.typeset as tslet value: ts.Penalty = ts.Penalty {unitEnd: 1,width: 0pt,rule: ts.BreakRule.Forced(),kind: ts.BreakKind.ForcedEnd(),flagged: false}let distance: Length<Pt> = value.width
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in Penalty
Linkimport std.typeset as tslet value: ts.Penalty = ts.Penalty {unitEnd: 1,width: 0,rule: ts.BreakRule.Forced(),kind: ts.BreakKind.ForcedEnd(),flagged: false}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:4:10
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in BreakPolicy
Linkimport std.typeset as tslet value: ts.BreakPolicy = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.Unicode16Ja(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [true],generatedHyphenEnds: [],protectFittingLatin: true,preserveShortWords: true,narrowestWordTarget: 12pt,bodyWordTarget: 24pt}let distance: Length<Pt> = value.narrowestWordTarget
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in BreakPolicy
Linkimport std.typeset as tslet value: ts.BreakPolicy = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.Unicode16Ja(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [true],generatedHyphenEnds: [],protectFittingLatin: true,preserveShortWords: true,narrowestWordTarget: 12,bodyWordTarget: 24}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:11:24
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in BreakCluster
Linkimport std.typeset as tslet value: ts.BreakCluster = ts.BreakCluster {text: "A",advance: 12pt,trackingAfter: 0pt}let distance: Length<Pt> = value.advance
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in BreakCluster
Linkimport std.typeset as tslet value: ts.BreakCluster = ts.BreakCluster {text: "A",advance: 12,trackingAfter: 0}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:4:12
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in LatinSpacing
Linkimport std.typeset as tslet value: ts.LatinSpacing = ts.LatinSpacing {minWordSpaceRatio: 0.8,maxWordSpaceRatio: 1.33,maxLetterSpacingEm: 0.01em,fontSizePt: 12pt}let distance: Length<Pt> = value.fontSizePt
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in LatinSpacing
Linkimport std.typeset as tslet value: ts.LatinSpacing = ts.LatinSpacing {minWordSpaceRatio: 0.8,maxWordSpaceRatio: 1.33,maxLetterSpacingEm: 0.01em,fontSizePt: 12.0}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:6:15
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in JustificationPolicy
Linkimport std.typeset as tslet value: ts.JustificationPolicy = ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(),minGapCount: 0,minLineWidthRatioM: 0,minFinalLineWidthRatioM: None(),maxAdjustment: 12pt,maxGapAdjustment: 3pt,maxGapRatioR: 0,latinSpacing: None(),cjkStretchRatio: 0.0}let distance: Length<Pt> = value.maxAdjustment
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in JustificationPolicy
Linkimport std.typeset as tslet value: ts.JustificationPolicy = ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(),minGapCount: 0,minLineWidthRatioM: 0,minFinalLineWidthRatioM: None(),maxAdjustment: 12,maxGapAdjustment: 3,maxGapRatioR: 0,latinSpacing: None(),cjkStretchRatio: 0.0}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:7:18
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in LineGeometry
Linkimport std.typeset as tslet value: ts.LineGeometry = ts.LineGeometry {bodyTarget: 24pt,firstTarget: 20pt,dropCapSpan: 0,dropCapInset: 0pt}let distance: Length<Pt> = value.bodyTarget
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in LineGeometry
Linkimport std.typeset as tslet value: ts.LineGeometry = ts.LineGeometry {bodyTarget: 24,firstTarget: 20,dropCapSpan: 0,dropCapInset: 0}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:3:15
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Use point lengths in PlanLine
Linkimport std.typeset as tslet value: ts.PlanLine = ts.PlanLine {start: 0,endExclusive: 1,trimmedEndExclusive: 1,displayTextScalarLength: 1,kind: ts.BreakKind.ForcedEnd(),target: 12pt,rawTextWidth: 10pt,trimmedTextWidth: 10pt,costTextWidth: 10pt,selectedPenaltyWidth: 0pt,postValidationWidthLimit: Some(13pt),cost: 0,adjustmentRatioR: 0}let distance: Length<Pt> = value.targetlet limit: Option<Length<Pt>> = value.postValidationWidthLimit
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject untyped physical distances in PlanLine
Linkimport std.typeset as tslet value: ts.PlanLine = ts.PlanLine {start: 0,endExclusive: 1,trimmedEndExclusive: 1,displayTextScalarLength: 1,kind: ts.BreakKind.ForcedEnd(),target: 12,rawTextWidth: 10,trimmedTextWidth: 10,costTextWidth: 10,selectedPenaltyWidth: 0,postValidationWidthLimit: Some(13),cost: 0,adjustmentRatioR: 0}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:8:11
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Pass typed distances to the line-cost function
Linkimport std.typeset as tslet value = ts.lineBadness(20pt, 20pt, 4, 1, ts.BreakKind.ForcedEnd(), false, 0, 0pt)
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Reject raw distances at the line-cost boundary
Linkimport std.typeset as tslet value = ts.lineBadness(20, 20, 4, 1, ts.BreakKind.ForcedEnd(), false, 0, 0)
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:2:28
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 16 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/spacing.tpz at
271329b482bc· 38 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
271329b482bc· 90 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1846 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1976 - compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-length-ptatworking-tree - topaz.decision.typeset-length-pt.1 at
topaz.decisi
Diagnostics
LinkCompute fixed-point line badness from point lengths
LinkCompute fixed-point line badness from point lengths
line is the public entry point. lineBadnessMpt is absent and importing it is rejected with TPZ3009.
The three distances require Length<Pt>. A raw scalar or another unit marker is rejected with TPZ5001. Width and hyphen advance may be negative. justificationB accepts every int and can make the resulting cost negative.
Evaluate all eight argument expressions once in source order before entering the function. Convert width, target, and hyphenAdvance to millipoints in that order with the shared nearest-even rule.
The converted target must be positive. charCount and spaces must each be nonnegative and need not satisfy a relation to each other. Invalid inputs return Err containing TypesetError.InvalidInput before cost arithmetic. The explanatory message text is not fixed.
Let w, t, and h be the converted distances, c the character count, s the space count, and j the supplied justification cost. Let B be 1,000,000 and R be 100,000,000.
For a nonnegative n and positive d, H gives n divided by d rounded to the nearest integer with ties upward. H describes cost rounding. Physical Length conversion keeps its separate nearest-even rule.
The following sequence uses checked int operations in the stated order. A failing intermediate operation stops with runtime diagnostic TPZ4004. It does not return TypesetError or replace overflow with a bounded cost.
Set effective to w + h for LatinSoftHyphen and to w for every other kind. Set slack to t - effective and absolute to the absolute value of slack.
Set raw to 4 R when absolute is at least 4 t. Otherwise set raw to absolute * R / with integer division. This explicit ratio cap does not change a supplied length.
Set capacity to 100 + s * 45 when slack is nonnegative and to 100 + s * 25 otherwise. Set ratio = H(raw * 100, capacity), then q = H(ratio * ratio, R), then cost = H(q * (1000 * B), R).
If isLast is true, replace cost with H(cost * 2, 5). Add 500 B when isLast is true and `w 100 < t * 52`. The strict comparison uses the original converted width and also applies when charCount is zero.
If slack is negative, add 20000 * B + H(20000 * B * ratio, R). Add 65 B for LatinHyphen or LatinSoftHyphen. Add 50000 B for HardFallback. The other break kinds add no break penalty.
If c is at most two, add 275 B. Then add 10 B and j in that order and return the result in Ok. The hyphenAdvance input affects width for LatinSoftHyphen and is ignored for the other kinds.
An exact fit with more than two characters, no special break penalty, and zero justification cost returns 10000000. The documented 90 point line against a 100 point target with nine characters and two spaces returns 12770080.
The function performs no I/O, changes no input, and reads no font, paragraph, or global grid state. Effects from argument evaluation remain visible on InvalidInput or a later arithmetic fault.
An arithmetic fault identifies the public lineBadness call as its primary source location. Argument effects already performed remain visible and later expressions do not run.
Why
One typed entry point fixes the physical meaning before scoring a line. Explicit intermediate rounding makes costs reproducible. The same last-line width condition applies to every valid character count, including an empty line.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Compute a line cost from point lengths
Linkimport std.ioimport std.typeset as tslet cost = ts.lineBadness(20pt, 20pt, 4, 1, ts.BreakKind.ForcedEnd(), false, 0, 0pt)match (cost) {case Ok(value) => io.writeLine("{value}")case Err(_) => io.writeLine("unexpected input error")}
10000000
Expected result
Expected result
Execution completes. Exit code 0.
10000000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Reject the former millipoint function name
Linkimport std.typeset { lineBadnessMpt }
No stdout.
Expected result
Expected result
Rejection during resolve. Nonzero exit.
TPZ3009selected-name-not-exported atmain.tpz:1:22
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Preserve the published fixed-point costs
Linkimport std.typeset as tsimport std.testimport std.iofunction show(value: Result<int, ts.TypesetError>) -> () {let cost = test.assertOk(value)io.writeLine("{cost}")}show(ts.lineBadness(100pt, 100pt, 10, 2, ts.BreakKind.LatinSpace(), false, 0, 0pt))show(ts.lineBadness(90pt, 100pt, 9, 2, ts.BreakKind.LatinSpace(), false, 0, 0pt))show(ts.lineBadness(100pt, 100pt, 10, 2, ts.BreakKind.LatinHyphen(), false, 0, 0pt))show(ts.lineBadness(40pt, 100pt, 4, 0, ts.BreakKind.ForcedEnd(), true, 0, 0pt))
10000000 12770080 75000000 654000000
Expected result
Expected result
Execution completes. Exit code 0.
100000001277008075000000654000000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Apply break penalties and the small character count boundary
Linkimport std.typeset as tsimport std.testimport std.iofunction show(value: Result<int, ts.TypesetError>) -> () {let cost = test.assertOk(value)io.writeLine("{cost}")}show(ts.lineBadness(100pt, 100pt, 3, 0, ts.BreakKind.CjkCluster(), false, 0, 0pt))show(ts.lineBadness(100pt, 100pt, 3, 0, ts.BreakKind.ClosingPunctuation(), false, 0, 0pt))show(ts.lineBadness(100pt, 100pt, 3, 0, ts.BreakKind.HardFallback(), false, 0, 0pt))show(ts.lineBadness(100pt, 100pt, 2, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt))show(ts.lineBadness(99pt, 100pt, 9, 0, ts.BreakKind.LatinSoftHyphen(), false, 0, 1pt))show(ts.lineBadness(99pt, 100pt, 9, 0, ts.BreakKind.LatinHyphen(), false, 0, 1pt))
10000000 10000000 50010000000 285000000 75000000 75100000
Expected result
Expected result
Execution completes. Exit code 0.
1000000010000000500100000002850000007500000075100000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Use a strict last-line width threshold
Linkimport std.typeset as tsimport std.testimport std.iofunction show(value: Result<int, ts.TypesetError>) -> () {let cost = test.assertOk(value)io.writeLine("{cost}")}show(ts.lineBadness(52pt, 100pt, 4, 0, ts.BreakKind.ForcedEnd(), true, 0, 0pt))show(ts.lineBadness(51pt, 100pt, 4, 0, ts.BreakKind.ForcedEnd(), true, 0, 0pt))
102160000 606040000
Expected result
Expected result
Execution completes. Exit code 0.
102160000606040000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Apply the last-line width condition to zero characters
Linkimport std.typeset as tsimport std.testimport std.iofunction show(value: Result<int, ts.TypesetError>) -> () {let cost = test.assertOk(value)io.writeLine("{cost}")}show(ts.lineBadness(0pt, 100pt, 0, 0, ts.BreakKind.ForcedEnd(), true, 0, 0pt))
1185000000
Expected result
Expected result
Execution completes. Exit code 0.
1185000000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Keep signed inputs and cap the scoring ratio explicitly
Linkimport std.typeset as tsimport std.testimport std.iofunction show(value: Result<int, ts.TypesetError>) -> () {let cost = test.assertOk(value)io.writeLine("{cost}")}show(ts.lineBadness(100pt, 100pt, 3, 0, ts.BreakKind.ForcedEnd(), false, -10000001, 0pt))show(ts.lineBadness(-1000pt, 100pt, 3, 0, ts.BreakKind.ForcedEnd(), false, 0, -1pt))show(ts.lineBadness(500pt, 100pt, 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt))show(ts.lineBadness(600pt, 100pt, 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt))
-1 16010000000 116010000000 116010000000
Expected result
Expected result
Execution completes. Exit code 0.
-116010000000116010000000116010000000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Return InvalidInput for the target and count boundaries
Linkimport std.typeset as tsimport std.iofor result in ([ts.lineBadness(1pt, 0pt, 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt),ts.lineBadness(1pt, -1pt, 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt),ts.lineBadness(1pt, 1pt, -1, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt),ts.lineBadness(1pt, 1pt, 3, -1, ts.BreakKind.ForcedEnd(), false, 0, 0pt)]) {match (result) {case Err(InvalidInput(_)) => io.writeLine("invalid input")case _ => io.writeLine("unexpected result")}}
invalid input invalid input invalid input invalid input
Expected result
Expected result
Execution completes. Exit code 0.
invalid inputinvalid inputinvalid inputinvalid input
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Validate target positivity after millipoint conversion
Linkimport std.typeset as tsimport std.testimport std.iofunction show(value: Result<int, ts.TypesetError>) -> () {let cost = test.assertOk(value)io.writeLine("{cost}")}let rejected = ts.lineBadness(0pt, ts.fromScaledPoints(32), 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt)match (rejected) {case Err(InvalidInput(_)) => io.writeLine("rounded target is zero")case _ => io.writeLine("unexpected result")}show(ts.lineBadness(ts.fromScaledPoints(33), ts.fromScaledPoints(33), 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt))show(ts.lineBadness(ts.fromScaledPoints(4096), ts.fromMilliPoints(62), 3, 0, ts.BreakKind.ForcedEnd(), false, 0, 0pt))
rounded target is zero 10000000 10000000
Expected result
Expected result
Execution completes. Exit code 0.
rounded target is zero1000000010000000
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Evaluate every argument before input validation
Linkimport std.typeset as tsimport std.iofunction length(label: string, value: Length<Pt>) -> Length<Pt> {io.writeLine(label)value}function count(label: string, value: int) -> int {io.writeLine(label)value}function kind(value: ts.BreakKind) -> ts.BreakKind {io.writeLine("kind")value}function last(value: bool) -> bool {io.writeLine("last")value}let result = ts.lineBadness(length("width", 1pt), length("target", 0pt),count("chars", 3), count("spaces", 0),kind(ts.BreakKind.ForcedEnd()), last(false),count("justification", 0), length("hyphen", 0pt))match (result) {case Err(InvalidInput(_)) => io.writeLine("invalid input")case _ => io.writeLine("unexpected result")}
width target chars spaces kind last justification hyphen invalid input
Expected result
Expected result
Execution completes. Exit code 0.
widthtargetcharsspaceskindlastjustificationhypheninvalid input
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi
Stop on checked cost overflow
Linkimport std.typeset as tsts.lineBadness(1pt, 1pt, 3, 0, ts.BreakKind.ForcedEnd(), false, 9223372036854775807, 0pt)
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/cost.tpz at
271329b482bc· 1 - compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
271329b482bc· 80 - compiler/crates/topaz_syntax/src/length.rs at
271329b482bc· 293 - compiler/crates/topaz_self_frontend/topaz/resolver/validation_init.tpz at
271329b482bc· 174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
271329b482bc· 1511 - compiler/crates/topaz_resolve/src/std/typeset/wide.tpz at
b48527d0a174· 29 - docs/content/en/docs/stdlib/typeset.mdx at
912a5e86e1f9· 379 - issues/31 at
topaz.decisi· 1 - pull/51 at
topaz.decisi· 1 - compiler/crates/topaz_product_runtime/src/runtime/machine.rs at
b48527d0a174· 490 -
topaz.stdlib.contract.line-badnessatworking-tree - topaz.decision.line-badness-name.1 at
topaz.decisi