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

build123d imports SVG incorrectly (but ocpsvg does not show this issue) #661

Closed
jldeon opened this issue Jul 19, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@jldeon
Copy link

jldeon commented Jul 19, 2024

I've got the latest version (0.6.0) of build123d installed. I am trying to render an SVG file that contains 2 L shapes:

ll

This renders in most SVG viewers (browsers, Inkscape, etc) looking like LL.

When I use import_svg to import it to build123d:

from build123d import *

with BuildSketch() as svg:
    svg_obj = import_svg("ll.svg")
    add(svg_obj)
display(svg.sketch)

... it renders with the first L flipped along the X axis, and the second L is in the correct orientation.

If I write similar code to render this in ocpsvg directly:

from ocpsvg import ColorAndLabel, import_svg_document

svg_path = "ll.svg"

imported = list(import_svg_document(svg_path, metadata=ColorAndLabel))

for face_or_wire, color_and_label in imported:
    show_object(
        face_or_wire,
        f"{color_and_label.label} #{id(face_or_wire):x}",
        dict(color=color_and_label.stroke_color),
    )

... the output is correct - LL.

Is there something wrong with my build123d code, or is this a bug in build123d?

@gumyr gumyr added the bug Something isn't working label Jul 20, 2024
@gumyr gumyr added this to the Gating Release 1.0.0 milestone Jul 20, 2024
@gumyr
Copy link
Owner

gumyr commented Jul 20, 2024

Thanks for raising the issue; it has nothing to do with SVG. The problem occurs because one of the "L"s is up-side-down:

show(import_svg("ll.svg"))

Screenshot from 2024-07-20 09-51-52
The same issue can be seen by just flipping a Face over:

f1 = make_face(Polyline((4, 0), (7, 0), (7, 1), (5, 1), (5, 6), (4, 6), (4, 0))).face()
f2 = -make_face(Polyline((0, 0), (3, 0), (3, 1), (1, 1), (1, 6), (0, 6), (0, 0))).face()
with BuildSketch() as s:
    add(f1)
    add(f2)
show_all()

image

The problem was in Face.is_coplanar which required that the Face normal and the Plane z_dir be equal which resulted in flipped Faces being declared non-coplanar which wasn't the desired behavior. I've relaxed this requirement to allow normal and flipped Faces to be coplanar which fixes the problem and causes your code to generate:
image

@gumyr gumyr closed this as completed Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants