.. role:: ts-api-decorator

###############
SnapPointPicker
###############

.. js:module:: cee
   :noindex:

.. container:: ts-api-section

   .. js:class:: SnapPointPicker

      Helper class for implementing Snap-to features in an application

      To snap to a point on while checking if the point is visible (not obscured by the model(s)):


      .. code-block:: javascript

          // Get the ray at mouse position
         const ray = myViewer.rayFromCssCoordinate(myView, event.offsetX, event.offsetY);

         // Find the radius to use based on model extent
         const modelBoundingBox = myModel.getBoundingBox();
         const radius = modelBoundingBox.getExtent().getLength()/100;
         let closestPoint = null;

         // Snap to point, check if visible
         const snapPointPicker = new cee.SnapPointPicker(myView, ray, radius);
         const pointIndex = snapPointPicker.findClosestPoint(myHotSpots);

         if (pointIndex >= 0) {
             closestPoint = new cee.Vec3(myHotSpots[3*pointIndex], 
                myHotSpots[3*pointIndex + 1], myHotSpots[3*pointIndex + 2]);
         }



      To just find the closest point to the view, not checking the model if the point is visible:

      .. code-block:: javascript

         // Snap to closest point, not checking the model
         const pointIndex = cee.RaySphereIntersector.findClosestIntersectedSphereToRay(ray, radius, g.hotSpots);

         if (pointIndex >= 0) {
             closestPoint = new cee.Vec3(g.hotSpots[3*pointIndex], 
                g.hotSpots[3*pointIndex + 1], g.hotSpots[3*pointIndex + 2]);
         }





.. container:: api-index-section

   .. rubric:: Constructors

   .. rst-class:: api-index-list-item api-kind-constructor api-parent-kind-class

   * :js:meth:`~cee.SnapPointPicker.constructor`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~cee.SnapPointPicker.findClosestPoint`





------------

Constructors
============

.. container:: ts-api-section

   .. js:function:: SnapPointPicker.constructor( view, ray, radius)

      :param view: None
      :type view: View
      :param ray: None
      :type ray: Ray
      :param radius: None
      :type radius: number


      :rtype: SnapPointPicker



Methods
=======

.. rst-class:: ts-api-section

findClosestPoint
----------------

.. js:method:: SnapPointPicker.findClosestPoint( pointsArr)

   :param pointsArr: None
   :type pointsArr: ArrayLike <number>


   Find the point closest to the ray that is visible (not obscured by the model). 

   The radius determines the maximum distance from the point in order to snap to it.

   The pointsArr array contains a number of points (sphere centers) in a 1d array:
   <s1.x, s1.y, s1.z, s2.x, s2.y, s2.z> ...

   Returns the index of the closest visible point. -1 if there was not hit.


   :rtype: number

