Sketch close returns start point of for construction edge when closing non construction edge
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 541
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 5
Description
`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.
```py
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")
```

Uncommenting `assemble()`:

A solution is to omit close by explicitly specifying the edge end/start point:
```py
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()
)
```

Solution using callback:
```py
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:
```py
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.