komarovd95 opened a new pull request #270: URL: https://github.com/apache/poi/pull/270
Hi, I faced an issue with drawing circular arcs provided from VSDX files (`ArcTo` geometry rows). The current implementation has some bugs: it tries to draw an elliptical arc (see arguments `width` and `height` of `Arc2D.Double` constructor) because chord length equals `2 * radius` only if this chord is a diameter. And it always draws a half of that ellipse (180 degrees angle extent). The proposed fix uses 3 simple steps to draw an accurate circular arc: 1. Find a normal vector to the arc's chord. 2. Normalise the length of the normal vector (just divide by the length). 3. Set the origin of the normal vector to the midpoint of the chord. 4. Multiply the normal vector by the height of the arc (aka `a` parameter from the arc). Note that this parameter can be negative (like in example below). 5. The endpoint of this vector is the third point on the circle. Using these 3 points we can draw an elliptical arc by calling an existing method `EllipticalArcTo#createEllipticalArc`. Note that we need to set the parameter `d` of this method to 1 because we draw a circular arc. This is how my shape is drawn with the current version of Apache POI: <img width="344" alt="Screenshot 2021-10-27 at 15 55 30" src="https://user-images.githubusercontent.com/11631627/139085646-893d8637-75c0-4f9a-8087-525319fbcf6d.png"> This is how my shape is drawn after the patch (the shape looks like it looks in MS Visio): <img width="356" alt="Screenshot 2021-10-27 at 16 19 49" src="https://user-images.githubusercontent.com/11631627/139085785-59110d1b-0c5e-4716-9d50-3a2f0340d0dc.png"> Also, I attached a VSDX file with that diagram (just rename it from `.zip` to `.vsdx`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
