deepnest-io / Deepnest

An open source nesting application for laser cutters, plasma cutters and other CNC machines.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SVG import doesn't clean up polyline

iliis opened this issue · comments

Importing an SVG with paths described by the polyline tag will result in open line segments instead of being merged into a closed path.

To Reproduce
Steps to reproduce the behavior:

  1. Download the following file (right click and 'Save Image As...'). It contains three squares (from left to right):
    1. A rectangle (svg:rect)
    2. A square made out of four paths (svg:path)
    3. A square made out of four polylines (svg:polyline).
      three_squares
  2. Import it in Deepnest

Expected Behavior
Three squares, as individual shapes.

Observed Behavior
Only the first two squares are correctly imported, the third one is ignored and shown in red.
image

Desktop:

  • OS: Windows 10 Enterprise (10.0.19045 Build 19045)
  • Deepnest Version: v1.1.4

Additional context
This issue came up when trying to import an SVG exported by the SVG exporter from OnShape. Exporting DXF seems to run into the same problem.
I can work around the issue with Inkscape by selecting everything and applying 'Path' -> 'Object to Path'. However, on a production file this takes a really long time and isn't really practical.

Thank you for your thorough report. Development has just restarted after a long summer-break. We are currently stuck with funding (a major sponsor went silent), see https://github.com/deepnest-io/Deepnest/issues/109. After publishing version 1.1.5, work on detail level (like this issue) can happen.

Importing an SVG with paths described by the polyline tag will

Are you sure that this is a commonly used construct? According to:

Typically a polyline is used to create open shapes as the last point doesn't have to be connected to the first point. For closed shapes see thehttps://developer.mozilla.org/en-US/docs/Web/SVG/Element/polygon element.

"polygon" should be used.

Issue

The issue seems to be:

=> Deepnest does not recognize shapes formed by multiple polylines

(which looks to me like a non-issue, or special-case/non-standard functionality)

Possible Solution

  • isolate code that "cleans up" svg:path
  • copy code, modify it to work with svg:polyline

(note that this is not of priority)

I do not know how common this is, but at least my CAD software exports a lot of shapes as polylines.
Here's an SVG straight from an OnShape drawing:

onshape_raw

This actually loads fine, but has an unwanted border and thus loads as one single piece in Deepnest:

image

When I ungroup the elements and remove the border in Inkscape and save it as (plain) SVG:
onshape_without_groups_and_border_plain

Then it looks like this in Deepnest:
image

Which is interesting, as some shapes are imported correctly, even though they are segmented polylines too. So maybe Deepnest tries to clean up the polylines but somehow fails for some? I tried various settings for the endpoint tolerance, but this didn't seem to have any effect.


I agree that maybe the CAD software should export with a different tag. However, this is a 2D drawing I'm exporting (projected from the 3D geometry), which in general can contain open open shapes (e.g. arrows or dimensions), so maybe that's why they are exporting everything as polylines.

I would argue this is still an issue though, at least for myself and following Postel's law ("be conservative in what you do, be liberal in what you accept from others"). If I have time I'll have a look at the code, but I'm not used to JavaScript.

my CAD software

Which is it? Maybe it has a configuration to tweak the output?

https://www.onshape.com/ and no, unfortunately it doesn't. At least not for SVG. The DXF export has a few options, but I didn't find any that worked either.

No postel's law here. Just the brutal reality of "lack of sponsors"...

I can spare a couple bucks, but nothing major. But I'm also not expecting you to do anything, just thought I'd report my findings.

fixed in 1.1.9

Thank you very much for woking on this! I've replied at the other issue.

@iliis , I'll reopen this as i'll publish 1.2.0 in the next days.

Funding deficit is anyways not your fault (you just came into the cross-fire).

@iliis , could you check this on your side to confirm it works?