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

feat(decorations): add flat-brace #238

Merged
merged 3 commits into from
Oct 3, 2023
Merged

feat(decorations): add flat-brace #238

merged 3 commits into from
Oct 3, 2023

Conversation

RubixDev
Copy link
Contributor

@RubixDev RubixDev commented Oct 1, 2023

This PR adds a second kind of brace which isn't just composed of two bezier curves, but four small curves plus two straight lines. This is the same approach as used by TikZ: https://github.com/pgf-tikz/pgf/blob/6e5fd71581ab04351a89553a259b57988bc28140/tex/generic/pgf/libraries/decorations/pgflibrarydecorations.pathreplacing.code.tex#L136-L185. It has the advantage that the spike's position doesn't have to be in the center of the brace and it generally looks better for small amplitudes.

Screenshot of the example in the manual:
image

@johannes-wolf
Copy link
Member

Can you add a test for flat-brace, please? Looks pretty good!

@RubixDev
Copy link
Contributor Author

RubixDev commented Oct 3, 2023

Sure

Copy link
Member

@johannes-wolf johannes-wolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@johannes-wolf johannes-wolf merged commit cea2081 into cetz-package:master Oct 3, 2023
1 check passed
@ParaN3xus
Copy link

There might be a bug while using flat-brace with anchor.

For example, I expected to get a flat-brace pointing to point O and B (whose anchor is defined in the plot), but the direction seems to be wrong.
PixPin_2024-03-02_10-15-22

Same code with brace won't produce this issue.
PixPin_2024-03-02_10-15-43

Code in pictures:

#let c=3
#cetz.canvas(length: 2.5cm, 
{
  import cetz.draw: *
  import cetz.plot

  plot.plot(
    size: (2.6, 2.6),
    axis-style: "school-book",

    x-max: 8.5,
    x-min: -1.5,
    y-max: 8.5,
    y-min: -1.5,

    x-tick-step: 5,
    x-minor-tick-step: 1,
    y-tick-step: 5,
    y-minor-tick-step: 1,

    x-grid: "both",
    y-grid: "both",

    name: "p",
    {
      plot.add(
        axes: ("x", "y"),
        
        domain: (-2, 11), x => (x * x - c * c)/(2 * c)
      )
      plot.add(
        axes: ("x", "y"),
        domain: (-2, 11), x => -1 / 2 *  (x - 6) + 4.5
      )
      plot.add(
        axes: ("x", "y"),
        domain: (0, 6), x => 4.5 / 6 * x
      )

      plot.add-anchor("O", (0, 0))
      plot.add-anchor("A", (6, 4.5))
      plot.add-anchor("B", (0, 7.5))
    }
  )
  
  circle("p.O", radius: 0.03, name: "pointO")
  content((rel: (-0.1, 0.1)), $O$)

  circle("p.A", radius: 0.03)
  content((rel: (0.1, 0.1)), $A$)

  circle("p.B", radius: 0.03)
  content((rel: (0.1, 0.1)), $B$)

  cetz.decorations.brace("p.B", "p.O")

})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants