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

XDGF: replace an elliptical arc with a line when a control point is co-linear with begin and end #601

Closed
wants to merge 4 commits into from

Conversation

komarovd95
Copy link

We've faced an issue with elliptical arcs in VSDX files - when a control point of the elliptic arc is co-linear (i.e. lies on the same line) with begin and end points of the arc, it leads to very huge numbers when calculating coordinates of the center of the arc.

It happens because slopes of two tangents (class EllipticalArcTo lines 198 and 201) are equal to each other which leads to division by zero (or by value that is very near to zero).

As the solution it's proposed to check co-linearity before calculating an arc. I added this condition check into EllipticalArcTo#createEllipticalArc method to also cover corner-cases with ArcTo (which uses the method under the hood) and with RelEllipticalArcTo.

Below you can find an example that high-lights the problem.
Screenshot 2024-02-29 at 16 11 00

And after the fix:
Screenshot 2024-02-29 at 16 12 11

The file itself (just change extension to .vsdx since GitHub does not allow to upload VSDX files)
Single Icon.zip

@@ -40,9 +39,9 @@ public void setDebugAcceptor(ShapeVisitorAcceptor acceptor) {
}

@Override
protected Path2D drawPath(XDGFShape shape) {
Copy link
Contributor

@pjfanning pjfanning Feb 29, 2024

Choose a reason for hiding this comment

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

does this compile? Regardless, I don't think we should change protected method signatures in a patch release. Could you consider adding new private methods and leave the protected methods alone?

Copy link
Author

Choose a reason for hiding this comment

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

Hey @pjfanning! Good catch. I completely forgot that ShapeRenderer class might be used outside of poi codebase itself.

Can you please check out the last revision? I reverted changing the method signature and preserved its behaviour. Now, it draws all the sections but returns only first drawn path.

@komarovd95
Copy link
Author

Hi @pjfanning! Can you please take a look one more time?

@@ -0,0 +1,76 @@
package org.apache.poi.xdgf.usermodel.section.geometry;
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add license headers to the new files?

Copy link
Author

Choose a reason for hiding this comment

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

Just pushed the changes. Headers are added to this file and TestGeometryUtils.java.

@asfgit asfgit closed this in baae7b0 Mar 6, 2024
@pjfanning
Copy link
Contributor

thanks - merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants