Skip to content

gradient.repeat() sometimes produces non-monotonic stops #5819

@Mc-Zen

Description

@Mc-Zen

Description

Sometimes, when repeat()ing a gradient and retrieving the new gradients stops, it's not possible to feed them back into a gradient constructor.
MWE:

#let my-gradient = gradient.linear(red, blue).repeat(5)
#gradient.linear(..my-gradient.stops())

The error message is "Offsets must be in strictly monotonic order".

Most interestingly, this only happens with 7,9,10,11,12,13,... repetitions. Moreoever, if the stops are hover-inspected and copied to a variable explicitly, like

#let stops = (
  (rgb("#ff4136"), 0%),
  (rgb("#0074d9"), 20%),
  (rgb("#ff4136"), 20%),
  (rgb("#0074d9"), 40%),
  (rgb("#ff4136"), 40%),
  (rgb("#0074d9"), 60%),
  (rgb("#ff4136"), 60%),
  (rgb("#0074d9"), 80%),
  (rgb("#ff4136"), 80%),
  (rgb("#0074d9"), 100%),
)

#gradient.linear(..stops)

the issue vanishes. For this reason I assume that due to floating point errors, some offset values end off lower than others.

One a side note, looking at line

if stop.get() < last_stop {
, stops are only required to be in monotonic order, not in strictly monotonic order (regarding the phrasing of the error message).

Reproduction URL

No response

Operating system

No response

Typst version

  • I am using the latest version of Typst

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingvisualizeRelated to the visualize category, which is about drawing and illustrating

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions