I rewrote the macro a bit, added debugging and used RayIndex and BodyIndex.
from Debug:
==============================================================
SUSPICIOUS RAY / BODY
RayIndex = 199
BodyIndex = 0
Ray origin [mm]: X=763,513514 Y=583,000000 Z=-924,066924
Raw hits = 9
Clusters = 2
Parity crossings= 2
--- RAW HITS ---
raw[0] XYZ[mm]=(763,513514, 583,000000, -842,342342) dZ=- Type=4 [&H4] EDGE
raw[1] XYZ[mm]=(763,513514, 583,000000, -842,342342) dZ=0,000000 Type=4 [&H4] EDGE
raw[2] XYZ[mm]=(763,513514, 583,000000, -842,342342) dZ=0,000000 Type=4 [&H4] EDGE
raw[3] XYZ[mm]=(763,513514, 583,000000, -842,342342) dZ=0,000000 Type=8 [&H8] VERTEX
raw[4] XYZ[mm]=(763,513514, 583,000000, -842,342342) dZ=0,000000 Type=1 [&H1] FACE
raw[5] XYZ[mm]=(763,513514, 583,000000, -416,666667) dZ=425,675676 Type=1 [&H1] FACE
raw[6] XYZ[mm]=(763,513514, 583,000000, -416,666667) dZ=0,000000 Type=4 [&H4] EDGE
raw[7] XYZ[mm]=(763,513514, 583,000000, -416,666667) dZ=0,000000 Type=4 [&H4] EDGE
raw[8] XYZ[mm]=(763,513514, 583,000000, -416,666667) dZ=0,000000 Type=8 [&H8] VERTEX
--- CLUSTERS ---
cluster[0] Z=-842,342342 mm members=5 Type=13 [&HD] FACE|EDGE|VERTEX -> TOGGLE
cluster[1] Z=-416,666667 mm members=4 Type=13 [&HD] FACE|EDGE|VERTEX -> TOGGLE
==============================================================
That is, one physical entry point generated 5 records because the ray hit several topological objects simultaneously.
Z = -842.342342 mm
EDGE + EDGE + EDGE + VERTEX + FACE
The output is the same - FACE, EDGE, EDGE, VERTEX
This is very good; I didn’t see any direct kernel errors (although I’m not ruling them out).
Your “ROUNDING_DIGITS = 3” in a significant number of cases actually didn’t correct the numerical error, but simply accidentally merged multiple results from the same intersection.
** You can see that “dZ=0.000000”
even when outputting to the sixth decimal place. That is, the difference is less than approximately 0.0000005 mm, if it exists at all.
Therefore, a 1 mm tolerance is completely excessive here. I tested (in my code) DUPLICATE_Z_TOL_M As Double = 0.001 and now you can make 0.000001 m = 0.001 mm = 1 µm and retest, well, play around.
Also very interesting are these:
==============================================================
SUSPICIOUS RAY / BODY
RayIndex = 195
BodyIndex = 0
Ray origin [mm]: X=763,513514 Y=235,000000 Z=-924,066924
Raw hits = 7
Clusters = 4
Parity crossings= 4
--- RAW HITS ---
raw[0] XYZ[mm]=(763,513514, 235,000000, -842,342342) dZ=- Type=1 [&H1] FACE
raw[1] XYZ[mm]=(763,513514, 235,000000, -842,342342) dZ=0,000000 Type=4 [&H4] EDGE
raw[2] XYZ[mm]=(763,513514, 235,000000, -680,653741) dZ=161,688602 Type=4 [&H4] EDGE
raw[3] XYZ[mm]=(763,513514, 235,000000, -680,653741) dZ=0,000000 Type=1 [&H1] FACE
raw[4] XYZ[mm]=(763,513514, 235,000000, -549,578715) dZ=131,075025 Type=1 [&H1] FACE
raw[5] XYZ[mm]=(763,513514, 235,000000, -416,666667) dZ=132,912049 Type=1 [&H1] FACE
raw[6] XYZ[mm]=(763,513514, 235,000000, -416,666667) dZ=0,000000 Type=4 [&H4] EDGE
--- CLUSTERS ---
cluster[0] Z=-842,342342 mm members=2 Type=5 [&H5] FACE|EDGE -> TOGGLE
cluster[1] Z=-680,653741 mm members=2 Type=5 [&H5] FACE|EDGE -> TOGGLE
cluster[2] Z=-549,578715 mm members=1 Type=1 [&H1] FACE -> TOGGLE
cluster[3] Z=-416,666667 mm members=2 Type=5 [&H5] FACE|EDGE -> TOGGLE
==============================================================
OUTSIDE-INSIDE-OUTSIDE-INSIDE-OUTSIDE
At the very beginning, you said that you don’t need to display the points graphically in the application itself - they can be passed on.
This, of course, does not include full debug output, only execution information.
======================================
Point creation: 0,461 s
Rays: 200
Raw hits: 552
Cloud points: 891
======================================
Sketch 'Point Cloud' contains 891 points.
Drawing: 1,367 s
I will try many more bodies and many more points.