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

Sketch close returns start point of for construction edge when closing non construction edge #1443

Open
lorenzncode opened this issue Nov 18, 2023 · 1 comment
Labels
bug Something isn't working sketching

Comments

@lorenzncode
Copy link
Member

Sketch close() closes an edge that is not for construction with an edge created with forConstruction=True.

I attempted to close the triangle with itself, however, it was closed with the starting point of the for construction arc.

import cadquery as cq

s0 = (
    cq.Sketch()
    .arc((0, 0), 30, 0, 120, tag="e0", forConstruction=True)
    .edges(tag="e0")
    .distribute(1, rotate=False)
    .segment((0, 0), (10, 2))
    .segment((10, -2))
    .close()
    # .assemble()
)

show_object(s0, name="s0")

issue1

Uncommenting assemble():

issue1_assemble

A solution is to omit close by explicitly specifying the edge end/start point:

s0 = (
    cq.Sketch()
    .arc((0, 0), 30, 0, 120, tag="e0", forConstruction=True)
    .edges(tag="e0")
    .distribute(1, rotate=False)
    .segment((0, 0), (10, 2))
    .segment((10, -2))
    .segment((0, 0))
    .assemble()
)

without_close

Solution using callback:

def triangle(loc):
    s = cq.Sketch().segment((0, 0), (10, 2)).segment((10, -2)).close().assemble()
    return s.moved(loc)


s0 = (
    cq.Sketch()
    .arc((0, 0), 30, 0, 120, tag="e0", forConstruction=True)
    .edges(tag="e0")
    .distribute(1, rotate=False)
    .each(triangle)
)

Is there a scenario where it is desired to close an edge in non construction mode with an edge in construction mode?
If not, perhaps Sketch _startPoint can be changed to something like this:

    def _startPoint(self) -> Vector:

        if not self._edges:
            raise ValueError("No free edges available")

        # find the first edge matching current edge mode
        mode = self._edges[-1].forConstruction 
        for edge in reversed(self._edges):
            if edge.forConstruction != mode:
                break
            prevedge = edge

        e = prevedge

        # current implementation selects first edge:
        # e = self._edges[0]

        return e.startPoint()

I didn't find any failing tests with this change.

@adam-urbanczyk adam-urbanczyk added the bug Something isn't working label Jan 4, 2024
@adam-urbanczyk
Copy link
Member

Thanks @lorenzncode , I think that the proposal makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sketching
Projects
None yet
Development

No branches or pull requests

2 participants