Skip to content

Commit 8c70dde

Browse files
committed
Merge branch 'fix-rounding-errors'
2 parents 92d2cb2 + 3568ed8 commit 8c70dde

File tree

8 files changed

+18
-9
lines changed

8 files changed

+18
-9
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
- Fixed a bug when passing a coordinate to the `angle:` argument of
2626
`content` and a transformation matrix ≠ id.
2727
- Fixed a bug with cetz creating invalid stroke objects for `stroke: none` (#1059).
28+
- Increased the rounding digits from 8 to 10, fixing some rounding bugs
29+
with `ortho`.
2830

2931
# 0.4.2
3032
- The `tree` element now has a `anchor:` argument to position the tree (#929)

src/draw/projection.typ

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,33 +162,40 @@
162162
// - sorted (bool): Sort drawables by maximum distance (front to back)
163163
// - cull-face (none,str): Enable back-face culling if set to `"cw"` for clockwise
164164
// or `"ccw"` for counter-clockwise. Polygons of the specified order will not get drawn.
165-
#let _projection(body, view-matrix, projection-matrix, reset-transform: true, sorted: true, cull-face: "cw") = {
165+
// - flatten (bool): Set $z=0$ for all geometry
166+
#let _projection(body, view-matrix, projection-matrix, reset-transform: true, sorted: true, cull-face: "cw", flatten: false) = {
166167
(ctx => {
167168
let transform = ctx.transform
168169
let perspective-mode = type(projection-matrix) == function
169170
let previous-perspective-mode = ctx.at("_perspective-projection", default: false)
170171
if perspective-mode {
171172
ctx._perspective-projection = true
172173
}
173-
ctx.transform = view-matrix
174174

175-
let (ctx, drawables, bounds) = process.many(ctx, util.resolve-body(ctx, body))
175+
let local-ctx = ctx
176+
let local-transform = if flatten {
177+
local-ctx.transform = matrix.mul-mat(
178+
((1,0,0,0), (0,1,0,0), (0,0,0,0), (0,0,0,1.0)),
179+
view-matrix)
180+
} else {
181+
local-ctx.transform = view-matrix
182+
}
183+
184+
let (ctx, drawables, bounds) = process.many(local-ctx, util.resolve-body(ctx, body))
176185

177186
if cull-face != none {
178187
assert(cull-face in ("cw", "ccw"),
179188
message: "cull-face must be none, cw or ccw.")
180189
drawables = _filter-cw-faces(drawables, mode: cull-face)
181190
}
191+
182192
if sorted {
183193
drawables = _sort-by-distance(drawables)
184194
}
185195

186-
if projection-matrix != none {
187-
drawables = drawable.apply-transform(projection-matrix, drawables)
188-
}
189-
190196
ctx.transform = transform
191197
if perspective-mode {
198+
drawable.apply-transform(projection-matrix, drawables)
192199
ctx._perspective-projection = previous-perspective-mode
193200
}
194201
if not reset-transform {

src/matrix.typ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#let cetz-core = plugin("../cetz-core/cetz_core.wasm")
44

55
// Global rounding precision
6-
#let precision = 8
6+
#let precision = 10
77

88
#let _round = calc.round.with(digits: precision)
99

@@ -243,7 +243,7 @@
243243
/// - ..matrices (matrix): The matrices to multiply from left to right.
244244
/// -> matrix
245245
#let mul-mat(..matrices) = {
246-
matrices = matrices.pos()
246+
matrices = matrices.pos().filter(m => m != none)
247247
let out = matrices.first()
248248
for i in range(1, matrices.len()) {
249249
let matrix = matrices.at(i)

tests/custom/mark/ref/1.png

-28 Bytes
Loading

tests/merge/ref/1.png

-6 Bytes
Loading

tests/projection/ortho/ref/1.png

-179 Bytes
Loading
3.97 KB
Loading
48 Bytes
Loading

0 commit comments

Comments
 (0)