espu-lib-vector 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.
- espu_lib_vector-0.0.1/PKG-INFO +21 -0
- espu_lib_vector-0.0.1/README.md +11 -0
- espu_lib_vector-0.0.1/pyproject.toml +19 -0
- espu_lib_vector-0.0.1/setup.cfg +4 -0
- espu_lib_vector-0.0.1/src/espu/lib/vector/__init__.py +1 -0
- espu_lib_vector-0.0.1/src/espu/lib/vector/utils.py +14 -0
- espu_lib_vector-0.0.1/src/espu/lib/vector/vector2.py +112 -0
- espu_lib_vector-0.0.1/src/espu_lib_vector.egg-info/PKG-INFO +21 -0
- espu_lib_vector-0.0.1/src/espu_lib_vector.egg-info/SOURCES.txt +10 -0
- espu_lib_vector-0.0.1/src/espu_lib_vector.egg-info/dependency_links.txt +1 -0
- espu_lib_vector-0.0.1/src/espu_lib_vector.egg-info/requires.txt +1 -0
- espu_lib_vector-0.0.1/src/espu_lib_vector.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: espu-lib-vector
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Internal library for the ESPU ecosystem
|
|
5
|
+
Author: EscapedShadows
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: espu==0.0.1
|
|
10
|
+
|
|
11
|
+
# ESPU Internal Library
|
|
12
|
+
|
|
13
|
+
This package is an internal library used by the **ESPU** ecosystem.
|
|
14
|
+
|
|
15
|
+
It is not intended for direct use.
|
|
16
|
+
|
|
17
|
+
## Links
|
|
18
|
+
|
|
19
|
+
Core package:
|
|
20
|
+
https://pypi.org/project/espu/
|
|
21
|
+
https://github.com/EscapedShadows/ESPU
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "espu-lib-vector"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Internal library for the ESPU ecosystem"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "EscapedShadows" }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
dependencies = [
|
|
14
|
+
"espu==0.0.1"
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
19
|
+
build-backend = "setuptools.build_meta"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .vector2 import Vec2
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
DEFAULT_EPSILON = 1e-9
|
|
4
|
+
|
|
5
|
+
def almost_equal(a: float, b: float, eps: float = DEFAULT_EPSILON) -> bool:
|
|
6
|
+
return abs(a - b) <= eps
|
|
7
|
+
|
|
8
|
+
def clamp(value: float, min_value: float, max_value: float) -> float:
|
|
9
|
+
return max(min_value, min(max_value, value))
|
|
10
|
+
|
|
11
|
+
def safe_div(value: float, divisor: float, default: float = 0.0) -> float:
|
|
12
|
+
if abs(divisor) < DEFAULT_EPSILON:
|
|
13
|
+
return default
|
|
14
|
+
return value / divisor
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Iterable
|
|
6
|
+
from .utils import DEFAULT_EPSILON, almost_equal, safe_div
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True, slots=True)
|
|
9
|
+
class Vec2:
|
|
10
|
+
x: float
|
|
11
|
+
y: float
|
|
12
|
+
|
|
13
|
+
@staticmethod
|
|
14
|
+
def from_tuple(v: Iterable[float]) -> Vec2:
|
|
15
|
+
x, y = v
|
|
16
|
+
return Vec2(float(x), float(y))
|
|
17
|
+
|
|
18
|
+
def to_tuple(self) -> tuple[float, float]:
|
|
19
|
+
return (self.x, self.y)
|
|
20
|
+
|
|
21
|
+
ZERO = None
|
|
22
|
+
ONE = None
|
|
23
|
+
UP = None
|
|
24
|
+
DOWN = None
|
|
25
|
+
LEFT = None
|
|
26
|
+
RIGHT = None
|
|
27
|
+
|
|
28
|
+
def __add__(self, o: Vec2) -> Vec2:
|
|
29
|
+
return Vec2(self.x + o.x, self.y + o.y)
|
|
30
|
+
|
|
31
|
+
def __sub__(self, o: Vec2) -> Vec2:
|
|
32
|
+
return Vec2(self.x - o.x, self.y - o.y)
|
|
33
|
+
|
|
34
|
+
def __mul__(self, s: float) -> Vec2:
|
|
35
|
+
return Vec2(self.x * s, self.y * s)
|
|
36
|
+
|
|
37
|
+
def __rmul__(self, s: float) -> Vec2:
|
|
38
|
+
return self * s
|
|
39
|
+
|
|
40
|
+
def __truediv__(self, s: float) -> Vec2:
|
|
41
|
+
return Vec2(
|
|
42
|
+
safe_div(self.x, s),
|
|
43
|
+
safe_div(self.y, s)
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def __neg__(self) -> Vec2:
|
|
47
|
+
return Vec2(-self.x, -self.y)
|
|
48
|
+
|
|
49
|
+
def __iter__(self):
|
|
50
|
+
yield self.x
|
|
51
|
+
yield self.y
|
|
52
|
+
|
|
53
|
+
def almost_equal(self, o: Vec2, eps: float = DEFAULT_EPSILON) -> bool:
|
|
54
|
+
return (
|
|
55
|
+
almost_equal(self.x, o.x, eps)
|
|
56
|
+
and almost_equal(self.y, o.y, eps)
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# geometry
|
|
60
|
+
def dot(self, o: Vec2) -> float:
|
|
61
|
+
return self.x * o.x + self.y * o.y
|
|
62
|
+
|
|
63
|
+
def length_sq(self) -> float:
|
|
64
|
+
return self.dot(self)
|
|
65
|
+
|
|
66
|
+
def length(self) -> float:
|
|
67
|
+
return math.sqrt(self.length_sq())
|
|
68
|
+
|
|
69
|
+
def distance_sq(self, o: Vec2) -> float:
|
|
70
|
+
return (self - o).length_sq()
|
|
71
|
+
|
|
72
|
+
def distance(self, o: Vec2) -> float:
|
|
73
|
+
return math.sqrt(self.distance_sq(o))
|
|
74
|
+
|
|
75
|
+
def normalize(self) -> Vec2:
|
|
76
|
+
l = self.length()
|
|
77
|
+
if l < DEFAULT_EPSILON:
|
|
78
|
+
return Vec2.ZERO
|
|
79
|
+
return self / l
|
|
80
|
+
|
|
81
|
+
def clamp_length(self, max_len: float) -> Vec2:
|
|
82
|
+
l = self.length()
|
|
83
|
+
if l <= max_len:
|
|
84
|
+
return self
|
|
85
|
+
return self.normalize() * max_len
|
|
86
|
+
|
|
87
|
+
def lerp(self, o: Vec2, t: float) -> Vec2:
|
|
88
|
+
return Vec2(
|
|
89
|
+
self.x + (o.x - self.x) * t,
|
|
90
|
+
self.y + (o.y - self.y) * t
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def perp(self) -> Vec2:
|
|
94
|
+
return Vec2(-self.y, self.x)
|
|
95
|
+
|
|
96
|
+
def angle(self) -> float:
|
|
97
|
+
return math.atan2(self.y, self.x)
|
|
98
|
+
|
|
99
|
+
def rotate(self, radians: float) -> Vec2:
|
|
100
|
+
c = math.cos(radians)
|
|
101
|
+
s = math.sin(radians)
|
|
102
|
+
return Vec2(
|
|
103
|
+
self.x * c - self.y * s,
|
|
104
|
+
self.x * s + self.y * c
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
Vec2.ZERO = Vec2(0.0, 0.0)
|
|
108
|
+
Vec2.ONE = Vec2(1.0, 1.0)
|
|
109
|
+
Vec2.UP = Vec2(0.0, 1.0)
|
|
110
|
+
Vec2.DOWN = Vec2(0.0, -1.0)
|
|
111
|
+
Vec2.LEFT = Vec2(-1.0, 0.0)
|
|
112
|
+
Vec2.RIGHT = Vec2(1.0, 0.0)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: espu-lib-vector
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Internal library for the ESPU ecosystem
|
|
5
|
+
Author: EscapedShadows
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: espu==0.0.1
|
|
10
|
+
|
|
11
|
+
# ESPU Internal Library
|
|
12
|
+
|
|
13
|
+
This package is an internal library used by the **ESPU** ecosystem.
|
|
14
|
+
|
|
15
|
+
It is not intended for direct use.
|
|
16
|
+
|
|
17
|
+
## Links
|
|
18
|
+
|
|
19
|
+
Core package:
|
|
20
|
+
https://pypi.org/project/espu/
|
|
21
|
+
https://github.com/EscapedShadows/ESPU
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/espu/lib/vector/__init__.py
|
|
4
|
+
src/espu/lib/vector/utils.py
|
|
5
|
+
src/espu/lib/vector/vector2.py
|
|
6
|
+
src/espu_lib_vector.egg-info/PKG-INFO
|
|
7
|
+
src/espu_lib_vector.egg-info/SOURCES.txt
|
|
8
|
+
src/espu_lib_vector.egg-info/dependency_links.txt
|
|
9
|
+
src/espu_lib_vector.egg-info/requires.txt
|
|
10
|
+
src/espu_lib_vector.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
espu==0.0.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
espu
|