Unintended behaviour in Grasshopper of Curve.ClosestPoints

In the Curve.ClosestPoints() method of RhinoCommon, when I enter Surface as a list of GeometryBases and try to find the surfaces corresponding to the input curves, I can successfully I was able to get a combination of curves and surfaces, but when I build the component using the GrasshopperSDK, I cannot find the corresponding surfaces using the same interface methods below.

We would be grateful if someone could give us some advice. Thank you in advance.

ClosestPoints Method

The files for the above samples are attached. In addition, the code for the Grasshopper component is as follows.

public class Curve_ClosestPoints_Test_Component : GH_Component
{

    public Curve_ClosestPoints_Test_Component()
      : base("Curve_ClosestPoints_Test", "Curve_ClosestPoints_Test",
        "Curve_ClosestPoints_Test",
        "Tests", "Tests")
    {
    }

    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
    {
        pManager.AddCurveParameter("Curve", "Curve", "Curve", GH_ParamAccess.item);
        pManager.AddGeometryParameter("Geoms", "Geoms", "Geoms", GH_ParamAccess.list);
    }

    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddGeometryParameter("Closest", "Closest", "Closest", GH_ParamAccess.item);
    }

    protected override void SolveInstance(IGH_DataAccess DA)
    {
        Curve crv = null;
        DA.GetData(0, ref crv);

        List<GeometryBase> geoms = new List<GeometryBase>();
        DA.GetDataList(1, geoms);

        bool found = crv.ClosestPoints(geoms, out Point3d pt_crv, out Point3d pt_geo, out int idx);

        if (found) { DA.SetData(0, geoms[idx]); }
        else { DA.SetData(0, null); }
    }

    protected override System.Drawing.Bitmap Icon => null;

    public override Guid ComponentGuid => new Guid("5fd8b8ce-a9d0-4639-a1f9-29c08ecaa7a0");
}

sample.3dm (34.9 KB)
sample.gh (11.7 KB)

See attached.

Curve_GeomBase_Proximity_V1.gh (122.0 KB)

Thank you for your response. It seems that checking the relationship between Curves and GeometryBases for all combinations of each, as in the sample you sent, would certainly yield results.

I was thinking that if the Curve.ClosestPoints() function gives a one-to-many distance relationship, it would make the code a bit more simple. If it is not stable, it seems appropriate to check the results one by one, as in the sample you sent me.

NO, it could yield fuzzy results in the sense that you don’t know what is prox to what (first, second path indices in the out Tree(s)) … meaning the obvious.

BTW: For that kind of elementary stuff … talking about code simplicity has no meaning at all.

Added a rnd rot option (for fun).

Curve_GeomBase_Proximity_V1A.gh (122.5 KB)

Thank you for the additional sample files. As you point out, it seems more reliable to check the relationship between each geometry individually.

Thank you for your advice.