fix(hit_test): correct hatch selection — NaN-aware ray-cast + block-insert resolve

Two related click bugs:

1. `point_in_polygon` treated NaN points (the path separators used by
   multi-path hatches with islands / holes) as regular vertices,
   producing spurious closing edges between sub-paths. The cursor
   inside a real hatch failed the test → the click iterator moved on
   to the NEXT hatch in HashMap order and silently returned the wrong
   one. Rewrite the ray-cast to reset the previous-vertex / path-start
   state at every NaN, so each sub-path closes against its own first
   vertex and contributes its parity flip correctly.

2. Clicking on a hatch *inside* a block was either missing entirely
   (after the visible_hatches_for_click filter) or returning the
   block-defn source hatch handle (misleading — that handle isn't the
   thing the user sees). AutoCAD selects the parent Insert when a
   sub-entity of a block is clicked. Add `Scene::insert_hatches_for_click`
   which walks the same explode path `synced_hatch_models` uses and
   tags every exploded sub-hatch with its parent Insert handle, plus
   `hit_test::click_hit_insert_hatch` which iterates that list. The
   click resolver now tries wire → MSPACE hatch → insert-internal hatch
   in order, so clicking on a block-internal hatch selects the Insert.

Box / lasso select paths are unchanged — wire hit-test already picks
up Inserts, and dragging a box over block-internal hatches is rare
enough not to need its own resolution path yet.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.7 committed 2026-05-16 13:02:57 +03:00
1 parent 0f252e8b53
commit c815be9c6f
3 files changed
+174 -20

No files matched your search

+14 -4
View File
@@ -1998,7 +1998,7 @@ impl H7CAD {
a,
p,
crossing,
&self.tabs[i].scene.hatches,
&self.tabs[i].scene.visible_hatches_for_click(),
vp_mat,
bounds,
));
@@ -2031,7 +2031,7 @@ impl H7CAD {
handles.extend(scene::hit_test::poly_hit_hatch(
&poly_pts,
crossing,
&self.tabs[i].scene.hatches,
&self.tabs[i].scene.visible_hatches_for_click(),
vp_mat,
bounds,
));
@@ -2058,7 +2058,17 @@ impl H7CAD {
.or_else(|| {
scene::hit_test::click_hit_hatch(
p,
&self.tabs[i].scene.hatches,
&self.tabs[i].scene.visible_hatches_for_click(),
vp_mat,
bounds,
)
})
.or_else(|| {
// Block-internal hatch: resolve to the
// parent Insert (AutoCAD behaviour).
scene::hit_test::click_hit_insert_hatch(
p,
&self.tabs[i].scene.insert_hatches_for_click(),
vp_mat,
bounds,
)
@@ -2096,7 +2106,7 @@ impl H7CAD {
a,
p,
crossing,
&self.tabs[i].scene.hatches,
&self.tabs[i].scene.visible_hatches_for_click(),
vp_mat,
bounds,
));