Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Add Sector shape

Open ErrorCraft opened this issue 1 year ago • 15 comments

What does the pull request do?

This PR adds a Sector shape, similar to the Arc shape. Sector 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

ErrorCraft avatar Aug 03 '22 19:08 ErrorCraft

CLA assistant check
All CLA requirements met.

dnfadmin avatar Aug 03 '22 19:08 dnfadmin

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]

avaloniaui-team avatar Aug 03 '22 20:08 avaloniaui-team

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?

kekekeks avatar Aug 03 '22 20:08 kekekeks

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.

maxkatz6 avatar Aug 04 '22 21:08 maxkatz6

A sector is the proper mathematical name.

We were also discussing this here: https://github.com/AvaloniaUI/Avalonia/pull/6003#issuecomment-856046022

robloo avatar Aug 05 '22 02:08 robloo

there are other possible names https://en.wikipedia.org/wiki/Circular_sector

Sorien avatar Aug 05 '22 09:08 Sorien

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. Sector Shape Inner

ErrorCraft avatar Aug 06 '22 19:08 ErrorCraft

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).

robloo avatar Aug 07 '22 19:08 robloo

Would InnerRadius control inner oval height or width?

kekekeks avatar Aug 07 '22 19:08 kekekeks

Would InnerRadius control inner oval height or width?

Good point, I was thinking just for uniform/circular sectors.

Options:

  1. InnerRadius could be of type Size and have both width/height components together
  2. Break apart into two properties
    • InnerRadiusX
    • InnerRadiusY
  3. Break apart into two properties but follow the outer radius concepts/naming
    • InnerHeight
    • InnerWidth
  4. 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.
  5. Have a single InnerRadius property of type RelativeRect 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.

robloo avatar Aug 07 '22 19:08 robloo

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).

jp2masa avatar Aug 07 '22 22:08 jp2masa

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.

robloo avatar Aug 07 '22 22:08 robloo

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.

robloo avatar Aug 07 '22 23:08 robloo

RelativeSize type for the inner radius? So it can be specified as percentage OR absolute values.

maxkatz6 avatar Aug 08 '22 00:08 maxkatz6

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 a Rect 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.

robloo avatar Aug 10 '22 02:08 robloo

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.

robloo avatar Aug 14 '22 16:08 robloo

@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.

robloo avatar Aug 14 '22 18:08 robloo

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]

avaloniaui-team avatar Aug 14 '22 18:08 avaloniaui-team