How to connect line to non-rectangle/non-circle shape (each shape lives inside a square in debug mode)? #156
-
I have a manual operation block in a flowchart. I need to connect lines from the sides to #let manual-operation(name, start: none, direction: "down", text) = {
import cetz.draw: *
validate-start-coordinate(start)
validate-direction-vector(direction, valid-directions: ("down", "right"))
if direction == "down" {
start = (rel: (0, -height / 2), to: start)
} else if direction == "right" {
start = (rel: (width / 2, 0), to: start)
}
line(
(rel: (-width / 2, height / 2), to: start),
(rel: (width, 0)),
(rel: (-width / 4, -height)),
(rel: (-width / 4 * 2, 0)),
close: true,
name: name,
)
content(name + ".center", text)
} P.S. The right line should connect to the right edge of the block, but the left line isn't really connecting to anything anyway (this is kinda a bug in my implementation for now). Update: I was able to fix it by manually calculating perimeter and all edges, then using ...
let top = width
let bottom = width / 2
let side = calc.sqrt(calc.pow((top - bottom) / 2, 2) + calc.pow(height, 2))
let perimeter = top + bottom + side * 2
let right-offset = (top + side / 2) / perimeter
let left-offset = (top + side + bottom + side / 2) / perimeter
place-anchors(name: name, line(
(rel: (-width / 2, height / 2), to: start),
(rel: (width, 0)),
(rel: (-width / 4, -height)),
(rel: (-width / 4 * 2, 0)),
close: true,
name: name,
// ), (name: "left", pos: .88), (name: "right", pos: .465))
), (name: "left", pos: left-offset), (name: "right", pos: right-offset))
if direction == "right" { line(start-old, name + ".left") }
... This technically answers the question, but this is way more code/calculations that in my mind should be done. The anchor positions should be correct automatically or by providing a flag such as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I would do it by placing the path in a named group and overwriting the left/right anchor:
If you calculate all 4 coordinates, you can use linear interpolation |
Beta Was this translation helpful? Give feedback.
I would do it by placing the path in a named group and overwriting the left/right anchor: