title: Nearest point to point, nearest point to line
body: <p>Imagine a set of <code>m</code> points in 2D plane, called "candidates". And then one of two scenarios:</p>
  
  <ul>
  <li><p>there is also a set of <code>n</code> points ("objects") - see Fig. 1</p></li>
  <li><p>there is also a set of <code>n</code> lines collinear with X or Y axis ("objects") - see Fig. 2</p></li>
  </ul>
  
  <p>I would like to know which candidate-object pair has the shortest Cartesian distance of all the pairs.</p>
  
  <p>Please, does anyone know if this problem has a name in computational geometry? Is there algorithm which is faster than O(m*n)? And if objects remain the same, and only candidates change - would it it possible to go faster than O(m*n) by some clever pre-computation?</p>
  
  <p>Fig. 1</p>
  
  <pre><code>              c      o
         c
                            o         c      o
             o    c
                               c
                c o              
                         c             o
                                            c
                 o                 c
            c
  </code></pre>
  
  <p>Fig. 2</p>
  
  <pre><code>             |                      c           |  
  -------------+----------------------------------+------  
               |                                  |  
               |              c                   |    c  
               c                                  |  
               |                                  |  
  -------------+----------------------------------+------  
               |          c            c          |  
  -------------+----------------------------------+------  
               |                            c     |  
  </code></pre>