/usr/share/pyshared/pymecavideo/vecteur.py is in python-mecavideo 6.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #-*- coding: utf-8 -*-
"""
vecteur.py is a module of pymecavideo.
pymecavideo is a program to track moving points in a video frameset
Copyright (C) 2007 Jean-Baptiste Butet <ashashiwa@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
"""
vecteur.py implements some operations for 2D vectors, using tuples
"""
import math
class vecteur:
def __init__(self,x=0,y=0):
self.value=(float(x),float(y))
def copy(self):
return vecteur(self.x(),self.y())
def x(self):
return self.value[0]
def y(self):
return self.value[1]
def __getitem__(self,i):
#print "Utilisation de vecteur.__getitem__ déconseillée"
return self.value[i]
def setValue(self,x=None,y=None):
if x == None: x=self.value[0]
if y == None: y=self.value[1]
self.value=(float(x),float(y))
def rounded(self):
self.value=(math.floor(self.value[0]+0.5),math.floor(self.value[1]+0.5))
def __add__(self,v):
x=self.x()+v.x()
y=self.y()+v.y()
return vecteur(x,y)
def __sub__(self,v):
x=self.x()-v.x()
y=self.y()-v.y()
return vecteur(x,y)
def __mul__(self,v):
if type(v)==type(self):
# produit scalaire de deux vecteurs
return self.x()*v.x()+self.y()+v.y()
else:
# produit du vecteur par un nombre
x=float(v)*self.x()
y=float(v)*self.y()
return vecteur(x,y)
def __str__(self):
return "(%5f, %5f)" %(self.x(), self.y())
def __repr__(self):
return "vecteur %s" %self
def norme(self):
return math.sqrt(self.x()*self.x()+self.y()*self.y())
def anglePolaire(self):
return math.atan2(self.y(),self.x())
def minXY(self,v):
if v==None:
return self
else:
if self.x() > v.x():
x=v.x()
else:
x=self.x()
if self.y() > v.y():
y=v.y()
else:
y=self.y()
return vecteur(x,y)
def maxXY(self,v):
if v==None:
return self
else:
if self.x() < v.x():
x=v.x()
else:
x=self.x()
if self.y() < v.y():
y=v.y()
else:
y=self.y()
return vecteur(x,y)
|