In [ ]:
point = Point(2, 3, 4)
point.x # 2
point.y # 3
point.z # 4

uv = Point(.2, .3)
uv.u # .2
uv.v # .3
point = uv
point.x # .2
point.y # .3

point * 1.0
point *= 1.0
point + 1.0
point += 1.0
point + uv # Point(2.2, 3.3, 4)
point += uv

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point = Point()

In [ ]:
point.x, point.y, point.z

In [ ]:
point = Point.One()

In [ ]:
point.x, point.y, point.z

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattr__(self, name):
        print("get: " + name)
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point = Point(1, 2, 3)
point.u
point.x
point.y
point.z

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point = Point(.2, .3)

In [ ]:
print(point.x, point.y)
print(point.u, point.v)

In [ ]:
point.u = 1

In [ ]:
print(point.x, point.y)
print(point.u, point.v)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point = Point(.2, .3)

print(point.x, point.y)
print(point.u, point.v)

point.u = 1
point.v = .5

print(point.x, point.y)
print(point.u, point.v)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point1 = Point(1, 2, 3)
point1 * 2
print(point1.x, point1.y, point1.z)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rmul__(self, other):
        return self * other
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point1 = Point(1, 2, 3)
point1 *= 2
print(point1.x, point1.y, point1.z)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rmul__(self, other):
        return self * other
    
    def __div__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x /= other
            self.y /= other
            self.z /= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rdiv__(self, other):
        return self / other
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point1 = Point(8, 8, 8)
point1 = point1 / 2
print(point1.x, point1.y, point1.z)
point1 /= 2
print(point1.x, point1.y, point1.z)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rmul__(self, other):
        return self * other
    
    def __div__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x /= other
            self.y /= other
            self.z /= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rdiv__(self, other):
        return self / other
    
    def __add__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x += other
            self.y += other
            self.z += other
        elif isinstance(other, Point):
            self.x += other.x
            self.y += other.y
            self.z += other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __radd__(self, other):
        return self + other
        
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point1 = Point(1, 2, 3)
point1 + 2.
print(point1.x, point1.y, point1.z)
point2 = Point(3, 2, 1)
point1 = point1 + point2
print(point1.x, point1.y, point1.z)

In [ ]:
point1 = Point(1, 2, 3)
point1 += 2.
print(point1.x, point1.y, point1.z)
point2 = Point(3, 2, 1)
point1 += point2
print(point1.x, point1.y, point1.z)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rmul__(self, other):
        return self * other
    
    def __div__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x /= other
            self.y /= other
            self.z /= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rdiv__(self, other):
        return self / other
    
    def __add__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x += other
            self.y += other
            self.z += other
        elif isinstance(other, Point):
            self.x += other.x
            self.y += other.y
            self.z += other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __radd__(self, other):
        return self + other
    
    def __sub__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x -= other
            self.y -= other
            self.z -= other
        elif isinstance(other, Point):
            self.x -= other.x
            self.y -= other.y
            self.z -= other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __rsub__(self, other):
        return self - other
    
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point1 = Point(1, 2, 3)
point1 - 2.
print(point1.x, point1.y, point1.z)
point2 = Point(3, 2, 1)
point1 = point1 - point2
print(point1.x, point1.y, point1.z)

In [ ]:
point1 = Point(1, 2, 3)
point1 -= 2.
print(point1.x, point1.y, point1.z)
point2 = Point(3, 2, 1)
point1 -= point2
print(point1.x, point1.y, point1.z)

In [ ]:
print(point1)

In [ ]:
str(point)

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rmul__(self, other):
        return self * other
    
    def __div__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x /= other
            self.y /= other
            self.z /= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rdiv__(self, other):
        return self / other
    
    def __add__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x += other
            self.y += other
            self.z += other
        elif isinstance(other, Point):
            self.x += other.x
            self.y += other.y
            self.z += other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __radd__(self, other):
        return self + other
    
    def __sub__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x -= other
            self.y -= other
            self.z -= other
        elif isinstance(other, Point):
            self.x -= other.x
            self.y -= other.y
            self.z -= other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __rsub__(self, other):
        return self - other
    
    def __str__(self):
        return "(%d, %d, %d)" % (self.x, self.y, self.z)
    
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point = Point(1, 2, 3)
print(point)

In [ ]:
point

In [ ]:
class Point(object):
    '''This is a Point in 2/3D space.
    You can use .u ro .v for a uv point'''
    
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
        
    def __getattribute__(self, name):
        if name == 'u':
            return self.x
        elif name == 'v':
            return self.y
            
        return super(Point, self).__getattribute__(name)
    
    def __setattr__(self, name, value):
        if name == 'u':
            self.x = value
        elif name == 'v':
            self.y = value
            
        super(Point, self).__setattr__(name, value)
    
    def __mul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x *= other
            self.y *= other
            self.z *= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rmul__(self, other):
        return self * other
    
    def __div__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x /= other
            self.y /= other
            self.z /= other
        else:
            raise TypeError("must mul with int or float type")
            
        return self
            
    def __rdiv__(self, other):
        return self / other
    
    def __add__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x += other
            self.y += other
            self.z += other
        elif isinstance(other, Point):
            self.x += other.x
            self.y += other.y
            self.z += other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __radd__(self, other):
        return self + other
    
    def __sub__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.x -= other
            self.y -= other
            self.z -= other
        elif isinstance(other, Point):
            self.x -= other.x
            self.y -= other.y
            self.z -= other.z
        else:
            raise TypeError("must mul with int or float type")
            
        return self
    
    def __rsub__(self, other):
        return self - other
    
    def __str__(self):
        return "(%d, %d, %d)" % (self.x, self.y, self.z)
    
    def __repr__(self):
        return "Point(%d, %d, %d)" % (self.x, self.y, self.z)
    
    @staticmethod
    def One():
        return Point(1, 1, 1)

In [ ]:
point = Point(1, 2, 3)
print(point)
point

In [ ]:
# --------------------------------------------------------------------------------  
# Copyright (c) 2013 - 2014 Mack Stone. All rights reserved.  
#   
# Permission is hereby granted, free of charge, to any person obtaining a copy  
# of this software and associated documentation files (the "Software"), to deal  
# in the Software without restriction, including without limitation the rights  
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
# copies of the Software, and to permit persons to whom the Software is  
# furnished to do so, subject to the following conditions:  
#   
# The above copyright notice and this permission notice shall be included in  
# all copies or substantial portions of the Software.  
#   
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  
# THE SOFTWARE.  
# --------------------------------------------------------------------------------