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

Add circle sector recipe #3806

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JohannesNE
Copy link
Contributor

Description

Adds recipe for creating a circle sector.
arc is used as template for this, but instead of many lines imitating an arc, it creates a filled path using BezierPath. (Using code modified from an example from @jkrumbiegel ).

Related to #3741. And solves the problem I initially wanted to use the offset pie for.

Example:

using CairoMakie
f = Figure() 
Axis(f[1, 1], aspect = DataAspect())

for i in 1:10
    sector!(Point2f(i, 0), 0.4, 0, 2π*i/10, inner_radius = 0.2)
end

f

download

(btw, is there a smart way to trim this figure, which is also in the docs?)

I'm quite new to Julia/Dev, so I have a few questions:

  • Should I make a test for this, or are the examples in the docs enough?
  • An If-else statement is used to draw a sector if inner_radius is 0 or a "fat" arc if inner_radius is > 0. Is there a smarter way to do this?

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • Added an entry in CHANGELOG.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@jkrumbiegel
Copy link
Member

Thanks for the PR! I feel like this is so similar to pie that it's a bit confusing to have both. It has a scatter-like signature in that the position is the first positional arg(s) but other than that, I think an array-enabled offset or position keyword for pie would do a similar thing, no?

@jkrumbiegel
Copy link
Member

Hm although pie has this cumulative effect where one passes the fractions in order, maybe one would have to remodel that behavior a little then. So that one can pass array-valued offsets as well so it's start-stop for each?

@JohannesNE
Copy link
Contributor Author

JohannesNE commented Apr 25, 2024

pie with a position argument could accomplish the same.

I made this a seperate recipe for two reasons.

  1. In Add optional origin parameter to pie #3741 @SimonDanisch suggested making a separate recipe for making pie-scatters with a position argument, rather than add a position argument to pie.
  2. It feels backwards to use a more complex function (pie) to generate a primitive (a circle sector).

We could update pie to use sector, so it draws actual circles rather than a high-vertex polygon.

@jkrumbiegel
Copy link
Member

Ok I guess reusing it for pie internals makes more sense. Pie predates the bezier stuff, hence the vertices.

@JohannesNE
Copy link
Contributor Author

Ok I guess reusing it for pie internals makes more sense. Pie predates the bezier stuff, hence the vertices.

But that is a separate PR right?, or should I try to include it in this?

@jkrumbiegel
Copy link
Member

I would probably include it so you know whether your implementation is suitable for that purpose.

@jkrumbiegel
Copy link
Member

jkrumbiegel commented Apr 26, 2024

If it's a scatter-like thing then I'd probably change the signature to PointLike style to match scatter, so only the positions as positional args (with the default conversions from the PointLike trait). And the other settings as attributes, accepting either scalar or vector

@JohannesNE
Copy link
Contributor Author

Well, I did not consider whether it should be scatter-like or something else.
Really, I just wanted something similar to arc but drawing sectors, so it seemed simplest to just make it behave similar to arc.
Maybe it is more appropriate to add a Sector feature to GeometryBasics.jl and use poly, like for drawing a Circle or a Rect (thought I have no idea how to do that).

@t-bltg t-bltg added the recipes label May 11, 2024
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.

None yet

4 participants