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

Added DrawRectangle overload accepting RectangleF #62385

Merged
merged 9 commits into from
Jan 11, 2022
Merged

Added DrawRectangle overload accepting RectangleF #62385

merged 9 commits into from
Jan 11, 2022

Conversation

medo64
Copy link
Contributor

@medo64 medo64 commented Dec 4, 2021

FillRectangle contains the following 4 overloads:

  • public void FillRectangle(Brush brush, RectangleF rect)
  • public void FillRectangle(Brush brush, float x, float y, float width, float height)
  • public void FillRectangle(Brush brush, Rectangle rect)
  • public void FillRectangle(Brush brush, int x, int y, int width, int height)

However, DrawRectangle, contains only the following 3 overloads:

  • public void DrawRectangle(Pen pen, Rectangle rect)
  • public void DrawRectangle(Pen pen, float x, float y, float width, float height)
  • public void DrawRectangle(Pen pen, int x, int y, int width, int height)

In the interest of symmetry, I propose adding the "missing" RectangleF overload:

  • public void DrawRectangle(Pen pen, RectangleF rect)

Since overload taking individual elements already exists, this new overload will just "decompose" rectangle structure into individual elements and call the existing function. Approach is exactly the one used in FillRectangle code.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 4, 2021
@ghost
Copy link

ghost commented Dec 4, 2021

Tagging subscribers to this area: @dotnet/area-system-drawing
See info in area-owners.md if you want to be subscribed.

Issue Details

FillRectangle contains the following 4 overloads:

  • public void FillRectangle(Brush brush, RectangleF rect)
  • public void FillRectangle(Brush brush, float x, float y, float width, float height)
  • public void FillRectangle(Brush brush, Rectangle rect)
  • public void FillRectangle(Brush brush, int x, int y, int width, int height)

However, DrawRectangle, contains only the following 3 overloads:

  • public void DrawRectangle(Pen pen, Rectangle rect)
  • public void DrawRectangle(Pen pen, float x, float y, float width, float height)
  • public void DrawRectangle(Pen pen, int x, int y, int width, int height)

In the interest of symmetry, I propose adding the "missing" RectangleF overload:

  • public void DrawRectangle(Pen pen, RectangleF rect)

Since overload taking individual elements already exists, this new overload will just "decompose" rectangle structure into individual elements and call the existing function. Approach is exactly the one used in FillRectangle code.

Author: medo64
Assignees: -
Labels:

area-System.Drawing

Milestone: -

@Wraith2
Copy link
Contributor

Wraith2 commented Dec 4, 2021

If there is an approved api issue for this can you link to it please? If not you will need to go through the Api Approval Process before it is added.

@medo64
Copy link
Contributor Author

medo64 commented Dec 4, 2021

If there is an approved api issue for this can you link to it please? If not you will need to go through the Api Approval Process before it is added.

I have added the API proposal. Will wait for result of the same. :)

@teo-tsirpanis
Copy link
Contributor

teo-tsirpanis commented Dec 5, 2021

Since you are adding a new API you also have to add it in the reference assembly's sources.

public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.Rectangle rect) { }
public void DrawRectangle(System.Drawing.Pen pen, int x, int y, int width, int height) { }
public void DrawRectangle(System.Drawing.Pen pen, float x, float y, float width, float height) { }
public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.RectangleF[] rects) { }
public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.Rectangle[] rects) { }

@dnfadmin
Copy link

dnfadmin commented Dec 6, 2021

CLA assistant check
All CLA requirements met.

@medo64
Copy link
Contributor Author

medo64 commented Dec 6, 2021

Since you are adding a new API you also have to add it in the reference assembly's sources.

Added, thank you.

@safern
Copy link
Member

safern commented Dec 6, 2021

@medo64 thanks for your contribution, given that the API Proposal issue has to be approved first, let's wait for it get reviewed by the review board and if approved we can reopen this PR. I will close the PR to follow the API Proposal guidelines on the repository, and we can reopen when ready.

@safern safern closed this Dec 6, 2021
@medo64
Copy link
Contributor Author

medo64 commented Dec 15, 2021

API proposal has been approved. Please reopen this pull request.

@safern
Copy link
Member

safern commented Dec 15, 2021

@medo64 could you mind adding a test for each added API

@teo-tsirpanis
Copy link
Contributor

teo-tsirpanis commented Dec 15, 2021

@medo64 I made a mistake previously about the reference assembly's sources, you need to add the new API definitions to src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs instead of System.Drawing.Common.cs (these new APIs will be available only for .NET Core). Please move them from the latter to the former.

@safern
Copy link
Member

safern commented Dec 15, 2021

@teo-tsirpanis the other overloads are available for all target frameworks, so I think it is fine to keep them in all targets.

@teo-tsirpanis
Copy link
Contributor

Well, I got confused, the .NET Framework 4.6.1 assembly on NuGet has only type forwards on the framework library, not actual types.

@medo64
Copy link
Contributor Author

medo64 commented Dec 16, 2021

@medo64 could you mind adding a test for each added API

For DrawRectangle I added an entry with RectangleF in every existing test I could find. Since other overloads are already actually tested here, I believe this is appropriate.

For FillPie there were no current test so I added basic argument tests modeled after tests present for DrawPie.

I do have two extra questions in regards to tests though:

  1. I see that Fill* methods are missing even basic argument tests. What is the process for adding the same? Should I open a [bug] and wait for approval or should I just add them to this PR?

  2. Test case named DrawPie_ZeroHeight_ThrowsArgumentException actually tests DrawArc method (looks to be a copy/paste error). Should I just make this minor correction here or should I open a new [bug] and wait for approval?

@medo64
Copy link
Contributor Author

medo64 commented Jan 10, 2022

Anything else you fill needs to be added or this is it?

@safern
Copy link
Member

safern commented Jan 10, 2022

I think @teo-tsirpanis was right and we need to move the APIs to the ref/netcoreapp.cs, that should fix the build. Also the tests should only be included for .NET Core targets, you can do that by putting them on their own .netcoreapp.cs test file and compile it only when we are targeting .NET Core.

@medo64
Copy link
Contributor Author

medo64 commented Jan 11, 2022

you can do that by putting them on their own .netcoreapp.cs test file

I see that there are some tests already in GraphicsTests.Core.cs and that one seems to be targeting NETCoreApp. Should I add tests in this one or you want me to create a new file instead?

@medo64
Copy link
Contributor Author

medo64 commented Jan 11, 2022

need to move the APIs to the ref/netcoreapp.cs

Do you mean System.Drawing.Common.netcoreapp.cs in my case? I cannot find just plain netcoreapp.cs file...

@safern
Copy link
Member

safern commented Jan 11, 2022

I see that there are some tests already in GraphicsTests.Core.cs and that one seems to be targeting NETCoreApp. Should I add tests in this one or you want me to create a new file instead?

Adding them to that file seems better.

Do you mean System.Drawing.Common.netcoreapp.cs in my case?

Yeah, I missed the * to state that.

* Only testing RectangleF overloads in GraphicsTests.Core.cs; other
  overloads stay as they are.
* FillPie tests that were newly added as part of issue #62385 are split
  in the same manner.
DrawRectangle with RectangleF overload is new and not compiled into
mono.
@safern safern merged commit 64f4885 into dotnet:main Jan 11, 2022
@safern
Copy link
Member

safern commented Jan 11, 2022

Thank you @medo64!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Drawing community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants