updade from Atlas repo
This commit is contained in:
@@ -264,7 +264,7 @@ class Vector:
|
||||
def __repr__(self):
|
||||
components = reprlib.repr(self._components)
|
||||
components = components[components.find('['):-1]
|
||||
return 'Vector({})'.format(components)
|
||||
return f'Vector({components})'
|
||||
|
||||
def __str__(self):
|
||||
return str(tuple(self))
|
||||
@@ -283,7 +283,7 @@ class Vector:
|
||||
|
||||
# tag::VECTOR_V6_UNARY[]
|
||||
def __abs__(self):
|
||||
return math.sqrt(sum(x * x for x in self))
|
||||
return math.hypot(*self)
|
||||
|
||||
def __neg__(self):
|
||||
return Vector(-x for x in self) # <1>
|
||||
@@ -313,11 +313,11 @@ class Vector:
|
||||
pos = cls.shortcut_names.find(name)
|
||||
if 0 <= pos < len(self._components):
|
||||
return self._components[pos]
|
||||
msg = '{.__name__!r} object has no attribute {!r}'
|
||||
raise AttributeError(msg.format(cls, name))
|
||||
msg = f'{cls.__name__!r} object has no attribute {name!r}'
|
||||
raise AttributeError(msg)
|
||||
|
||||
def angle(self, n):
|
||||
r = math.sqrt(sum(x * x for x in self[n:]))
|
||||
r = math.hypot(*self[n:])
|
||||
a = math.atan2(r, self[n-1])
|
||||
if (n == len(self) - 1) and (self[-1] < 0):
|
||||
return math.pi * 2 - a
|
||||
|
||||
Reference in New Issue
Block a user