Thin space between tightly placed shapes
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 56.1k
- Forks
- 1.7k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
Description
Consider the following code in which we display a series of rectangles using rect in the first line and an alike series of rectangles created with polygon.
// Simulate `rect` with a polygon
#let polygon-rect(width: 20pt, height: 20pt, stroke: auto, fill: auto) = {
polygon((0pt, 0pt), (width, 0pt), (width, height), (0pt, height), (0pt, 0pt), fill: fill, stroke: stroke)
}
#let len = 1cm
#for i in range(5) {
place(dx: len * i, rect(width: len, height: len, fill: red, stroke: none))
}
#v(len * 2)
#for i in range(5) {
place(dx: len * i, polygon-rect(width: len, height: len, fill: red, stroke: none))
}
With polygon, a slight space appears between the tightly set rectangles.
Note I have not discovered this on PDFs, it only seems to happen with PNG export. With SVGs, the story is different: here, both with rect and polygon, a slight space is left between consecutive rectangles.
This may not seem as a great issue in itself but is indeed very annoying for many tasks such as general layout design, heatmaps, and more.
A (not very nice) workaround would be to add a very thin stroke. But how thin should the stroke be?
(Why use polygon instead of rect? The latter does not accept negative dimensions, see also #3265, this can be overcome with polygon).
Reproduction URL
No response
Operating system
No response
Typst version
- I am using the latest version of Typst
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Typst example and compare the PNG and SVG export paths for tightly adjacent rect and polygon shapes. Reproduce the visible gaps, then verify that adjacent shapes render without unintended spaces in PNG while retaining the reported SVG behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100