# Rhino.Geometry.Intersect.Intersection.MeshLine broken

Hi,

it appears to me that the latest Rhino7 update breaks the said function from the Rhino-Common API. I’ve got a couple of scripts making use of it and they don’t find intersections anymore since I updated to version 7.3.21039.11201, 8/02/2021. I used this function just before the update and it worked. The previous Rhino version was from 21/01/2021, if I remember correctly.

It would be great if you could check that. I’m using those scripts frequently in my daily workflow.

Kind regards, Gero.

Do you have a sample script that you can share that no longer works? This would help us identify the problem.

Hi,
I believe this code demonstrates the problem:

``````from Rhino.Geometry import Line, Mesh, Point3d
from Rhino.Geometry.Intersect.Intersection import MeshLine
import scriptcontext as sc

meshA = Mesh()

meshB = meshA.Duplicate()
meshB.Normals.ComputeNormals()

line = Line(Point3d(0.9,0.1,-1.0) , Point3d(0.9,0.1,1.0))

testA = True # 2D MeshLine intersection
if testA:
inter = MeshLine(meshA, line)
print inter

testB = False # 3D MeshLine intersection
if testB:
inter = MeshLine(meshB, line)
print inter
for pt in inter[0]:
``````

I apologize for the bad formatting. I’m new to this forum and have yet no idea how to paste source code properly.

Yes, it appears to me that the function fails if there are more than one intersections.

This code…

``````import rhinoscriptsyntax as rs
from Rhino.Geometry.Intersect.Intersection import MeshLine

vertices=[(0.0,0.0,0.5), (1.0,0.0,0.5), (1.0,1.0,0.5), (0.0,0.0,1.0)],
face_vertices=[(0,1,2), (1,2,3)])

inter = MeshLine(rs.coercemesh(mesh), rs.coerceline(line))
print "%d intersections with mesh" % len(inter[0])
for pt, faceId in zip(*inter):
print "... face id %d, inter-pt %s" % (faceId, pt)
``````

results in this output:

``````1 intersections with mesh
... face id 0, inter-pt 0,0,0
``````

where good old Rhino6 yields:

``````2 intersections with mesh
... face id 0, inter-pt 0.5,0.3,0.5
... face id 1, inter-pt 0.5,0.3,0.75
``````

Yes, this is a marshalling bug, RH-62807. The reason we had to switch the code from V6 is that it was behaving poorly in many situation. Many people weren’t all so convinced about the “good old” part

Based on that feedback, Rhino 7 shipped with a revised mesh-ray intersector based on V6. That didn’t work out so well. We are now switching to the new Mesh|Mesh intersector code also for Mesh|Ray. I’m sorry about the mistake in this transition. If you care for the next Service Release to be very stable for your needs, the best thing you can do is test it occasionally.

1 Like

Thank you Giulio,
I’m not really familiar with Rhino’s update scheme (I just acknowledge any update request Rhino comes up with). Can you estimate when we can expect a fix? I’m wondering if it’s worth the effort downgrading to an earlier version.

And a second question concerning the tests you suggest: Such tests would have to be (semi-)automatic to be practical for us. Can you suggest a good/simple unit test framework that works with Rhino-Python and might be suitable for a medium size library of all sorts of routines. I’m familiar with the CPython unittest module but that doesn’t seem to be available with Rhino-Python. And I’ve got no clue how to test GUI functions -i.e. mouse input.

We recently decided to move our ever-shifting SR date to “Patch Tuesday”, or the second Tuesday of the month.

My hope is that we can release a hotfix to 7 SR3 later today*. The switch to Patch Tuesday made us release some code a little too early.

We’ve created a small project that uses NUnit, and launches Rhino.Inside, inside NUnit. This means that we can test all cases regularly and automatically. I have been meaning to open-source this, but didn’t do it so far because you are the first to ask.

`*` – UPDATE 2021 Feb 16, 23:00 CET: It was decided that this fix was not requested often enough for it to deserve a hotfix for now. It will end up being released next week as a Service Release candidate, unless you install from a specially-forged link. Either me tomorrow or some other colleague will send you a link via PM.

Please, if you would be so kind @piac add me to this PM. I’m coming from here.

Thanks a lot Giulio, that would be faster than I could hope.

Thanks also for your suggestion using NUnit with Rhino.inside. I hope I can check that out, eventually. So far we’ve developed all our Rhino extensions/tools in Python. That’s a bit of an effort to get to the point to directly test those Python scripts. But I can envision a route through the jungle. I’ll get back to you should I get lost

Kind regards,
Gero.

Ups I was searching what did I do wrong in my code, until I realized I updated Rhino.
For me MeshLine was also working fine, since I have simple cases.

Any news when this will be updated?

Meanwhile I can use MeshPolyline, that does produce correct results:
Point3d pts0 = Rhino.Geometry.Intersect.Intersection.MeshPolyline(m0, pc, out int faceIds0);

@brian @stevebaer and I are discussing a hotfix for Rhino 7 SR3. This second version will have `MeshLine` working. If this works, users that will update to 7 SR3 will be able to use your scripts and definitions.

1 Like

Thank you

Is there any RhinoCommon method that allows to intersect infinite line with mesh? Ray intersection only takes closest point, and meshline is finite intersection.

Iirc i was looking for the same though actually you still need to know `Vector3d` for it. So if you know it no problem to multiply `Line` points it by insane magnitude with vector direction befor passing to `MeshLine` (?) or i miss something here?

@Petras_Vestartas
“infinite line” → the rhinocommon Intersection.LineBox Method is based on a infinite Lines.
use the boudingbox of the mesh to get 2 intersections-points.
if two points found: this will allow you to create a line, that intersects your mesh.
hope that helps. kind regards. -tom

1 Like

I’ve added it to the wish list. Internally, code can decide if the intersection is infinite or bounded. The infinite case has actually less code to run. RH-62956

Thanks this is a neat trick;)

Thank you Giulio and I will try for new fix in Rhino update.