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 to rh coordinate system #502

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CeTZ 0.3.0 requires Typst 0.11.0

## Canvas
- Transformation matrices are now rounded
- The default coordinate system changed to a right-hand side system.
Use `scale(z: -1)` if you want to change back to a left-hand system.

## Plot
- Added support for automatically adding axis breaks (sawtooth lines) by setting the `break`
Expand Down
16 changes: 8 additions & 8 deletions src/canvas.typ
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
/// 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)$
/// $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 @@ -45,12 +45,12 @@
// Previous element position & bbox
prev: (pt: (0, 0, 0)),
style: styles.default,
// Current transformation matrix, a lhs coordinate system
// Current transformation matrix, a rhs coordinate system
// where z is sheared by a half x and y.
// +x = right, +y = up, +z = 1/2 (right + up)
// +x = right, +y = up, +z = 1/2 (left + down)
transform:
((1, 0,+.5, 0),
(0,-1,-.5, 0),
((1, 0,-.5, 0),
(0,-1,+.5, 0),
(0, 0, .0, 0),
(0, 0, .0, 1)),
// Nodes, stores anchors and paths
Expand Down
Binary file modified tests/arc/arc-through/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.
Binary file modified tests/arc/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.
Binary file modified tests/content/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.
Binary file modified tests/content/transform/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.
Binary file modified tests/cube/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.
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.
Binary file added tests/projection/default/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.
22 changes: 22 additions & 0 deletions tests/projection/default/test.typ
fenjalien marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#import "/src/lib.typ" as cetz
#import "/tests/helper.typ": *

// Positive direction
#test-case({
import cetz.draw: *

set-style(mark: (transform-shape: false))
line((0,0,0), (1,0,0), mark: (end: ">"))
line((0,0,0), (0,1,0), mark: (end: ">"))
line((0,0,0), (0,0,1), mark: (end: ">"))
})

// Negative direction
#test-case({
import cetz.draw: *

set-style(mark: (transform-shape: false))
line((0,0,0), (-1,0,0), mark: (end: ">"))
line((0,0,0), (0,-1,0), mark: (end: ">"))
line((0,0,0), (0,0,-1), mark: (end: ">"))
})
Loading