vecmath 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kennedy Ruiz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
vecmath-0.1/PKG-INFO ADDED
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: vecmath
3
+ Version: 0.1
4
+ Summary: A compact math library with vector operations, trigonometry, and handy utilities.
5
+ Author-email: Kennedy Ruiz <kennedyruiz.dev@gmail.com>
6
+ License: MIT
7
+ License-File: LICENSE.txt
8
+ Dynamic: license-file
vecmath-0.1/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # VecMath
2
+
3
+ ## Description
4
+ VecMath is a compact Python math library with vector operations, trigonometry functions, and handy utilities.
5
+ It includes functions like `dot`, `norm`, `normalize`, `distance`, `project`, `reject`, `angle`, `sqrt`, `atan`, `atan2`, `acos`, and more.
6
+
7
+ ## Installation
8
+ Install VecMath locally using pip:
9
+
10
+ ```bash
11
+ pip install .
12
+ ```
13
+
14
+
15
+ Or clone the repository and import the module:
16
+ git clone https://github.com/knd579/VecMath.git
17
+ cd vecmath
18
+ ```bash
19
+ pip install .
20
+ ```
21
+
22
+
23
+ ## Usage
24
+ Import the library and use its functions:
25
+
26
+ ```python
27
+ import vecmath as vc
28
+
29
+ pi = vc.pi()
30
+
31
+ v = [1, 2]
32
+ z = [3, 4]
33
+ x = dot(v, z)
34
+ ```
35
+
36
+
37
+ ## Features
38
+ - Vector operations
39
+
40
+ - Trigonometry
41
+
42
+ - Float precision helpers: float16, float32, float64
43
+
44
+ - Constants: pi, tau, eps, e
45
+
46
+
47
+ ## Contributing
48
+ Contributions are welcome! Feel free to submit pull requests or open issues.
49
+
50
+
51
+ ## License
52
+ MIT License
@@ -0,0 +1,8 @@
1
+ [project]
2
+ name = "vecmath"
3
+ version = "0.1"
4
+ description = "A compact math library with vector operations, trigonometry, and handy utilities."
5
+ authors = [
6
+ { name = "Kennedy Ruiz", email = "kennedyruiz.dev@gmail.com" }
7
+ ]
8
+ license = { text = "MIT" }
vecmath-0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,35 @@
1
+ import vecmath as vc
2
+
3
+ x = vc.clamp(5, 0, 10)
4
+ print(x) # output: 5
5
+
6
+ a = [1, 2, 3]
7
+ b = [4, 5, 6]
8
+ print(vc.dot(a, b) == 1*4 + 2*5 + 3*6) # output: True | =32
9
+
10
+ print("pi: " + str(vc.pi)) # output: pi: 3.141592653589793
11
+ print("tau: " + str(vc.tau)) # output: tau: 6.283185307179586
12
+ print("epsilon: " + str(vc.eps)) # output: epsilon: 2.220446049250313e-16
13
+ print("euler: " + str(vc.e)) # output: euler: 2.718281828459045
14
+
15
+
16
+ pi1 = vc.float64(3.14)
17
+ pi2 = vc.float32(3.14)
18
+ pi3 = vc.float16(3.14)
19
+
20
+ y = vc.Array([1, 2, 3])
21
+ print(y) # output: Array([1, 2, 3])
22
+ print(y[1]) # output: 2
23
+
24
+ y[1] = 42
25
+ y.append(4)
26
+ print(y) # output: Array([1, 42, 3, 4])
27
+
28
+ y.pop()
29
+ print(y) # output: Array([1, 2, 3])
30
+
31
+
32
+ try:
33
+ vc.dot([1,2], [1])
34
+ except ValueError as e:
35
+ print("Erro:", e) # output: Erro: dot: vectors must have the same length
@@ -0,0 +1 @@
1
+ from .vecmath import *
@@ -0,0 +1,245 @@
1
+ import struct
2
+
3
+
4
+ def float64(x):
5
+ return struct.unpack('d', struct.pack('d', x))[0]
6
+
7
+ def float32(x):
8
+ return struct.unpack('f', struct.pack('f', x))[0]
9
+
10
+ def float16(x):
11
+ return struct.unpack('e', struct.pack('e', x))[0]
12
+
13
+ pi = float64(3.141592653589793)
14
+ tau = float64(2*pi)
15
+ eps = float64(1e-9)
16
+ e = float64(2.718281828459045)
17
+
18
+
19
+ class Array:
20
+ def __init__(self, values):
21
+ self.values = list(values)
22
+
23
+ def __repr__(self):
24
+ return f"Array({self.values})"
25
+
26
+ def __getitem__(self, i):
27
+ return self.values[i]
28
+
29
+ def __setitem__(self, i, v):
30
+ self.values[i] = v
31
+
32
+ def __len__(self):
33
+ return len(self.values)
34
+
35
+ def append(self, v):
36
+ self.values.append(v)
37
+
38
+ def pop(self, i=-1):
39
+ return self.values.pop(i)
40
+
41
+
42
+
43
+ def sqrt(x):
44
+ if x < 0:
45
+ raise ValueError("sqrt: x must be >= 0")
46
+
47
+ if x == 0:
48
+ return 0.0
49
+
50
+ return x ** 0.5
51
+
52
+
53
+ def atan(x, iterations=20):
54
+ if abs(x) > 1:
55
+ if x > 0:
56
+ return pi / 2 - atan(1 / x, iterations)
57
+ else:
58
+ return -pi / 2 - atan(1 / x, iterations)
59
+
60
+ r = 0
61
+ for n in range(iterations):
62
+ term = ((-1) ** n) * (x ** (2*n + 1)) / (2*n + 1)
63
+ r += term
64
+
65
+ return r
66
+
67
+
68
+ def atan2(x, y):
69
+ if x > 0:
70
+ return atan(y / x)
71
+ elif x < 0 and y >= 0:
72
+ return atan(y / x) + pi
73
+ elif x < 0 and y < 0:
74
+ return atan(y / x) - pi
75
+ elif x == 0 and y > 0:
76
+ return pi / 2
77
+ elif x == 0 and y < 0:
78
+ return -pi / 2
79
+ else:
80
+ raise ValueError("atan2: x and y cannot both be 0")
81
+
82
+
83
+ def acos(x):
84
+ if x < -1 or x > 1:
85
+ raise ValueError("acos: x must be in [-1, 1]")
86
+
87
+ if x == 1:
88
+ return 0.0
89
+ if x == -1:
90
+ return pi
91
+
92
+ return atan(sqrt(1 - x*x) / x)
93
+
94
+
95
+ def dot(a, b):
96
+ # a and b must have the same length.
97
+
98
+ if len(a) != len(b):
99
+ raise ValueError("dot: vectors must be the same size")
100
+
101
+ return sum(x * y for x, y in zip(a, b))
102
+
103
+
104
+ def norm(v):
105
+ return sum(x*x for x in v) ** 0.5
106
+
107
+
108
+ def normalize(v):
109
+ n = norm(v)
110
+ if n == 0:
111
+ raise ValueError("normalize: cannot normalize zero vector")
112
+
113
+ return [x / n for x in v]
114
+
115
+
116
+ def distance(a, b):
117
+ if len(a) != len(b):
118
+ raise ValueError("distance: size mismatch")
119
+
120
+ return norm([x - y for x, y in zip(a, b)])
121
+
122
+
123
+ def project(v, n):
124
+ # n must be normalized
125
+
126
+ k = dot(v, n)
127
+ return [k * x for x in n]
128
+
129
+
130
+ def reject(v, n):
131
+ p = project(v, n)
132
+ return [x - y for x, y in zip(v, p)]
133
+
134
+
135
+ def angle(a, b):
136
+ return acos(dot(a, b) / (norm(a) * norm(b)))
137
+
138
+
139
+ def cross(a, b):
140
+ if len(a) == 3 and len(b) == 3:
141
+ return [
142
+ a[1]*b[2] - a[2]*b[1],
143
+ a[2]*b[0] - a[0]*b[2],
144
+ a[0]*b[1] - a[1]*b[0]
145
+ ]
146
+ raise ValueError("cross: only for 3D vectors")
147
+
148
+
149
+ def factorial(n):
150
+ r = 1
151
+ for i in range(2, n+1):
152
+ r *= i
153
+ return r
154
+
155
+
156
+ def sin(x, iterations=20):
157
+ r = 0
158
+ for n in range(iterations):
159
+ r += ((-1)**n) * x**(2*n + 1) / factorial(2*n + 1)
160
+ return r
161
+
162
+
163
+ def cos(x, iterations=20):
164
+ r = 0
165
+ for n in range(iterations):
166
+ r += ((-1)**n) * x**(2*n) / factorial(2*n)
167
+ return r
168
+
169
+
170
+ def tan(x):
171
+ return sin(x) / cos(x)
172
+
173
+
174
+ def exp(x, iterations=20):
175
+ r = 0
176
+ for n in range(iterations):
177
+ r += x**n / factorial(n)
178
+ return r
179
+
180
+
181
+ def log(x, iterations=50):
182
+ if x <= 0:
183
+ raise ValueError("log: x must be > 0")
184
+
185
+ y = (x - 1) / (x + 1)
186
+ y2 = y * y
187
+ r = 0
188
+ for n in range(1, iterations+1, 2):
189
+ r += (1/n) * y**n
190
+ y *= y2
191
+ return 2 * r
192
+
193
+
194
+ def clamp(x, min_val, max_val):
195
+ return max(min_val, min(x, max_val))
196
+
197
+
198
+ def reflect(v, n):
199
+ k = 2 * dot(v, n)
200
+ return [x - k * y for x, y in zip(v, n)]
201
+
202
+
203
+ def pow(x, y):
204
+ return x ** y
205
+
206
+
207
+ def abs(x):
208
+ return x if x >= 0 else -x
209
+
210
+
211
+ def degrees(x):
212
+ return x * 180 / pi
213
+
214
+
215
+ def radians(x):
216
+ return x * pi / 180
217
+
218
+
219
+ def lerp(a, b, t):
220
+ return a + (b - a) * t
221
+
222
+
223
+ def sign(x):
224
+ if x > 0:
225
+ return 1
226
+ elif x < 0:
227
+ return -1
228
+ else:
229
+ return 0
230
+
231
+
232
+ def minv(*args):
233
+ return min(args)
234
+
235
+
236
+ def maxv(*args):
237
+ return max(args)
238
+
239
+
240
+ def clamp(x, min_val, max_val):
241
+ return max(min_val, min(x, max_val))
242
+
243
+
244
+ def clamp_vec(v, min_val, max_val):
245
+ return [clamp(x, min_val, max_val) for x in v]
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: vecmath
3
+ Version: 0.1
4
+ Summary: A compact math library with vector operations, trigonometry, and handy utilities.
5
+ Author-email: Kennedy Ruiz <kennedyruiz.dev@gmail.com>
6
+ License: MIT
7
+ License-File: LICENSE.txt
8
+ Dynamic: license-file
@@ -0,0 +1,10 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ tests/tests.py
5
+ vecmath/__init__.py
6
+ vecmath/vecmath.py
7
+ vecmath.egg-info/PKG-INFO
8
+ vecmath.egg-info/SOURCES.txt
9
+ vecmath.egg-info/dependency_links.txt
10
+ vecmath.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ vecmath