-
Notifications
You must be signed in to change notification settings - Fork 146
Upstream svgpathtools improvement - v2.1 #236
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
Upstream svgpathtools improvement - v2.1 #236
Conversation
Hi @NGExplorer, it looks like several of my requests / comments in #233 have not been taken care of yet. Please take a second look. |
Also, would it be possible for you to add some test? |
Hello @mathandy , On vglite-tools-2.1 branch we've incorporated following changes,
Let us know if we missed something to improve svgpathtools. |
Hi @mathandy |
svgpathtools/svg_to_paths.py
Outdated
|
||
return d + 'z' | ||
|
||
return d + ' Z' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change have any effect?
(if no, let's remove it to avoid unnecessarily changing output)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this changes does not have side-effect. We will remove it.
svgpathtools/svg_to_paths.py
Outdated
@@ -1,3 +1,6 @@ | |||
# | |||
# Modified by NXP 2024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this attribution -- many folks have worked on this file and your contributions are recorded in the git blame and likely the GitHub contributors view also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mathandy
This is the modification copyright according to our NXP policy.
For the newly created files we have to add:
"Copyright 2025 NXP"
and just for those kind of files that already exist, but without copyright, we do not want to take any extra credit so this is why it says just:
"Modified by NXP 2025"
Please let me know if staying as is looks acceptable to you.
svgpathtools/svg_to_paths.py
Outdated
@@ -68,7 +94,7 @@ def polyline2pathd(polyline, is_polygon=False): | |||
# The `parse_path` call ignores redundant 'z' (closure) commands | |||
# e.g. `parse_path('M0 0L100 100Z') == parse_path('M0 0L100 100L0 0Z')` | |||
# This check ensures that an n-point polygon is converted to an n-Line path. | |||
if is_polygon and closed: | |||
if is_polygon or closed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the justification for this change?
I think this needs to be reverted, but if you have some reason for the change, we can talk about a solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In SVG, a element is always rendered as a closed shape, regardless of whether the last point explicitly matches the first point. For example:
Test vector: shapes-polygon-01-t.svg
<polygon xml:id="polygon-01" fill="none" stroke="#000000" points="59,45,95,63,108,105,82,139,39,140,11,107,19,65" />
In this case, the first and last points differ, so a 'closed' flag computed from point equality would be false.
The original condition:
if is_polygon and closed:
points.append(points[0])
fails to append the starting point because closed flag is false, even though 'is_polygon' is True. This can lead to incorrect processing in cases where polygon closure needs to be explicitly handled in the logic.
To account for the SVG specification and ensure consistent behaviour, this condition should be updated to:
if is_polygon or closed:
points.append(points[0])
This change ensures that elements are always treated as closed paths, aligning with the SVG specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This can lead to incorrect processing in cases where polygon closure needs to be explicitly handled in the logic."
@NGExplorer Can you give an example of this please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This can lead to incorrect processing in cases where polygon closure needs to be explicitly handled in the logic."
@NGExplorer Can you give an example of this please?
I got your point,
polygon() uses polyline2pathd() internally.
closure is implicit in polygon and is_polygon already sets to True in such cases.
Where is in case of polyline is_polygon is false.
In vector drawing close command can be specified using 'z' or Line (origin) command.
We are trying to force 'z' command where possible.
As a result if we compute closed by taking is_polygon in consideration, original condition can be retained.
Patch may look something like following, We will check this in our test-suite and update you by EOD.
closed = (float(points[0][0]) == float(points[-1][0]) and
float(points[0][1]) == float(points[-1][1]))
+ closed = closed or (is_polygon == True)
if is_polygon and closed:
points.append(points[0])
+ if closed:
- if is_polygon or closed:
d += 'z'
With this change existing tests are failing. So, we've used only point count related change in final fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have extended test-suite to validate our fix.
Please check and approve changes.
svgpathtools/svg_to_paths.py
Outdated
"""converts the parameters from an ellipse or a circle to a string for a | ||
Path object d-attribute""" | ||
|
||
cx = ellipse.get('cx', 0) | ||
cy = ellipse.get('cy', 0) | ||
cx = (ellipse.get('cx', 0) or 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've made several changes like this -- what's the justification? Is null a valid option here? If so, why change it to zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this change.
Done. |
d422483
to
dfac122
Compare
Hello @mathandy , We have incorporated review comments. Please review. Best Regards, Nilam |
dfac122
to
0e39e95
Compare
@mathandy Please review and let us know if any changes are required. |
svgpathtools/svg_to_paths.py
Outdated
@@ -1,3 +1,6 @@ | |||
# | |||
# Modified by NXP 2024, 2025 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you leave this attribution in by accident or is there some reason you really want it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @mathandy
I left an explanation here: #236 (comment)
Is this acceptable to stay in the code? It just says that we, NXP, modified some code on the offending file. It is NXP policy to enforce this upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to make it a single line and move into or above the if-statement you added, I'll accept this PR and leave it.
If you need to leave it where it is and you won't be angry if I remove it later, then I'll merge and likely remove it later. I can't guarantee that attribution will stay for long though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we moved our modified copyright on the if block.
Thanks!
Looks great! I asked a question about the attribution, other than that, I think this is ready. |
0e39e95
to
b6370f7
Compare
… option References: MGG-1481, MGG-1656 When H/W does not have 'arc' command, circrle or ellispe can be drawn using cubic curves. Start ellipse path from rightmost point and draw clockwise Signed-off-by: Harikrushna Parmar <[email protected]>
…if no dedicated end path is provided References: MGG-1402, MGG-1448 * Handle case when no points are specified in polygon. * Update is_polygon properly for rectangle, polygon and polyline. Signed-off-by: Harikrushna Parmar <[email protected]>
* Added polyline.svg and polygons_no_poits.svg to validate recent changes to svgpathtools Signed-off-by: Nilam Gaikwad <[email protected]>
b6370f7
to
aeb799b
Compare
Thanks @nicusorcitu and @NGExplorer ! |
Fixes #232
Incorporated review comments mentioned in PR #233
@mathandy Please review and let us know if any changes are required.