Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
calc_distance.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/kdtree/calc_distance.cc
11 /// @brief
12 /// @author James Thompson
13 
14 #include <numeric/types.hh>
15 #include <utility/vector1.hh>
16 
17 #include <cmath>
18 
19 namespace numeric {
20 namespace kdtree {
21 
25 ) {
26  assert( vec1.size() == vec2.size() );
27  using numeric::Real;
28  using numeric::Size;
29  using utility::vector1;
30 
31  static Size n_comp( 0 );
32 
33  numeric::Real dist( 0.0 );
35  it1 = vec1.begin(), it2 = vec2.begin(),
36  end1 = vec1.end(), end2 = vec2.end();
37  it1 != end1 && it2 != end2; ++it1, ++it2
38  ) {
39  //std::cout << "comparing " << *it1 << " and " << *it2 << std::endl;
40  dist += ( *it1 - *it2 ) * ( *it1 - *it2 );
41  }
42  //std::cout << "dist = " << dist << std::endl;
43 
44  n_comp++;
45  //std::cout << "n_comp = " << n_comp << std::endl;
46 
47  return dist;
48 }
49 
53 ) {
54  return std::sqrt( sq_vec_distance( vec1, vec2 ) );
55 }
56 
57 } // kdtree
58 } // numeric
numeric::Real vec_distance(utility::vector1< numeric::Real > const &vec1, utility::vector1< numeric::Real > const &vec2)
Returns the Euclidean distance between the two points vec1 and vec2.
platform::Size Size
Definition: types.hh:42
numeric::Real sq_vec_distance(utility::vector1< numeric::Real > const &vec1, utility::vector1< numeric::Real > const &vec2)
distance metrics for real-valued points
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
double Real
Definition: types.hh:39
vector1: std::vector with 1-based indexing
def dist
Definition: coordlib.py:16