forked from C-Core/UltimateTrimUV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry.py
108 lines (80 loc) · 2.5 KB
/
geometry.py
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
"""Geometry module.
This module contain geometry utilities.
"""
import mathutils
# coords in blender start from bottom-right corner as (0.0, 0.0)
# so change accordling
class Rectangle():
"""Rectangle rappresentation.
:param lowest: lowest corner
:type lowest: :class:`mathutils.Vector`
:param highest: highest corner
:type lowest: :class:`mathutils.Vector`
"""
def __init__(self, lowest, highest):
self.__topLeft = mathutils.Vector((lowest.x, highest.y))
self.__bottomRight = mathutils.Vector((highest.x, lowest.y))
def topLeft(self):
"""Return the top left corner.
:return: top left corner
:rtype: :class:`mathutils.Vector`
"""
return self.__topLeft
def top(self):
"""Return the top.
:return: top edge
:rtype: int
"""
return self.__topLeft.y
def topRight(self):
"""Return the top right corner.
:return: top right corner
:rtype: :class:`mathutils.Vector`
"""
return mathutils.Vector((self.__bottomRight.x, self.__topLeft.y))
def right(self):
"""Return the right edge.
:return: right edge
:rtype: int
"""
return self.__bottomRight.x
def bottomRight(self):
"""Return the bottom right corner.
:return: top bottom right
:rtype: :class:`mathutils.Vector`
"""
return self.__bottomRight
def bottom(self):
"""Return the bottom edge.
:return: bottom edge
:rtype: int
"""
return self.__bottomRight.y
def bottomLeft(self):
"""Return the bottom left corner.
:return: bottom left
:rtype: :class:`mathutils.Vector`
"""
return mathutils.Vector((self.__topLeft.x, self.__bottomRight.y))
def left(self):
"""Return the left edge.
:return: left edge
:rtype: int
"""
return self.__topLeft.x
def center(self):
"""Return the bounding box center.
:return: rectangle center
:rtype: :class:`mathutils.Vector`
"""
return (self.__topLeft + self.__bottomRight) / 2
class Size():
"""Rappresentation of size.
:param width: width.
:type width: float
:param height: height.
:type height: float
"""
def __init__(self, width, height):
self.width = width
self.height = height