epic-utils 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- epic_utils-0.0.1/PKG-INFO +12 -0
- epic_utils-0.0.1/epic_utils/__init__.py +1 -0
- epic_utils-0.0.1/epic_utils/core.py +155 -0
- epic_utils-0.0.1/epic_utils.egg-info/PKG-INFO +12 -0
- epic_utils-0.0.1/epic_utils.egg-info/SOURCES.txt +8 -0
- epic_utils-0.0.1/epic_utils.egg-info/dependency_links.txt +1 -0
- epic_utils-0.0.1/epic_utils.egg-info/requires.txt +2 -0
- epic_utils-0.0.1/epic_utils.egg-info/top_level.txt +1 -0
- epic_utils-0.0.1/setup.cfg +4 -0
- epic_utils-0.0.1/setup.py +19 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: epic_utils
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Dependencies i regurlarly use
|
|
5
|
+
Author: Epic099
|
|
6
|
+
Author-email:
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Requires-Dist: math
|
|
12
|
+
Requires-Dist: typing
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from epic_utils.core import Vector2, Region2, Color, Converter
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
class ErrorHandler:
|
|
5
|
+
def raiseError(typ, message : str):
|
|
6
|
+
raise typ(message)
|
|
7
|
+
def isType(obj, typ) -> bool:
|
|
8
|
+
return isinstance(obj, typ)
|
|
9
|
+
def isTypes(obj, types) -> bool:
|
|
10
|
+
for typ in types:
|
|
11
|
+
if isinstance(obj, typ):
|
|
12
|
+
return True
|
|
13
|
+
return False
|
|
14
|
+
|
|
15
|
+
class Converter:
|
|
16
|
+
def dec2hex(value : int):
|
|
17
|
+
h = hex(value)
|
|
18
|
+
result = str.upper(h[2:])
|
|
19
|
+
if len(result) < 2:
|
|
20
|
+
result = "0" + result
|
|
21
|
+
return result
|
|
22
|
+
class Vector2:
|
|
23
|
+
def __init__(self, x : float, y : float):
|
|
24
|
+
self.x : float = x
|
|
25
|
+
self.y : float = y
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def sqrMagnitude(self):
|
|
29
|
+
return self.x**2 + self.y**2
|
|
30
|
+
@property
|
|
31
|
+
def magnitude(self):
|
|
32
|
+
return math.sqrt(self.sqrMagnitude)
|
|
33
|
+
@property
|
|
34
|
+
def normalized(self):
|
|
35
|
+
mag = self.magnitude
|
|
36
|
+
return Vector2(self.x/mag, self.y/mag)
|
|
37
|
+
@classmethod
|
|
38
|
+
def sqrDistance(cls, vector1, vector2):
|
|
39
|
+
if not (isinstance(vector1, Vector2) and isinstance(vector2, Vector2)):
|
|
40
|
+
ErrorHandler.raiseError(TypeError, f"<Vector2, Vector2> expected, got <{type(vector1).__name__},{type(vector2).__name__}>")
|
|
41
|
+
return abs(vector2.x - vector1.x)**2 + abs(vector2.y - vector1.y)**2
|
|
42
|
+
@classmethod
|
|
43
|
+
def distance(cls, vector1, vector2) -> float:
|
|
44
|
+
if not (isinstance(vector1, Vector2) and isinstance(vector2, Vector2)):
|
|
45
|
+
ErrorHandler.raiseError(TypeError, f"<Vector2, Vector2> expected, got <{type(vector1).__name__},{type(vector2).__name__}>")
|
|
46
|
+
return math.sqrt(Vector2.sqrDistance(vector1, vector2))
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def fromArray(cls, array : Union[list, tuple]):
|
|
50
|
+
if not ErrorHandler.isTypes(array, [list, tuple]):
|
|
51
|
+
ErrorHandler.raiseError(TypeError, f"<list|tuple> expected, got <{type(array).__name__}>")
|
|
52
|
+
if len(array) < 2:
|
|
53
|
+
ErrorHandler.raiseError(IndexError, f"length <2> expected, got length <{len(array)}>")
|
|
54
|
+
return Vector2(array[0], array[1])
|
|
55
|
+
@classmethod
|
|
56
|
+
def fromDict(cls, dictionary : dict):
|
|
57
|
+
if not ErrorHandler.isType(dictionary, dict):
|
|
58
|
+
ErrorHandler.raiseError(TypeError, f"<dict> expected, got <{type(dictionary).__name__}>")
|
|
59
|
+
keys = list(dictionary.keys())
|
|
60
|
+
if not ("x" in keys and "y" in keys):
|
|
61
|
+
ErrorHandler.raiseError(KeyError, f"keys <x,y> expected, got keys <{",".join(keys)}>")
|
|
62
|
+
return Vector2(dictionary["x"], dictionary["y"])
|
|
63
|
+
|
|
64
|
+
def __add__(self, value):
|
|
65
|
+
if ErrorHandler.isType(value, Vector2):
|
|
66
|
+
return Vector2(self.x + value.x, self.y + value.y)
|
|
67
|
+
return Vector2(self.x + value, self.y + value)
|
|
68
|
+
def __sub__(self, value):
|
|
69
|
+
if ErrorHandler.isType(value, Vector2):
|
|
70
|
+
return Vector2(self.x - value.x, self.y - value.y)
|
|
71
|
+
return Vector2(self.x - value, self.y - value)
|
|
72
|
+
def __mul__(self, value):
|
|
73
|
+
if ErrorHandler.isType(value, Vector2):
|
|
74
|
+
return Vector2(self.x * value.x, self.y * value.y)
|
|
75
|
+
return Vector2(self.x * value, self.y * value)
|
|
76
|
+
def __div__(self, value):
|
|
77
|
+
if ErrorHandler.isType(value, Vector2):
|
|
78
|
+
if value.x == 0.0 or value.y == 0.0:
|
|
79
|
+
ErrorHandler.raiseError(ZeroDivisionError, "")
|
|
80
|
+
return Vector2(self.x / value.x, self.y / value.y)
|
|
81
|
+
if value == 0.0:
|
|
82
|
+
ErrorHandler.raiseError(ZeroDivisionError, "")
|
|
83
|
+
return Vector2(self.x / value, self.y / value)
|
|
84
|
+
def __truediv__(self, value):
|
|
85
|
+
if ErrorHandler.isType(value, Vector2):
|
|
86
|
+
if value.x == 0.0 or value.y == 0.0:
|
|
87
|
+
ErrorHandler.raiseError(ZeroDivisionError, "")
|
|
88
|
+
return Vector2(self.x / value.x, self.y / value.y)
|
|
89
|
+
if value == 0.0:
|
|
90
|
+
ErrorHandler.raiseError(ZeroDivisionError, "")
|
|
91
|
+
return Vector2(self.x / value, self.y / value)
|
|
92
|
+
def __pow__(self, value):
|
|
93
|
+
if ErrorHandler.isType(value, Vector2):
|
|
94
|
+
return Vector2(self.x **value.x, self.y**value.y)
|
|
95
|
+
return Vector2(self.x**value, self.y**value)
|
|
96
|
+
|
|
97
|
+
def __str__(self):
|
|
98
|
+
return f"Vector2({self.x}, {self.y})"
|
|
99
|
+
|
|
100
|
+
class Region2:
|
|
101
|
+
def __init__(self, vector1 : Vector2, vector2 : Vector2):
|
|
102
|
+
self.v1 : Vector2 = Vector2(min(vector1.x, vector2.x), min(vector1.y, vector2.y))
|
|
103
|
+
self.v2 : Vector2 = Vector2(max(vector1.x, vector2.x), max(vector1.y, vector2.y))
|
|
104
|
+
def isInside(self, vector : Vector2) -> bool:
|
|
105
|
+
return self.v1.x <= vector.x and self.v1.y <= vector.y and self.v2.x >= vector.x and self.v2.y >= vector.y
|
|
106
|
+
|
|
107
|
+
def __str__(self):
|
|
108
|
+
return f"Region2({self.v1}, {self.v2})"
|
|
109
|
+
|
|
110
|
+
class Color:
|
|
111
|
+
def __init__(self, r : int, g : int, b : int):
|
|
112
|
+
self.r : int = r
|
|
113
|
+
self.b : int = b
|
|
114
|
+
self.g : int = g
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def hex(self):
|
|
119
|
+
r = Converter.dec2hex(self.r)
|
|
120
|
+
g = Converter.dec2hex(self.g)
|
|
121
|
+
b = Converter.dec2hex(self.b)
|
|
122
|
+
return r + g + b
|
|
123
|
+
def toTuple(self) -> tuple:
|
|
124
|
+
return (self.r, self.g, self.b)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def fromTuple(cl, tup : tuple):
|
|
129
|
+
if len(tup) < 3:
|
|
130
|
+
return False
|
|
131
|
+
return Color(tup[0], tup[1], tup[2])
|
|
132
|
+
@property
|
|
133
|
+
@classmethod
|
|
134
|
+
def white(cl):
|
|
135
|
+
return Color(255, 255, 255)
|
|
136
|
+
@classmethod
|
|
137
|
+
@property
|
|
138
|
+
def black(cl):
|
|
139
|
+
return Color(0, 0, 0)
|
|
140
|
+
@classmethod
|
|
141
|
+
@property
|
|
142
|
+
def red(cl):
|
|
143
|
+
return Color(255, 0, 0)
|
|
144
|
+
@classmethod
|
|
145
|
+
@property
|
|
146
|
+
def green(cl):
|
|
147
|
+
return Color(0, 255, 0)
|
|
148
|
+
@classmethod
|
|
149
|
+
@property
|
|
150
|
+
def blue(cl):
|
|
151
|
+
return Color(0, 0, 255)
|
|
152
|
+
|
|
153
|
+
def __str__(self):
|
|
154
|
+
return f"Color({self.r}, {self.g}, {self.b})"
|
|
155
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: epic_utils
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Dependencies i regurlarly use
|
|
5
|
+
Author: Epic099
|
|
6
|
+
Author-email:
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Requires-Dist: math
|
|
12
|
+
Requires-Dist: typing
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
epic_utils
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
setup(
|
|
3
|
+
name='epic_utils',
|
|
4
|
+
version='0.0.1',
|
|
5
|
+
author='Epic099',
|
|
6
|
+
author_email='',
|
|
7
|
+
description='Dependencies i regurlarly use',
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
classifiers=[
|
|
10
|
+
'Programming Language :: Python :: 3',
|
|
11
|
+
'License :: OSI Approved :: MIT License',
|
|
12
|
+
'Operating System :: OS Independent',
|
|
13
|
+
],
|
|
14
|
+
python_requires='>=3.6',
|
|
15
|
+
install_requires=[
|
|
16
|
+
"math",
|
|
17
|
+
"typing"
|
|
18
|
+
]
|
|
19
|
+
)
|