Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека · std.typeset

    DistanceGrid.ScaledPoint

    Inspect the declaration, parameters, and availability of this API.

    DistanceGrid.ScaledPoint()
    Модуль
    std.typeset →
    Получатель
    Неприменимо
    Минимальное число аргументов
    0
    Максимальное число аргументов
    0

    Declaration and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    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.

    Получатель

    Ограничения параметров

    DistanceGrid has the two payload-free values ScaledPoint() and MilliPoint(). They are distinct selectors and have no numeric conversion or ambient state.

    Public physical inputs and outputs remain Length<Pt> under either selector. A grid selects internal quantization and does not reinterpret an integer or change a public unit marker.

    ScaledPoint uses the signed scaled-point integer stored in each physical length. MilliPoint converts each input through Length<Pt>.toMilliPoints with nearest-even rounding.

    Quantize each input once at the computation boundary. Resolve a relative length against its explicit font size before this conversion. Accumulation uses the resulting integers.

    Return a computed distance through fromScaledPoints for ScaledPoint or fromMilliPoints for MilliPoint. The shared constructor range and rounding rules apply at this output boundary.

    Grid conversion accepts signed lengths. Each grid computation applies its sign requirements after quantization. A positive point target that becomes zero millipoints fails a positive-target requirement. Font validation occurs during resolve before grid conversion.

    FixedPoint requires MilliPoint. A paragraph that selects FixedPoint with ScaledPoint returns Err containing TypesetError.InvalidPolicy. KnuthPlass accepts either grid.

    Selecting a grid and converting lengths perform no I/O and do not mutate their inputs. Ordinary receiver and argument evaluation happens once before conversion. Input evaluation failures propagate before the operation begins.

    A millipoint round trip can change the stored scaled-point value. For example, 4096 scaled points become 62 millipoints and then 4063 scaled points.

    Результат

    Эффекты

    Ошибки

    Result and effects

    Ссылка

    Select exact scaled-point integers at computation boundaries while public distances retain Length<Pt>. FixedPoint rejects this grid with TypesetError.InvalidPolicy.

    Resolved contracts

    Ссылка

    Related entries

    Ссылка

    std.typeset →

    Select a computation grid for typed distances

    Ссылка
    Правилоtopaz.stdlib.contract.distance-grid.rule

    Select a computation grid for typed distances

    DistanceGrid has the two payload-free values ScaledPoint() and MilliPoint(). They are distinct selectors and have no numeric conversion or ambient state.

    Public physical inputs and outputs remain Length<Pt> under either selector. A grid selects internal quantization and does not reinterpret an integer or change a public unit marker.

    ScaledPoint uses the signed scaled-point integer stored in each physical length. MilliPoint converts each input through Length<Pt>.toMilliPoints with nearest-even rounding.

    Quantize each input once at the computation boundary. Resolve a relative length against its explicit font size before this conversion. Accumulation uses the resulting integers.

    Return a computed distance through fromScaledPoints for ScaledPoint or fromMilliPoints for MilliPoint. The shared constructor range and rounding rules apply at this output boundary.

    Grid conversion accepts signed lengths. Each grid computation applies its sign requirements after quantization. A positive point target that becomes zero millipoints fails a positive-target requirement. Font validation occurs during resolve before grid conversion.

    FixedPoint requires MilliPoint. A paragraph that selects FixedPoint with ScaledPoint returns Err containing TypesetError.InvalidPolicy. KnuthPlass accepts either grid.

    Selecting a grid and converting lengths perform no I/O and do not mutate their inputs. Ordinary receiver and argument evaluation happens once before conversion. Input evaluation failures propagate before the operation begins.

    A millipoint round trip can change the stored scaled-point value. For example, 4096 scaled points become 62 millipoints and then 4063 scaled points.

    Причина

    Typed distances retain their meaning while a computation chooses precision. One conversion rule at each boundary makes grid selection reproducible and keeps font resolution explicit.

    Construct both computation grid selectors

    Ссылка
    main.tpzConstruct both computation grid selectorsОткрыть песочницу →
    1. import std.typeset as ts
    2. let scaled: ts.DistanceGrid = ts.DistanceGrid.ScaledPoint()
    3. let milli: ts.DistanceGrid = ts.DistanceGrid.MilliPoint()
    Ожидаемый выводКод завершения 0
    Нет стандартного вывода.
    $ topaz check main.tpz --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Проверка принимает программу. Код завершения 0.

    Round signed millipoint ties and expose grid loss

    Ссылка
    main.tpzRound signed millipoint ties and expose grid lossОткрыть песочницу →
    1. import std.typeset as ts
    2. import std.io
    3. for ticks in ([-12288, -4096, 0, 4096, 12288]) {
    4. let value = ts.fromScaledPoints(ticks).toMilliPoints()
    5. io.writeLine("{value}")
    6. }
    7. let restored = ts.fromMilliPoints(62)
    8. io.writeLine("{restored == ts.fromScaledPoints(4063)}")
    9. io.writeLine("{restored == ts.fromScaledPoints(4096)}")
    Ожидаемый выводКод завершения 0
    -188
    -62
    0
    62
    188
    true
    false
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. -188
    2. -62
    3. 0
    4. 62
    5. 188
    6. true
    7. false

    Reject a scaled-point grid for FixedPoint

    Ссылка
    main.tpzReject a scaled-point grid for FixedPointОткрыть песочницу →
    1. import std.typeset as ts
    2. import std.io
    3. function paragraph(grid: ts.DistanceGrid, spacing: Option<ts.LatinSpacing>) -> ts.Paragraph {
    4. ts.Paragraph {
    5. grid: grid,
    6. items: [
    7. ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "abc", width: 10pt, trackingAfter: 0pt }),
    8. ts.Item.PenaltyItem(ts.Penalty {
    9. unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(),
    10. kind: ts.BreakKind.ForcedEnd(), flagged: false
    11. })
    12. ],
    13. geometry: ts.LineGeometry {
    14. bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt
    15. },
    16. justification: ts.JustificationPolicy {
    17. mode: ts.JustificationMode.Unjustified(),
    18. minGapCount: 0, minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    19. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    20. latinSpacing: spacing, cjkStretchRatio: 0.0
    21. },
    22. costModel: ts.CostModel.FixedPoint(),
    23. knuthPlass: ts.KnuthPlassPolicy {
    24. toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0,
    25. flaggedDemerit: 0, finalFlaggedDemerit: 0
    26. }
    27. }
    28. }
    29. match (ts.breakParagraph(paragraph(ts.DistanceGrid.ScaledPoint(), None()))) {
    30. case Err(InvalidPolicy(_)) => io.writeLine("invalid grid policy")
    31. case _ => io.writeLine("unexpected result")
    32. }
    Ожидаемый выводКод завершения 0
    invalid grid policy
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. invalid grid policy

    Меню

    Загрузка →