2017-12-03 13:05:05 +01:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-12-10 15:12:51 +01:00
|
|
|
import operator
|
|
|
|
|
|
|
|
def is_numeric(a):
|
|
|
|
for i in a:
|
|
|
|
if not(isinstance(i,int)) and not(isinstance(i,float)):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def add(punkt1, punkt2):
|
|
|
|
if len(punkt1.wspolrzedne) == len(punkt2.wspolrzedne):
|
|
|
|
return Point(list(map(operator.add,punkt1.wspolrzedne,punkt2.wspolrzedne)))
|
|
|
|
else:
|
|
|
|
raise Exception("Dimension error")
|
|
|
|
|
|
|
|
class Point:
|
|
|
|
wspolrzedne = []
|
|
|
|
def __init__(self,wspolrzedne):
|
|
|
|
if is_numeric(wspolrzedne):
|
|
|
|
self.wspolrzedne = wspolrzedne
|
|
|
|
def to_string(self):
|
|
|
|
return "Współrzędne punktu to: " + str(self.wspolrzedne)
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.wspolrzedne)
|
|
|
|
def __str__(self):
|
|
|
|
return self.to_string()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
punkt = Point([0,1,2])
|
|
|
|
punkt2 = Point([10,15,20])
|
|
|
|
punkt3 = add(punkt,punkt2)
|
|
|
|
#punkt4 = add(punkt,Point([10,20]))
|
|
|
|
|
|
|
|
print(punkt.wspolrzedne, punkt2.wspolrzedne, punkt3.wspolrzedne)#, punkt4.wspolrzedne)
|
|
|
|
print(punkt.to_string())
|
|
|
|
print(punkt3)
|