build123d icon indicating copy to clipboard operation
build123d copied to clipboard

`location_at` returns forward direction even when edge is reversed

Open jdegenstein opened this issue 1 year ago • 2 comments

credit to @snoyer for recommending this

Consider changing location_at so that it returns the actual positive direction even when the edge/wire is reversed. Have not looked at faces to see if they suffer similar a problem but worth investigating that further.

jdegenstein avatar Jan 03 '25 02:01 jdegenstein

Supporting visual elements from the initial investigation on Discord with @jdegenstein

  1. Visualizing edge direction using locations: image

  2. However, looking at .is_forward: image

cone = Cone(0.3, 0, 0.8)
part = Box(10, 10, 2) - Cylinder(3, 2)
show_object(part.wrapped)
for e in part.edges():
    show_object(
        (e ^ 0.5) * cone,
        options=dict(color=(1.0, 0.0, 0.0) if e.is_forward else (0.0, 0.0, 1.0)),
    )
  1. now with locations accounting for .is_forward: image

snoyer avatar Jan 03 '25 03:01 snoyer

My current use case for this is optimizing tool paths, which was surprisingly slow due to how Edge.reversed() works (5s for 900 flips, vs. 290µs with Edge.wrapped.Reverse())

We should look into whether we can replace the implementation of Edge.reversed() once features like .position_at and start_point/end_point respect the is_forward flag.

CarpeNecopinum avatar Jan 06 '25 13:01 CarpeNecopinum