Salome HOME
Merge branch 'master' into gni/evolution
[modules/smesh.git] / src / Tools / blocFissure / gmu / distance2.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import logging
22
23 # -----------------------------------------------------------------------------
24 # --- calcul de distance carree entre deux points, jeux de coordonnees x,y,z
25
26 def distance2(xyz1, xyz2):
27   """
28   carrĂ© de la distance entre deux points donnĂ©s par des triplets [x,y,z]
29   """
30   #logging.info("start")
31   
32   d2 = 0
33   for i in range(3):
34     d2 += (xyz1[i]-xyz2[i])*(xyz1[i]-xyz2[i])
35   logging.debug('d2=%s', d2)
36   return d2
37
38 # -----------------------------------------------------------------------------
39 # --- test unitaire
40
41 import unittest
42 class Test_distance2(unittest.TestCase):
43
44   def setUp(self):
45     self.a=[0, 0, 0]
46     self.b=[3, 4, 5]
47     self.c=[-5,-4,-3]
48     
49   def test_calcul(self):
50     self.assertEqual(distance2(self.a, self.b), distance2(self.b, self.a))
51     self.assertEqual(distance2(self.a, self.b), distance2(self.a, self.c))
52     self.assertEqual(distance2(self.b, self.b), 0)
53     self.assertEqual(distance2(self.a, self.b), 50)
54