cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
733 stars 34 forks source link

[feature request] anchors for `line`'s coordinates #640

Open tapyu opened 3 days ago

tapyu commented 3 days ago

In

line(
    (0,1),
    (0,2),
    (0,3),
    mark: (end: ">"),
    name: "line"
  )

it would be interesting to have anchors to the coordinates that makes the line up. AFAIK CeTZ doesn't provide such anchor.

I propose the syntax "line.i" to access the ith coordinate. For instance, in "line", "line.1" would access (0,1), "line.2" would access (0,2), and so on.

PS: Path anchor (e.g., "line.30%") is not convenient when the line is very complex, so it is not a reasonable alternative.

johannes-wolf commented 3 days ago

Since <element>.<int> is already used for absolute length along a path, we could add anchors with a prefix like pt-: line.pt-1. What do you think?

tapyu commented 3 days ago

I see...

we could add anchors with a prefix like pt-: line.pt-1.

Are you proposing to add such prefix for absolute length anchors and leave the syntax "line.i" for my proposed anchor, right? If so, I think it is a good idea. However, I would suggest a small change: instead of "line.pt-1", I would adopt "line.1pt" for two reasons:

  1. 1pt matches with the syntax used for length types variables.
  2. No extra fancy - character is required.

Moreover, I think this "new" (AFAIU) anchor type deserves a subsection in sec 2.2 of CeTZ. It is distinct enough from named, border, and path anchor type. What do you think? I think so because the way we access it not based on a path, compass or angle, or a mere name. Rather, it is the ith coordinate used to construct the object (in this case, a line). I think the terms "coordinate anchor" or "order anchor" are good candidates to refer to it.

fenjalien commented 3 days ago

Are you proposing to add such prefix for absolute length anchors and leave the syntax "line.i" for my proposed anchor, right?

No, when using shorthand anchors, anchors that start with a digit are reserved for path anchors if the element supports them. What @johannes-wolf has proposed is that for each coordinate given to the line function a pt-i named anchor will be created, where i is the index of the coordinate. This is similar to how a bezier's control points are given anchors.

tapyu commented 3 days ago

Ah :( Well, it is up to you. I think pt-i too wordy, to be honest, but okay.

johannes-wolf commented 2 days ago

Something like pt-0, pt-1 is too wordy?

tapyu commented 1 day ago

Yes. Four characters when only one is actually useful.

This is obviously a matter of opinion, though. Fell free to disregard my point of view. Although it is verbose, pt-i is good, don't get me wrong. More importantly, this is the syntax used in CeTZ, like catmull, so I think it is the way-to-go for the sake of consistency.