Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Sketch / 2D Topology

- **Arc segments:** Each arc is a single sketch edge (not two chained edges). New arcs split existing straight and arc edges at interior crossings; arcs are subdivided when crossed. Face walking uses arc tangents at endpoints. The Arc Segment tool shows a line rubber-band after the first click and an arc preview after the second; optional **Add midpoint nodes** in the Arc tool Options adds a geometric-mid snap node (same setting as line edges). Documented in [usage-sketch.md](docs/usage-sketch.md#arc-segment-creation-tool). **Known open bug:** slot + circle intersection splitting — see [bugs.md](docs/bugs.md).
- For the **Add line edge** and **Add multi-line edge** tools, a new setting **"Add midpoints to new linear edges"** (Settings > Sketch; also exposed in the tool Options pane) controls whether automatic midpoint nodes are created on new straight edges. Default is **off** (no midpoints), so new edges do not get mid snap targets unless the option is enabled. Existing edges with mids are unaffected; JSON load/save supports edges without mids for compatibility.
- **Add line edge** Options: **Place from center** — first click sets the edge midpoint; second click or Tab length uses the **full** edge length (symmetric placement). Documented in the user guide with **?** help links in the Options panel.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Sketch: slot + circle edge splitting at intersections

---
github_issue: 165
status: active
---

**Opened on GitHub:** https://github.com/trailcode/EzyCad/issues/165

---

## Title (GitHub)

Sketch: slot + circle edges split or highlight incorrectly at intersections

## Body (GitHub)

### Summary

When a slot (two horizontal lines + end-cap arcs) is combined with a circle that crosses the horizontals, edge splitting and display can be wrong: one horizontal may split while the other does not, circle arcs may fail to split at line crossings, and some segments show incorrect highlight colors.

### Problem

- Adding end caps can spuriously split slot horizontals near the slot center (before any circle is added).
- Adding a circle that should cross both horizontals at two points each may not produce symmetric topology.
- Face update / edge styling can show inconsistent colors (e.g. white vs green segments).

### Likely causes (investigated, not yet fixed)

- `segment_arc_intersections_2d` (`utl_geom.cpp`): `GeomAPI_ExtremaCurveCurve` may return segment points paired with unrelated arc-foot points on the full circle outside the trimmed semicircle.
- `add_arc_circle_edges` / circle finalize argument order vs `GC_MakeArcOfCircle` node index conventions.
- Face walker parallel-edge loops (partial guard in `sketch_topo.cpp`).

### Acceptance criteria

- [ ] Slot horizontals remain unsplit after end caps are added (only endpoint nodes at corners).
- [ ] Circle crossing both horizontals splits each into three segments at the two intersection points.
- [ ] Circle arcs split at horizontal crossings; edge highlight colors consistent.
- [ ] `update_faces()` completes without infinite loop on slot + circle geometry.
- [ ] Regression tests: `SlotHorizontalLinesUnsplitBeforeCircleArcs`, `ArcSplit_CircleCrossesSlotLines`.

### Files / areas

- `src/utl_geom.cpp` — `segment_arc_intersections_2d`
- `src/sketch_edges.cpp` — `add_arc_circle_edges`
- `src/sketch_tools.cpp` — `finalize_circle_`, slot finalize
- `src/sketch_topo.cpp` — face walker
- `docs/bugs.md` — user-visible note
- `tests/sketch_tests.cpp`

### Related

- Documented in `docs/bugs.md`
- Arc topology PR (single edge per arc, intersection splitting) — separate work; does not resolve this bug

### Test plan

- [ ] Reproduce: slot tool + circle tool on same sketch, circle diameter larger than slot height.
- [ ] Verify edge counts per horizontal line before/after circle.
- [ ] Run targeted `EzyCad_tests` filters above.
47 changes: 47 additions & 0 deletions agents/drafts/prs/active/gh-166-sketch-arc-topology-improve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# PR - Sketch arc topology improvements

---
github_pr: 166
status: active
paired_draft: ../issues/active/gh-165-sketch-slot-circle-intersection-splitting.md
---

**Opened on GitHub:** https://github.com/trailcode/EzyCad/pull/166

Sketch arc topology: single edge per arc, intersection splitting, tangent face walker

## Summary

- Refactor arc sketch edges to **one graph edge per arc** (replacing two-edge internal representation).
- Split existing straight and arc edges when new arcs/lines cross them; subdivide new arcs at interior intersections.
- Face walking uses **arc tangents** at endpoints (fixes semicircle / slot cap loops).
- Arc Segment tool: rubber-band line after first click; **Add midpoint nodes** option adds geometric-mid snap node when enabled.
- Document arc behavior in `usage-sketch.md`; record open slot+circle bug in `bugs.md`.

## Files Changed

- `src/sketch_edge.cpp`, `src/sketch_edge.h`, `src/sketch_edges.cpp` — single arc edge, intersection split on add
- `src/sketch_topo.cpp`, `src/sketch_topo.h` — tangent-based face walker, arc/line split helpers, walk guard
- `src/utl_geom.cpp`, `src/utl_geom.h` — arc-line/arc-arc intersection helpers
- `src/sketch_tools.cpp`, `src/gui_mode.cpp` — arc preview, midpoint option in arc mode
- `src/sketch_delta.cpp`, `src/sketch_json.cpp`, `src/sketch_operations.cpp` — arc model migration
- `tests/sketch_tests.cpp` — arc split, semicircle walker, midpoint option tests
- `docs/usage-sketch.md`, `docs/bugs.md`, `CHANGELOG.md`

## Related

- Issue: https://github.com/trailcode/EzyCad/issues/165 (slot + circle bug — **not** fixed by this PR)
- Does **not** fix slot + circle intersection splitting; tracked separately.

## Test Plan

- [ ] Build `EzyCad_tests` (Debug).
- [ ] Run `Sketch_test.*Arc*`, `Sketch_test.*Semicircle*`, `Sketch_test.UpdateFaces_FaceWithArcs`.
- [ ] Manual: arc tool three-click flow, preview rubber band, optional midpoint node.
- [ ] Manual: line crossing arc splits both; slot + circle — confirm known bug still present (see issue).
- [ ] `sphinx-build -b html -W docs docs/_build`

## Notes

- `Walk_key` step cap in face walker prevents infinite loop on some parallel-edge cases; turn-rule improvement may follow.
- Circle finalize still uses legacy `add_arc_circle_(points[0], points[2], points[1])` call pattern; may need cleanup with slot+circle fix.
7 changes: 6 additions & 1 deletion docs/bugs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@
* Arc function needs to accept tab for radius.
* Dist tab dialog should state if it is a radius or diameter for arc.*
* Dist tab dialog should state if it is a 1/2 dist or full, for edge tool.
* **Wasm / OCCT 8.x GLES shading regression:** With OCCT **8.0.0.p1** (`V8_0_0_p1`) and `TKOpenGles`, new solids and extrude previews often render wireframe-only or with partial face shading in the browser. Native desktop (OCCT 8 + `TKOpenGl`) is unaffected. Rebuilding against **7.9.3** (`scripts/build-occt-793-wasm.ps1`) restores correct shading. Workarounds in EzyCad (`SetMaterial` + `Redisplay`, `refresh_shape_shading_`, bisect toggles in `occt_view_wasm_bisect.h`) do not fix the root cause on OCCT 8. Use 7.9.3 for wasm builds and demo publishing until upstream fixes GLES presentation.
* **Sketch: slot + circle — edges split / colored incorrectly at intersections.** Draw a slot (two horizontals + end-cap arcs), then add a circle that crosses both horizontals. Observed: one horizontal may split while the other does not; circle arcs may not split at line crossings; some edge segments show the wrong highlight color (e.g. white vs green). Caps can spuriously split the horizontals near the slot center before the circle is added. Likely causes investigated (fix attempted and reverted; still open):
- `segment_arc_intersections_2d` (`utl_geom.cpp`) uses `GeomAPI_ExtremaCurveCurve` and returns `p_on_seg` while validating arc parameter from `p_on_arc`. Extrema can pair a segment foot with a nearby point on the *full* circle outside the trimmed semicircle, yielding false interior hits (e.g. on the slot centerline when adding the right cap).
- `add_arc_circle_edges` (`sketch_edges.cpp`) may use inconsistent node indices for intersection/knot logic vs `GC_MakeArcOfCircle` (vector is `[start, pick, end]` from `Sketch::add_arc_circle_`; `pt_end` / knot end node must be `node_idxs[2]`, not `[1]`). A long-standing knot bug masked wrong argument order in circle finalize (`sketch_tools.cpp`: `add_arc_circle_(points[0], points[2], points[1])` passes bottom/top as `pt_b` where the API expects arc *end*, with pick on the opposite side).
- `update_faces()` face walker can loop on parallel shared edges (e.g. slot horizontals); a `Walk_key` step cap was added in `sketch_topo.cpp` as a guard — may hide topology errors rather than fix turn logic.
- Relevant tests (if re-added): `SlotHorizontalLinesUnsplitBeforeCircleArcs`, `ArcSplit_CircleCrossesSlotLines` in `tests/sketch_tests.cpp`. Use `slot_c` perpendicular to the slot centerline (e.g. `(15, 5)` for `slot_b = (15, 0)`), not `(0, 5)`, to match the slot tool.
* Wasm / OCCT 8.x GLES shading regression: With OCCT **8.0.0.p1** (`V8_0_0_p1`) and `TKOpenGles`, new solids and extrude previews often render wireframe-only or with partial face shading in the browser. Native desktop (OCCT 8 + `TKOpenGl`) is unaffected. Rebuilding against **7.9.3** (`scripts/build-occt-793-wasm.ps1`) restores correct shading. Workarounds in EzyCad (`SetMaterial` + `Redisplay`, `refresh_shape_shading_`, bisect toggles in `occt_view_wasm_bisect.h`) do not fix the root cause on OCCT 8. Use 7.9.3 for wasm builds and demo publishing until upstream fixes GLES presentation.
Loading
Loading