ClosestPoint and ON_COMPONENT_INDEX C++


I have another question, related to my last one, but different, so I am starting a new topic in case someone else needs help with this too…

I am using RhinoBrepClosestPoint to find the closest point to the brep and ON_Mesh::GetClosestPoint for a mesh …but…i really need to know if that new point is on the edge( border) or not. One option is is to generate a border (DupBorder equivalent) for the brep or the mesh and then check if the new point is on that curve. But that seems a bit “expensive”, and i thought i can use the ON_COMPONENT_INDEX for breps and ON_MESH_POINT Q. I have two problems with it…

  1. when I use RhinoBrepClosestPoint, no matter where the point is, ci.m_type is always 3 (simple test example posted bellow…and I expected it to be 2 on the edge…

  2. for the mesh I test Q.m_ci.m_type (Q returned from the GetClosestPoint function) and very often Q.m_ci.m_type = 13 works, but apparently not only on the border…when there is a crease, on that edge i also get 13, and i want only points on the border…

So long story short, is there an easier way to detect if the point is on the border of the brep or mesh, without extracting the curve of the border?

//test example in which every point on the brep is ci.m_type = 3

CRhinoCommand::result CCommandTestPointOnBrep::RunCommand( const CRhinoCommandContext& context )
CRhinoDoc* mydoc = ::RhinoApp().ActiveDoc();

ON_Brep* selectedbrep;
ON_3dPoint testpt;

CRhinoGetObject go;
go.SetCommandPrompt( L"Select  the brep to test a point" );	
go.SetGeometryFilter(CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object );
CRhinoGet::result res = go.GetObjects( 1, 1 );
  if( res == CRhinoGet::object )
		  const CRhinoObjRef& obj_ref = go.Object(0);
		  const ON_Brep* brep = obj_ref.Brep();	

		  selectedbrep = brep->BrepForm();

		CRhinoGetObject gp;
		gp.SetCommandPrompt(  L"Select  the point to test" );	
		gp.SetGeometryFilter( CRhinoGetObject::point_object );
		res = gp.GetObjects( 1, 1 );					

		  const CRhinoObjRef& ptobj_ref = gp.Object( 0 );
		  const ON_Point* point = ptobj_ref.Point();
		 testpt = ON_3dPoint( point->point.x, point->point.y, point->point.z);

//----test the closest point---------------------------------------------------------------

double s,t; //domain of the new points
ON_COMPONENT_INDEX ci; //this should tell us if the point is on the edge.
double max_dist = 0;
ON_3dPoint newpt;				

 RhinoBrepClosestPoint(*selectedbrep, testpt, &ci, &s, &t, &newpt, max_dist) ;

 mydoc->AddPointObject( newpt );

 RhinoApp().Print(L"New point type: %d \n", ci.m_type );	  
return CRhinoCommand::success;



I agree that duplicating edge curves can be expensive. But there is no need to duplicate them. You can just use the Brep and Mesh data structure as they are to perform your edge analysis tests.