Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / blocFissure / gmu / distance2.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2022  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 """calcul du carré de la distance entre deux points"""
21
22 import logging
23
24 # -----------------------------------------------------------------------------
25 # ---
26
27 def distance2(xyz1, xyz2):
28   """
29   carré de la distance entre deux points donnés par des triplets [x,y,z]
30   """
31   #logging.info("start")
32
33   dcarre = 0
34   for ijk in range(3):
35     dcarre += (xyz1[ijk]-xyz2[ijk])*(xyz1[ijk]-xyz2[ijk])
36   logging.debug('dcarre=%s', dcarre)
37
38   return dcarre
39
40 ## -----------------------------------------------------------------------------
41 ## --- test unitaire
42
43 #import unittest
44 #class Test_distance2(unittest.TestCase):
45   #"""test de la fonction"""
46
47   #def setUp(self):
48     #self.a=[0, 0, 0]
49     #self.b=[3, 4, 5]
50     #self.c=[-5,-4,-3]
51
52   #def test_calcul(self):
53     #self.assertEqual(distance2(self.a, self.b), distance2(self.b, self.a))
54     #self.assertEqual(distance2(self.a, self.b), distance2(self.a, self.c))
55     #self.assertEqual(distance2(self.b, self.b), 0)
56     #self.assertEqual(distance2(self.a, self.b), 50)