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

Fixes SVGLoader arc parsing with zero radius path commands. #20644

Merged
merged 4 commits into from
Nov 10, 2020

Conversation

gregzanch
Copy link
Contributor

Related issue: #20641

Description

If an SVG path has an arc command (A/a) with zero radius the path data gets thrown off. Adding a check in the path parser for zero radius fixes this:

if( numbers[ j ] == 0 || numbers[ j + 1 ] == 0 ) {
  // draw a line if either of the radii == 0
  path.lineTo( point.x, point.y );
}

Also, to avoid unnecessary computation, a check for useless arc command was added:

// skip command if start point == end point
if( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 8, 2020

It's also necessary to update examples/js/loaders/SVGLoader.js. The idea is to edit this file and then create the jsm module via node utils/modularize.js.

for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
// skip command if start point == end point
if( numbers[ j + 5 ] == 0 && numbers[ j + 6 ] == 0 ) continue
Copy link
Collaborator

@yomboprime yomboprime Nov 8, 2020

Choose a reason for hiding this comment

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

Shouldn't this line be if( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Νο, the 'a' indicates that the arguments are relative to the current point, so a 0 means no displacement

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, missed that

Copy link
Collaborator

@yomboprime yomboprime left a comment

Choose a reason for hiding this comment

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

I found three things to be improved.

examples/jsm/loaders/SVGLoader.js Outdated Show resolved Hide resolved
@yomboprime
Copy link
Collaborator

Oops, I messed a little bit the review, but the three things are there.

Comment on lines 669 to 674
if( rx == 0 || ry == 0 ) {
// draw a line if either of the radii == 0
path.lineTo( end.x, end.y );
return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 389 to 391

// skip command if start point == end point
if( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrdoob
Copy link
Owner

mrdoob commented Nov 9, 2020

Minor thing: Can change the if(s to if (?

@mrdoob mrdoob added this to the r123 milestone Nov 9, 2020
@mrdoob mrdoob changed the title Fixes SVGLoader arc parsing with zero radius path commands. See #20641 Fixes SVGLoader arc parsing with zero radius path commands. Nov 9, 2020
@gregzanch
Copy link
Contributor Author

Minor thing: Can change the if(s to if (?

Just committed the changes!

@mrdoob mrdoob merged commit 212d498 into mrdoob:dev Nov 10, 2020
@mrdoob
Copy link
Owner

mrdoob commented Nov 10, 2020

Thanks!

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

4 participants