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

SVG import: Add normalize_coordinates option #5038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chrysn
Copy link
Contributor

@chrysn chrysn commented Mar 14, 2024

This adds an option as described in #3460 (comment), closing #3460:

  • literal_coordinate
    Boolean. If set to true, the numeric values of x and y coordinates are used without format specific transformations.

    This argument only applies to SVG (or similar future formats): SVG's coordinate system applies the y value toward the bottom of the screen on the drawing plane, whereas in OpenSCAD's top view, y points toward the top of the screen. By default (i.e., when literal_coordinate=false), the import command flips an SVG file's y coordinates, and shifts the whole drawing into the positive area.

    Using literal_coordinate=true is particularly useful when the OpenSCAD script has additional information about positions inside the SVG file's coordinate system.

    This is mutually exclusive with the "center" argument.

There is open point from #3460 (comment): Should literal_coordinate also disregard scaling and force the import units to be SVG units, or is it fine as it is (and the documentation just needs slight adjustment)?

@t-paul
Copy link
Member

t-paul commented Mar 14, 2024

The option name feels a bit awkward, but I suppose the feature itself is useful. I don't have a good suggestion yet though.

This is mutually exclusive with the "center" argument.

Why? Is there a technical reason? It does not bring any additional feature as it should be identical to normal centered + y axis flipped but it might be helpful to not impose the exclusivity restriction.

@chrysn
Copy link
Contributor Author

chrysn commented Mar 14, 2024

I'm open for any other name.

As for being mutually exclusive with centering, this overrides all the coordinate processing -- scaling, flipping, viewbox adjustment and center offset. It's probably possible to apply center offsets still, but it kind of defeats the purpose of having the raw coordinates applied. All use cases where I've run into this were along the lines of "some tool generates me an SVG with a sidecar file of coordinates, and I want to put them together in 3D". (About 10 years ago it was visualizing PCBs, now it's assembling laser cut boxes in 3D). If you think it's useful to have, I think I can make it work, but I think it reduces maintainability without a practical benefit.

@t-paul
Copy link
Member

t-paul commented Mar 14, 2024

Oh, it skips transformations even on the objects? I don't think that will work, e.g. Inkscape has the tendency to modify the object transforms instead of the actual coordinates (create circle, make it a bit smaller, move slightly). Skipping those will just import random data.

@MichaelAtOz
Copy link
Member

I'm open for any other name.

flip=<true|*false>??

By default (i.e., when literal_coordinate=false), the import command FLIPS an SVG file's y coordinates, and shifts the whole drawing into the positive area.

@gsohler
Copy link
Member

gsohler commented Mar 15, 2024 via email

@chrysn
Copy link
Contributor Author

chrysn commented Apr 4, 2024

Oh, it skips transformations even on the objects?

No, it skips only the transformations that OpenSCAD would apply (the handedness correction / flip, the shift, and any centering). Anything internal to the SVG is preserved.

normalize

Sounds good, so it'd be normalize_coordinates=true/false. This also has the upside that (unlike the "literal" term) it'd be justifiable to stick with the current convention of OpenSCAD units being millimeters (as applying 'literal' coordinates to SVG's complex units system would be troublesome anyway).

The new parameter has the opposite semantics of the old parameter, and
thus the other default value.
@chrysn
Copy link
Contributor Author

chrysn commented Apr 4, 2024

With the PR updated, the documentation to be added would now be:

  • normalize_coordinates
    Boolean. If true (which is the default), OpenSCAD transforms coordinates from the file to be suitable in its coordinate system.

    This argument only applies to SVG (or similar future formats): SVG's coordinate system applies the y value toward the bottom of the screen on the drawing plane, whereas in OpenSCAD's top view, y points toward the top of the screen. During normalization of coordinates, the import command flips an SVG file's y coordinates, and shifts the whole drawing into the positive area.

    Using normalize_coordinates=false is particularly useful when the OpenSCAD script has additional information about positions inside the SVG file's coordinate system. The resulting object will appear to be mirrored upside down in the default view, but correct when viewed from the bottom.

    When this is set to false, the "center" argument is ignored, and a warning is shown if center=true.

@chrysn chrysn changed the title SVG import: Add literal_coordinate option SVG import: Add normalize_coordinates option Apr 13, 2024
@chrysn
Copy link
Contributor Author

chrysn commented Apr 13, 2024

Is there anything more I should adjust for this? From my point of view it is ready for final review.

remote

(Picture related: Assembling parts from SVG files requires precise control over the coordinate space.)

@chrysn
Copy link
Contributor Author

chrysn commented May 14, 2024

I've slightly extended the help text (around appearing mirrored), but that's kind of outside the PR. Is there anything I can do (add or remove) to advance this issue?

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