Refactor grid rendering

  • Correctly render axonometric and modular grid when canvas is rotated
  • Share the code for aligning to pixel grid
  • Make the grid/guideline an ruler more consistent with each other
  • Remove partial guideline gap on tile borders
  • Make the rectangle grid x and y dashes better aligned (at least for pixel based grids and round zoom levels)
  • Simplify and deduplicate parallel grid line calculations
  • Some changes to grid configuration labels and tooltips

Fixes #1857 (closed)

Detailed explanation

Main goal of the issue was fixing rotation. In the process I ended up simplifying refactoring a lot more of grid rendering than I expected. The old version had quite a bit of duplication with baked in assumptions about the view not being rotated.

The pixel snapping isn't perfect but it should behave a bit better and at least now it's in single place making it easier to do future adjustments while keeping the behavior of guides and multiple grid types the same.

In the current state it with perfect grid and zoom (px based grid, 100% or other round multiplier zoom) it should be more or less perfect and aligned with rulers. Can't get rulers and grid aligned for non px based (for example mm based) since the ruler has significantly different rendering logic doing things in blocks. With regards to rounding threshold, 0.5 is probably a bit too biased towards right, but the old approach of simply doing floor(x)+0.5 was worse and introduced inconsistency even for perfect grids. floor(x+0.0001)+0.5 might be mathematically more accurate while avoiding the problems of inconsistent rounding to floating point and other transformation producing numbers that close integer (9.9999 vs 10.00001), but the ruler seems to be even more biased towards right so for now kept floor(x+0.5) to keep them more similar.

I hope the label changes won't be too controversial. Made some of them in document properties match the ones from preferences and replaced the ones which where reused from rectangular grid with something more suitable for each type of grid. Also seems like the tooltips for rectangular grid were mixed up.

Comparison screenshots:

Click to download and inspect.

test_report.svg

Other scenarios considered and at least partially tried during testing:

  • flipping canvas horizontally/vertically
  • rotating canvas 180 and how it affects dash alignment

Related issues:

Fixes #1857 (closed)

Partially related to #794 although it's a bit of mess. Initial description complains about dots becoming crosses even though "before" screenshot also shows crosses just with lighter transparency and center looking darker from 2 overlapping semitransparent dashes and thus looking more like dot. Later discussion goes more in the direction of discussing misaligned rendering which this MR slightly improves. Wouldn't be surprised if there were some additional intentional changes between 0.92 and now.

Edited by karliss1

Merge request reports

Loading