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

Mitigate abnormally generated areas #989

Merged
merged 12 commits into from
Jul 14, 2023

Conversation

jamesbradleym
Copy link
Contributor

@jamesbradleym jamesbradleym commented Jul 3, 2023

BACKGROUND:

  • Polygon.Area() unexpectedly returned a negative area, turns out Polygon.Area() returns a signed area which some may find confusing.

DESCRIPTION:

  • Adds a bool signed = false default parameter to the Area function.
  • Polygon.Area() now returns a signed (signed=true) or magnitude area (signed=false)

TESTING:

  • Create a Polygon and check Polygon.Area value

FUTURE WORK:

REQUIRED:

  • All changes are up to date in CHANGELOG.md.

COMMENTS:


This change is Reviewable

@andrewheumann
Copy link
Member

Just want to make sure @ikeough doesn't have any objections to this change (and folding it as an additional breaking change into 2.0)

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @jamesbradleym)


Elements/src/Geometry/Polygon.cs line 2169 at r1 (raw file):

        /// Calculate the polygon's area in 3D.
        /// </summary>
        /// <returns>A double representing the signed or absolute value of this Polygon's area.</returns>

missing a comment for the signed parameter.

Copy link
Contributor Author

@jamesbradleym jamesbradleym left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @andrewheumann)


Elements/src/Geometry/Polygon.cs line 2169 at r1 (raw file):

Previously, andrewheumann (Andrew Heumann) wrote…

missing a comment for the signed parameter.

Done.

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Make sure to update the "changed" section of CHANGELOG.md with something like "Polygon.Area() now returns an unsigned area by default, and accepts a signed parameter to preserve the previous behavior."

Reviewed all commit messages.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @jamesbradleym)


Elements/src/Geometry/Polygon.cs line 2169 at r1 (raw file):
gonna be fussy and propose:

"If true, a counter-clockwise polygon will yield a positive area, while a clockwise polygon will give a negative area." or something like that. but LGTM!

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Just a ping, I think we want to get this in for the 2.0 release

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @jamesbradleym)

Copy link
Contributor Author

@jamesbradleym jamesbradleym left a comment

Choose a reason for hiding this comment

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

Whoops! Added comments and change log note

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @andrewheumann)


Elements/src/Geometry/Polygon.cs line 2169 at r1 (raw file):

Previously, andrewheumann (Andrew Heumann) wrote…

gonna be fussy and propose:

"If true, a counter-clockwise polygon will yield a positive area, while a clockwise polygon will give a negative area." or something like that. but LGTM!

Done.

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Some tests are failing. There may have been code in the library that depended on the signed area behavior which is now breaking.

Reviewable status: 1 change requests, 0 of 1 approvals obtained

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Also, there are many places in the code that call Math.Abs({something}.Area()). The .Abs calls are no longer needed and may be removed.

Reviewable status: 1 change requests, 0 of 1 approvals obtained

Copy link
Contributor Author

@jamesbradleym jamesbradleym left a comment

Choose a reason for hiding this comment

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

Went through the tests and found that one of the Mesh Volume tests anticipated an area to be signed negative as it was a boolean mesh. The test itself is validating whether or not the Mesh.Volume() value is accurate, what are your thoughts on including another test for Polygon.Area(true) for signed areas?

Went through the code and removed Math.Abs() that wrapped Polygon.Area()

Reviewed 2 of 2 files at r3, 7 of 7 files at r4, all commit messages.
Reviewable status: 1 change requests, 0 of 1 approvals obtained

Copy link
Contributor Author

@jamesbradleym jamesbradleym left a comment

Choose a reason for hiding this comment

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

var c = Polygon.Rectangle(3.0, 2.0);
Assert.Equal(-6.0, c.Reversed().Area(true));

Reviewable status: 1 change requests, 0 of 1 approvals obtained

Copy link
Member

@andrewheumann andrewheumann left a comment

Choose a reason for hiding this comment

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

Feel free to add that test if you feel like it! but this :lgtm:

Reviewed 6 of 7 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained

@jamesbradleym jamesbradleym merged commit 88a27bc into master Jul 14, 2023
2 checks passed
@jamesbradleym jamesbradleym deleted the mitigate-abnormally-generated-areas branch July 14, 2023 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants