updated from Atlas

This commit is contained in:
Luciano Ramalho
2021-08-07 00:44:01 -03:00
parent cbd13885fc
commit 01e717b60a
96 changed files with 580 additions and 1021 deletions

View File

@@ -1,5 +1,5 @@
"""
A 2-dimensional vector class
A two-dimensional vector class
>>> v1 = Vector2d(3, 4)
>>> print(v1.x, v1.y)
@@ -72,7 +72,7 @@ Tests of `x` and `y` read-only properties:
>>> v1.x = 123
Traceback (most recent call last):
...
AttributeError: can't set attribute
AttributeError: can't set attribute 'x'
Tests of hashing:
@@ -81,7 +81,7 @@ Tests of hashing:
>>> v2 = Vector2d(3.1, 4.2)
>>> hash(v1), hash(v2)
(7, 384307168202284039)
>>> len(set([v1, v2]))
>>> len({v1, v2})
2
"""
@@ -90,6 +90,8 @@ from array import array
import math
class Vector2d:
__match_args__ = ('x', 'y')
typecode = 'd'
def __init__(self, x, y):

View File

@@ -305,14 +305,16 @@ class Vector:
index = operator.index(key)
return self._components[index]
shortcut_names = 'xyzt'
__match_args__ = ('x', 'y', 'z', 't')
def __getattr__(self, name):
cls = type(self)
if len(name) == 1:
pos = cls.shortcut_names.find(name)
if 0 <= pos < len(self._components):
return self._components[pos]
try:
pos = cls.__match_args__.index(name)
except ValueError:
pos = -1
if 0 <= pos < len(self._components):
return self._components[pos]
msg = f'{cls.__name__!r} object has no attribute {name!r}'
raise AttributeError(msg)

View File

@@ -355,14 +355,16 @@ class Vector:
index = operator.index(key)
return self._components[index]
shortcut_names = 'xyzt'
__match_args__ = ('x', 'y', 'z', 't')
def __getattr__(self, name):
cls = type(self)
if len(name) == 1:
pos = cls.shortcut_names.find(name)
if 0 <= pos < len(self._components):
return self._components[pos]
try:
pos = cls.__match_args__.index(name)
except ValueError:
pos = -1
if 0 <= pos < len(self._components):
return self._components[pos]
msg = f'{cls.__name__!r} object has no attribute {name!r}'
raise AttributeError(msg)

View File

@@ -361,14 +361,16 @@ class Vector:
index = operator.index(key)
return self._components[index]
shortcut_names = 'xyzt'
__match_args__ = ('x', 'y', 'z', 't')
def __getattr__(self, name):
cls = type(self)
if len(name) == 1:
pos = cls.shortcut_names.find(name)
if 0 <= pos < len(self._components):
return self._components[pos]
try:
pos = cls.__match_args__.index(name)
except ValueError:
pos = -1
if 0 <= pos < len(self._components):
return self._components[pos]
msg = f'{cls.__name__!r} object has no attribute {name!r}'
raise AttributeError(msg)