CadQuery / CadQuery/cadquery

`moved()` and `offset2D()` bug. Different result when applying to different wire shape.

Open
#1,840 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

![Image](https://github.com/user-attachments/assets/c65efdb1-f39a-4d47-b9b2-87a914bcfe29)

**Bug 1**: When `moved` and `offset2D` applied to different shapes (circle or non-circle) , they result in different distance. (See screenshot. The wires group on top has larger distance)

**Bug 2**: A circle wire made by `section()` applied to middle of a circle-extruded solid fails to apply `moved` and `offset2D`

## To Reproduce

```python
import cadquery as cq
import traceback
print("=============================================")
solid = (
cq.Workplane()
.rect(1, 1)
.extrude(2)
.faces('>Z')
.circle(0.5)
.extrude(2)
)
show_object(solid)
r=0.2

arrz = [0, 1, 2, 3, 4]
for z in arrz:
try:
print(f'in loop {z=}')
wire0 = (cq.Workplane()
.add(solid).toPending()
.section(z)
.wires()
.val()
)
show_object(wire0, name=f'{z=} wire0')

wire_u = wire0.moved(cq.Vector(0, 0, r )).offset2D(0.1)
show_object(wire_u, name=f'{z=} wire_u')

wire_m1= wire0.moved(cq.Vector(0, 0, (1/3)*r )).offset2D(r)
show_object(wire_m1, name=f'{z=} wire_m1')

wire_m2= wire0.moved(cq.Vector(0, 0, -(1/3)*r )).offset2D(r)
show_object(wire_m2, name=f'{z=} wire_m2')

wire_d = wire0.moved(cq.Vector(0, 0, -r )).offset2D(0.1)
show_object(wire_d, name=f'{z=} wire_d')

except Exception as err:
traceback.print_exception(err)

```

## Backtrace

```
=============================================
in loop z=0
in loop z=1
in loop z=2
in loop z=3
Traceback (most recent call last):
File "", line 27, in
File "/home/username/.local/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py", line 2682, in offset2D
obj = downcast(offset.Shape())
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/.local/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py", line 374, in downcast
f_downcast: Any = downcast_LUT[shapetype(obj)]
^^^^^^^^^^^^^^
File "/home/username/.local/lib/python3.11/site-packages/cadquery/occ_impl/shapes.py", line 364, in shapetype
raise ValueError("Null TopoDS_Shape object")
ValueError: Null TopoDS_Shape object
in loop z=4

```

## Environment

OS:

```
$ pip3.11 list |grep -i -E "cq-editor|cadquery"
cadquery 2.5.2
cadquery-ocp 7.7.2
CQ-editor 0.5.0

```

Using:
CQ-Editor

Contributor guide

No contributing guide indexed for this repository

Research direction

Run the provided reproduction in CQ-Editor with the listed CadQuery 2.5.2 and cadquery-ocp 7.7.2 versions. Start in cadquery/occ_impl/shapes.py around offset2D at line 2682, comparing the circle and non-circle wires produced by section(). Done means the reported distance discrepancy is resolved and the z=3 case no longer produces a null TopoDS_Shape, with regression coverage for both bugs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.