Avalonia
Avalonia copied to clipboard
Add Sector shape
What does the pull request do?
This PR adds a Sector shape, similar to the Arc shape.
It also adds three methods to the MathUtilities
class which are used in the Sector
class. (These can also be used in the Arc
class, I will likely make a PR for this as well if it is accepted.)
Checklist
- [ ] Added unit tests (if possible)?
- [ ] Added XML documentation to any related classes?
- [ ] Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with user documentation
You can test this PR using the following package version. 0.10.999-cibuild0022832-beta
. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]
The code looks OK, but I'm not quite sure about the naming, Sector
seems to be too ambigious. Could we name it CircularSector
or CircleSector
instead?
If there is a similar control/shape in other GUI frameworks, we can take naming from there. There is none in WPF/UWP/Xamarin from what I know.
A sector is the proper mathematical name.
We were also discussing this here: https://github.com/AvaloniaUI/Avalonia/pull/6003#issuecomment-856046022
there are other possible names https://en.wikipedia.org/wiki/Circular_sector
I mainly chose the name Sector
because it's consistent with the name Arc
. If the name is changed to CircularSector
then Arc
should likely be renamed to CircularArc
as well. Also speaking of https://github.com/AvaloniaUI/Avalonia/pull/6003#issuecomment-856046022, I was thinking of adding an inner radius to the sector as well to allow for something like this.
In terms of properties I would follow what was decided for arc and have:
-
StartAngle
(units: degrees) -
SweepAngle
(units: degrees, positive is clockwise, negative is counter-clockwise) (make sure to document these, especially degrees units)
Then I would add an
-
InnerRadius
(units: DI pixels same as height/width) I've seen many cases where this would be useful already.
There is no need for a Radius
property since the height/width of the shape itself define that (as currently reflected in the code).
Would InnerRadius control inner oval height or width?
Would InnerRadius control inner oval height or width?
Good point, I was thinking just for uniform/circular sectors.
Options:
-
InnerRadius
could be of typeSize
and have both width/height components together - Break apart into two properties
-
InnerRadiusX
-
InnerRadiusY
-
- Break apart into two properties but follow the outer radius concepts/naming
-
InnerHeight
-
InnerWidth
-
- Have a single, normalized
InnerRadiusScale
property that is applied to the outside height and width to calculate the inside height and width. This would ensure uniform aspect ratios for both inside and outside. - Have a single
InnerRadius
property of typeRelativeRect
that would support both relative (percentage) and absolute width/height
Option 3 might make the most sense considering how the overall shape size is set.
Edit: However, Option 2 follows Rectangle
which follows the original WPF naming. So there is precedent for this naming as well.
Note that allowing different inner radius Width/Height would allow some weird shapes which may or not be wanted (e.g. circle cut by ellipse, ellipse cut by circle, or ellipse cut by other, not proportional, ellipse).
As written now, the Sector class supports non-uniform width and height. If that is supported for the outside geometry we should have the same for inside geometry. Since arc allows this, it seems sector should as well. While strange if misused, I think the logic for API purposes makes sense.
Although, I suppose there is a 4th option and the inner radius would be specified as a percentage. Then it would follow the same aspect ratio as the outside geometry. That would ensure both inside and outside are always matching: either ellipse or circle.
RelativeSize type for the inner radius? So it can be specified as percentage OR absolute values.
I couldn't find a RelativeSize
type, but the RelativeRect
type should work for this. That would allow a single property and both relative/absolute size as mentioned. There are some downsides:
- Having a property called
InnerRadius
taking aRect
doesn't make a lot of sense - It would still be possible to have an outside oval and inside circle which was a concern mentioned above (not so much a concern for me)
- The percentage would have to be specified for both the height AND width. That defeats the simplicity of using a percentage which would also match inner aspect ratio with outer.
Well, it's probably best to just finish this up without the inner radius functionality. That can always be added back as a non-breaking change once the API is settled. There doesn't seem to standard anywhere and all the ideas here are quite different.
@maxkatz6 Are you ok with the properties for the arc in Sector
being different than in Arc
? That still doesn't seem right to me and I would standardize that at least before a merge.
You can test this PR using the following package version. 0.10.999-cibuild0023180-beta
. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]