Skip to content

Add a bezier primitive - #333

Closed
SekoiaTree wants to merge 1 commit into
typst:mainfrom
SekoiaTree:bezier-primitive
Closed

SekoiaTree wants to merge 1 commit into
typst:mainfrom
SekoiaTree:bezier-primitive

Conversation

@SekoiaTree

Copy link
Copy Markdown
Contributor

Related to #260. Adds a Bezier primitive, documented and tested with some basic tests.

Like line there's a start and an end. Although the line docs say end is an offset relative to the start, from my testing they're not, so I did the same for bezier.

Beziers also have a start-control-point and end-control-point which are relative to their respective end point. Finally, just like line, the stroke is configurable.

@SekoiaTree SekoiaTree changed the title Add a bezier primitve Add a bezier primitive Mar 26, 2023
@LaurenzV

Copy link
Copy Markdown
Collaborator

I'm thinking, would it make sense to rename the method to curve instead of bezier? I think the term curve would be more easily understandable for most people.

And is there something speaking against actually just combining this with line (i.e. add start-control-point and end-control-point as additional parameters to line?

@SekoiaTree

Copy link
Copy Markdown
Contributor Author

line has the length and angle parameters, which make much less sense for a curve.

As for renaming, no problem, but Bezier is more explicit? And it'll pop up if you search for "curve" in the docs.

@laurmaedje

Copy link
Copy Markdown
Member

I think it would make sense if a single curve/bezier call could produce a curve with multiple segments. Otherwise, filling won't work properly. A single stroked curve would just be a special case of that.

@Enivex

Enivex commented Mar 28, 2023 •

Copy link
Copy Markdown
Collaborator

Can I suggest using the Hobby algorithm? Here's a tex implementation:

https://ctan.org/pkg/hobby?lang=en

It's very aesthetically pleasing.

@SekoiaTree

Copy link
Copy Markdown
Contributor Author

I think it would make sense if a single curve/bezier call could produce a curve with multiple segments. Otherwise, filling won't work properly. A single stroked curve would just be a special case of that.

Sure, but at that point I'd rather call it "path" (and probably open a different PR). Here's a quick syntax proposal:

  • "closed" boolean parameter which determines if we close it off at the end with a straight line
  • stroke parameter
  • fill parameter
  • a list of vertices, each written as either a single 2 element array, or an array of 2 points (1 mirrored point) or an array of 3 points (1 vertex + 2 control points)

Type-wise, I almost feel we should create a "Point" type that can be coerced from a 2 element array, for ease of writing.

Opinions?

@SekoiaTree

Copy link
Copy Markdown
Contributor Author

Can I suggest using the Hobby algorithm? Here's a tex implementation:

https://ctan.org/pkg/hobby?lang=en

It's very aesthetically pleasing.

Seems like that would fit under "one mirrored control point", correct?

@laurmaedje

laurmaedje commented Mar 28, 2023 •

Copy link
Copy Markdown
Member

Opinions?

Seems sensible. The problem with the Point type is that it already exists, but only allows absolute units. I had a similar problem with Length and Abs as well as Stroke and PartialStroke. Naming is hard.

Path also makes sense although one could confuse it for a file path.

@Enivex

Enivex commented Mar 28, 2023

Copy link
Copy Markdown
Collaborator

Can I suggest using the Hobby algorithm? Here's a tex implementation:
https://ctan.org/pkg/hobby?lang=en
It's very aesthetically pleasing.

Seems like that would fit under "one mirrored control point", correct?

I don't think so. The goal of Hobby's algorithm is to create nice looking interpolating splines through a list of points, with some degree of freedom. I'm not intimately familiar with the actual algorithm, but I think it's somewhat more complicated than that. It was originally published in this paper https://link.springer.com/article/10.1007/BF02187690

@SekoiaTree

Copy link
Copy Markdown
Contributor Author

You're right, it's not the same. However it can be described using Beziers, so this would probably be an extension rather than a core thing.

@SekoiaTree

Copy link
Copy Markdown
Contributor Author

Opinions?

Seems sensible. The problem with the Point type is that it already exists, but only allows absolute units. I had a similar problem with Length and Abs as well as Stroke and PartialStroke. Naming is hard.

Path also makes sense although one could confuse it for a file path.

I'll look into it then. In the meantime I'll leave this open, but I'll probably open another PR once that's done.

@SekoiaTree SekoiaTree mentioned this pull request Apr 2, 2023
@SekoiaTree

Copy link
Copy Markdown
Contributor Author

Superseded by #536

@SekoiaTree SekoiaTree closed this Apr 2, 2023
@SekoiaTree
SekoiaTree deleted the bezier-primitive branch August 7, 2023 19:49
kan190729 pushed a commit to oss-experiment-uec/2024-k2210165-typst that referenced this pull request Dec 23, 2024
Remove unused Jenkinsfile and yarn.lock files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants