drawable.apply-transform alternative #901
Replies: 3 comments 4 replies
-
|
I can see a use of this and I think Here is a hack that works (I hope): #import "@preview/cetz:0.4.0"
#import "@preview/cetz-plot:0.1.2"
#set page(width: auto, height: auto, margin: 0.6pt)
#let custom(body) = (
ctx => {
let old-ctx = ctx
let (ctx, drawables, bounds) = cetz.process.many(ctx, body)
let t = cetz.matrix.transform-translate(-4,-2,0)
// Hack: Find all new & changed nodes and install a new anchor handler.
// This is private API and might break with a new release!
for (name, value) in ctx.nodes {
if name not in old-ctx.nodes or old-ctx.nodes.at(name) != value {
let old-anchors = ctx.nodes.at(name).anchors
ctx.nodes.at(name).anchors = (name) => {
if name != () {
cetz.matrix.mul4x4-vec3(t, old-anchors(name))
} else {
old-anchors(name)
}
}
}
}
return (
ctx: ctx,
drawables: cetz.drawable.apply-transform(
t, drawables,
)
)
},
)
#cetz.canvas({
import cetz.draw: *
custom(circle((3,1), name: "c"))
for-each-anchor("c", name => {
circle((), radius: .1)
})
})Although, I do not like the search for the changed/new nodes. |
Beta Was this translation helpful? Give feedback.
-
|
Do you have an idea for an API? Maybe add a |
Beta Was this translation helpful? Give feedback.
-
|
Maybe returning all the names here: Line 44 in 7c03afc Line 89 in 7c03afc ctx.nodes.archors with a list of names. Not sure how else it should work.Alternative is returning a list of elements instead of names and then adding them to the ctx.nodes dict by hand…
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
To place an element correctly in my drawing, I use
process.manyto compute its bounds. It works as I want, but after that, I need to draw the element again, which almost doubles my rendering time. To optimize that, I tried to usedrawable.apply-transformto use the drawable output.The thing is that it doesn't translate the anchors. I searched the code, and it
seems complicated to translate all the anchors.
Is there a way to have the correct anchors and the translation without having to compute the drawing twice?
Here is a skeleton of the code:
Beta Was this translation helpful? Give feedback.
All reactions