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

canvas: Change default transform to remove z #505

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

## Misc
- The `hide` function now support an additional `bounds:` parameter to enable canvas bounds adjustment for hidden elements
- The default transformation matrix changed

## Libs
### Plot
Expand Down
21 changes: 15 additions & 6 deletions src/canvas.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

#import util: typst-length

/// Sets up a canvas for drawing on.
/// Sets up a canvas for drawing on.
///
/// The default transformation matrix of the canvas is set to:
/// $mat(1,0,0.5,0;
/// 0,-1,-0.5,0;
/// 0,0,0,0;
/// 0,0,0,1)$
///
/// - length (length,ratio): Used to specify what 1 coordinate unit is. If given a ratio, that ratio is relative to the containing elements width!
/// - body (none,array,element): A code block in which functions from `draw.typ` have been called.
Expand Down Expand Up @@ -41,11 +47,14 @@
prev: (pt: (0, 0, 0)),
em-size: measure(box(width: 1em, height: 1em), st),
style: styles.default,
// Current transform
transform: matrix.mul-mat(
matrix.transform-shear-z(.5),
matrix.transform-scale((x: 1, y: -1, z: 1)),
),
// Current transformation matrix, a lhs coordinate system
// where z is sheared by a half x and y.
// +x = right, +y = up, +z = 1/2 (right + up)
transform:
((1, 0,+.5, 0),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess hand writing the matrix, instead of using 2 multiplications, is more clear.

(0,-1,-.5, 0),
(0, 0, .0, 0),
(0, 0, .0, 1)),
// Nodes, stores anchors and paths
nodes: (:),
// group stack
Expand Down
Binary file modified tests/decorations/path/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading