Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thin space between tightly placed shapes #3432

Open
1 task done
Mc-Zen opened this issue Feb 17, 2024 · 5 comments
Open
1 task done

Thin space between tightly placed shapes #3432

Mc-Zen opened this issue Feb 17, 2024 · 5 comments
Labels
bug Something isn't working png Related to PNG export.

Comments

@Mc-Zen
Copy link

Mc-Zen commented Feb 17, 2024

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))
}

2

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
@Mc-Zen Mc-Zen added the bug Something isn't working label Feb 17, 2024
@Enter-tainer

This comment was marked as off-topic.

@Enivex
Copy link
Collaborator

Enivex commented Feb 17, 2024

#3216 (comment)

it's reader's problem and wont appear in printer

In this case it's png export, so not a reader problem.

It's a tricky issue though. Presumably due to float rounding.

@Enter-tainer
Copy link
Contributor

#3216 (comment)
it's reader's problem and wont appear in printer

In this case it's png export, so not a reader problem.

It's a tricky issue though. Presumably due to float rounding.

Maybe. But note that the same thin lines appears in svg and pdf export when using certain readers.

@laurmaedje laurmaedje added the png Related to PNG export. label Mar 11, 2024
@Enter-tainer
Copy link
Contributor

One trick is that you can draw it multiple times and the thin line will disappear.

#for i in range(5) {
  for _ in range(5) {
    place(dx: len * i, polygon-rect(width: len, height: len, fill: red, stroke: none))
  }
}

image
https://discord.com/channels/1054443721975922748/1088371919725793360/1244280894227742781

@Enter-tainer
Copy link
Contributor

This is related to anti alias rendering and is known as Conflation artifacts. For more please see linebender/vello#49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working png Related to PNG export.
Projects
None yet
Development

No branches or pull requests

4 participants