jerboapy 0.2rc332__cp313-cp313-win_amd64.whl

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.
jerboapy/__init__.py ADDED
@@ -0,0 +1,31 @@
1
+ import importlib.metadata
2
+
3
+ # # Importation du module C++ généré par pybind11
4
+ # from .jerboapy_bin import *
5
+
6
+ # # Lecture automatique des métadonnées depuis pyproject.toml
7
+ # __version__ = importlib.metadata.version("jerboapy")
8
+ # __description__ = importlib.metadata.metadata("jerboapy")["Summary"]
9
+ # __author__ = importlib.metadata.metadata("jerboapy")["Authors"]
10
+ # __license__ = importlib.metadata.metadata("jerboapy")["License"]
11
+
12
+ # Importation du module C++ généré par pybind11
13
+ from .jerboapy_bin import *
14
+
15
+ # Gestion sécurisée des métadonnées
16
+ try:
17
+ import importlib.metadata
18
+ __version__ = importlib.metadata.version("jerboapy")
19
+ __description__ = importlib.metadata.metadata("jerboapy")["Summary"]
20
+ __author__ = importlib.metadata.metadata("jerboapy")["Author-Email"]
21
+ if not __author__:
22
+ __author__ = importlib.metadata.metadata("jerboapy")["Author"]
23
+ __license__ = importlib.metadata.metadata("jerboapy")["License-Expression"]
24
+ if not __license__:
25
+ __license__ = importlib.metadata.metadata("jerboapy")["License"]
26
+ except (ImportError, importlib.metadata.PackageNotFoundError):
27
+ # Valeurs par défaut si le package n'est pas installé
28
+ __version__ = "X.X.X-dev"
29
+ __description__ = "Jerboa C++ bindings for Python (dev version without metadata)"
30
+ __author__ = "Hakim"
31
+ __license__ = "GPL-3.0-or-later"
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: jerboapy
3
+ Version: 0.2rc332
4
+ Summary: Bindings C++ avec pybind11 de Jerboa
5
+ Author-email: Hakim Belhaouari <hakim.belhaouari@univ-poitiers.fr>
6
+ License-Expression: GPL-3.0-or-later
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Provides-Extra: ext
11
+ Requires-Dist: pyvista[trame]; extra == "ext"
12
+ Requires-Dist: trame; extra == "ext"
13
+ Requires-Dist: numpy; extra == "ext"
14
+ Requires-Dist: tqdm; extra == "ext"
15
+ Dynamic: license-file
16
+
17
+ # Jerboapy
18
+
19
+ This project is a port of the Jerboa C++ implementation to Python. It is a pybind11 binding to the Jerboa C++ library, which is located in the `jerboa-cpp` directory. The goal of this project is to provide a Python interface for users who prefer to work in Python while leveraging the performance and capabilities of the Jerboa C++ library.
20
+
21
+ Currently it proves a 3D modeler (understanding that there is an alpha_3 links in their gmaps).
22
+
23
+ ## Installation
24
+
25
+
26
+ To install the required dependencies, run:
27
+
28
+ ```bash
29
+ pip install jerboapy
30
+ ```
31
+
32
+ ### Optional: 3D visualization and advanced features
33
+
34
+ If you want to use the 3D visualization features and advanced coordinate/color classes, install the extra `ext`:
35
+
36
+ ```bash
37
+ pip install jerboapy[ext]
38
+ ```
39
+
40
+ This will install additional dependencies for graphical display and advanced geometry. The extra `ext` enables:
41
+
42
+ - **3D visualization** (with PyVista and Trame)
43
+ - The module `jerboa_ext` with:
44
+ - `Point3`: class for 3D coordinates
45
+ - `Color4`: class for RGBA color management
46
+
47
+ You can then use these classes for embedding coordinates and managing colors in your models.
48
+
49
+ ## Usage
50
+
51
+ Provide an example of how to use your project:
52
+
53
+ ```python
54
+ from jerboapy import *
55
+
56
+ # Example usage
57
+ modeler = Modeler3D()
58
+ ```
@@ -0,0 +1,15 @@
1
+ jerboapy/__init__.py,sha256=BwH2vmd8gtuluqjBRAOh47eFE3_RNBMxd3E7dwy65W0,1364
2
+ jerboapy/jerboapy_bin.cp311-win_amd64.pyd,sha256=jzW7WK3qRAkAEVA8uYkVSgSKIMxoTf1sSR1aDwPSgGQ,5337948
3
+ jerboapy/jerboapy_bin.cp312-win_amd64.pyd,sha256=KPq85nb4gS70_vM7W18ChI8lr94m-2hZdKGDZGh93pE,5346094
4
+ jerboapy/jerboapy_bin.cp313-win_amd64.pyd,sha256=KsQgXWS49ej5st1zKMHar6P3V1vVaz1B1aQtPZ5M6nw,5346092
5
+ jerboapy-0.2rc332.dist-info/licenses/LICENSE,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
6
+ jerboapy_ext/Color4.py,sha256=UjBUEZfNh1PIBjVzq1SoXc4CNc_eMGQW0ykqV1WL5OQ,4589
7
+ jerboapy_ext/Point3.py,sha256=rvmwLO1PkbqDGQoZrjx8lKzlsCGbsXFOqqDQOAmsuOQ,7936
8
+ jerboapy_ext/__init__.py,sha256=eBQcF_RN2xGtUv3VH4SLC4W9C6BbA0ocQA8V3j-c_kg,441
9
+ jerboapy_ext/render.py,sha256=ass7pAWSg3-RuCEhs1Qw8Bx9mBjAiwjgmC6G0r5Z9n8,7525
10
+ jerboapy_ext/rules.py,sha256=bVI3pwDn_zQnSTJVf9sLJYmDk7SNrTUVIU7dDFHcaYw,24112
11
+ jerboapy_ext/utils.py,sha256=YV6e52wD3xDaD4IZbyw2RPVXOqn07Uena5rOaRZNO_s,6952
12
+ jerboapy-0.2rc332.dist-info/METADATA,sha256=aIkkhV1rZYr28aHhfncoEcOjJmRlEue-Nl4ljgXhcqY,1810
13
+ jerboapy-0.2rc332.dist-info/WHEEL,sha256=qV0EIPljj1XC_vuSatRWjn02nZIz3N1t8jsZz7HBr2U,101
14
+ jerboapy-0.2rc332.dist-info/top_level.txt,sha256=Yp6MLfErdDW3Ysd_UZnBjTlaeLGx46jrJFqxU8-o1Q0,22
15
+ jerboapy-0.2rc332.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
5
+
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,2 @@
1
+ jerboapy
2
+ jerboapy_ext
jerboapy_ext/Color4.py ADDED
@@ -0,0 +1,175 @@
1
+ import numpy as np
2
+ from typing import List
3
+
4
+ class Color4:
5
+ EPSILON = 1e-2
6
+ BRIGHTER = 20
7
+ DARKER = -20
8
+
9
+ # Pré-définition des couleurs standards
10
+ RED = None
11
+ GREEN = None
12
+ BLUE = None
13
+ LIGHTGRAY = None
14
+ BLACK = None
15
+ WHITE = None
16
+ MAGENTA = None
17
+ YELLOW = None
18
+ CYAN = None
19
+ GRAY = None
20
+ DARKGRAY = None
21
+ LIGHTGRAY = None
22
+ ORANGE = None
23
+ PINK = None
24
+ PURPLE = None
25
+ BROWN = None
26
+ LIME = None
27
+ TEAL = None
28
+ NAVY = None
29
+ OLIVE = None
30
+ SILVER = None
31
+ GOLD = None
32
+ CORAL = None
33
+ INDIGO = None
34
+ LAVENDER = None
35
+ MAROON = None
36
+ CHOCOLATE = None
37
+ SALMON = None
38
+ SKYBLUE = None
39
+ IVORY = None
40
+ AQUA = None
41
+
42
+ def __init__(self, r: float, g: float, b: float, a: float = 1.0):
43
+ self.rgba = np.array([r, g, b, a], dtype=np.float32)
44
+
45
+ def copy(self) -> 'Color4':
46
+ return Color4(*self.rgba)
47
+
48
+ def toNumpy(self) -> np.ndarray:
49
+ return self.rgba
50
+
51
+ def r(self) -> float:
52
+ return self.rgba[0]
53
+
54
+ def g(self) -> float:
55
+ return self.rgba[1]
56
+
57
+ def b(self) -> float:
58
+ return self.rgba[2]
59
+
60
+ def a(self) -> float:
61
+ return self.rgba[3]
62
+
63
+ def getR(self) -> float:
64
+ return self.r()
65
+
66
+ def setR(self, r: float):
67
+ self.rgba[0] = r
68
+
69
+ def getG(self) -> float:
70
+ return self.g()
71
+
72
+ def setG(self, g: float):
73
+ self.rgba[1] = g
74
+
75
+ def getB(self) -> float:
76
+ return self.b()
77
+
78
+ def setB(self, b: float):
79
+ self.rgba[2] = b
80
+
81
+ def getA(self) -> float:
82
+ return self.a()
83
+
84
+ def setA(self, a: float):
85
+ self.rgba[3] = a
86
+
87
+ def setRGB(self, r: float, g: float, b: float, a: float = None):
88
+ self.rgba[:3] = [r, g, b]
89
+ if a is not None:
90
+ self.rgba[3] = a
91
+
92
+ def equals(self, obj: object) -> bool:
93
+ if not isinstance(obj, Color4):
94
+ return False
95
+ return np.allclose(self.rgba, obj.rgba, atol=self.EPSILON)
96
+
97
+ @staticmethod
98
+ def middle(a: 'Color4', b: 'Color4') -> 'Color4':
99
+ return Color4(*(a.rgba + b.rgba) / 2)
100
+
101
+ @staticmethod
102
+ def middle_list(colors: List['Color4']) -> 'Color4':
103
+ rgba_sum = np.sum([color.rgba for color in colors], axis=0)
104
+ return Color4(*(rgba_sum / len(colors)))
105
+
106
+ def __str__(self) -> str:
107
+ return f"Color4(r={self.r()}, g={self.g()}, b={self.b()}, a={self.a()})"
108
+
109
+ @staticmethod
110
+ def make(r: float, g: float, b: float, a: float = 1.0) -> 'Color4':
111
+ return Color4(r, g, b, a)
112
+
113
+ @staticmethod
114
+ def randomColor() -> 'Color4':
115
+ return Color4(*np.random.rand(3), 1.0)
116
+
117
+ @staticmethod
118
+ def darker(color: 'Color4') -> 'Color4':
119
+ factor = 0.8
120
+ return Color4(*(color.rgba[:3] * factor), color.a())
121
+
122
+ def brighter(self, i: float = 1.2) -> 'Color4':
123
+ return Color4(
124
+ *np.clip(self.rgba[:3] * i, 0.0, 1.0),
125
+ self.a()
126
+ )
127
+
128
+ def toGray(self) -> 'Color4':
129
+ gray = 0.299 * self.r() + 0.587 * self.g() + 0.114 * self.b()
130
+ return Color4(gray, gray, gray, self.a())
131
+
132
+ def scale(self, d: float):
133
+ self.rgba[:3] *= d
134
+
135
+ def scaleAdd(self, r: float):
136
+ self.rgba[:3] += r
137
+
138
+ def compareTo(self, o: 'Color4') -> int:
139
+ if self.equals(o):
140
+ return 0
141
+ return -1 if np.sum(self.rgba[:3]) < np.sum(o.rgba[:3]) else 1
142
+
143
+
144
+ # Initialisation des couleurs standards
145
+ Color4.RED = Color4(1.0, 0.0, 0.0)
146
+ Color4.GREEN = Color4(0.0, 1.0, 0.0)
147
+ Color4.BLUE = Color4(0.0, 0.0, 1.0)
148
+ Color4.LIGHTGRAY = Color4(0.5, 0.5, 0.5)
149
+ Color4.BLACK = Color4(0.0, 0.0, 0.0)
150
+ Color4.WHITE = Color4(1.0, 1.0, 1.0)
151
+ Color4.MAGENTA = Color4(1.0, 0.0, 1.0)
152
+ Color4.YELLOW = Color4(1.0, 1.0, 0.0)
153
+ Color4.CYAN = Color4(0.0, 1.0, 1.0)
154
+ Color4.GRAY = Color4(0.5, 0.5, 0.5)
155
+ Color4.DARKGRAY = Color4(0.25, 0.25, 0.25)
156
+ Color4.LIGHTGRAY = Color4(0.75, 0.75, 0.75)
157
+ Color4.ORANGE = Color4(1.0, 0.5, 0.0)
158
+ Color4.PINK = Color4(1.0, 0.75, 0.8)
159
+ Color4.PURPLE = Color4(0.5, 0.0, 0.5)
160
+ Color4.BROWN = Color4(0.65, 0.16, 0.16)
161
+ Color4.LIME = Color4(0.0, 1.0, 0.0)
162
+ Color4.TEAL = Color4(0.0, 0.5, 0.5)
163
+ Color4.NAVY = Color4(0.0, 0.0, 0.5)
164
+ Color4.OLIVE = Color4(0.5, 0.5, 0.0)
165
+ Color4.SILVER = Color4(0.75, 0.75, 0.75)
166
+ Color4.GOLD = Color4(1.0, 0.84, 0.0)
167
+ Color4.CORAL = Color4(1.0, 0.5, 0.31)
168
+ Color4.INDIGO = Color4(0.29, 0.0, 0.51)
169
+ Color4.LAVENDER = Color4(0.9, 0.9, 0.98)
170
+ Color4.MAROON = Color4(0.5, 0.0, 0.0)
171
+ Color4.CHOCOLATE = Color4(0.82, 0.41, 0.12)
172
+ Color4.SALMON = Color4(0.98, 0.5, 0.45)
173
+ Color4.SKYBLUE = Color4(0.53, 0.81, 0.92)
174
+ Color4.IVORY = Color4(1.0, 1.0, 0.94)
175
+ Color4.AQUA = Color4(0.0, 1.0, 1.0)
jerboapy_ext/Point3.py ADDED
@@ -0,0 +1,231 @@
1
+ import numpy as np
2
+ from typing import List, Collection, Union, Set
3
+
4
+ class Point3:
5
+ EPSILON = 1e-3
6
+ sqrt2 = np.sqrt(2.0)
7
+ sqrt1_2 = 1.0 / sqrt2
8
+ ZERO = None # Will be initialized later as Point3(0, 0, 0)
9
+ PI = 3.141592653589793
10
+
11
+ def __init__(self, x=0.0, y=None, z=None):
12
+ if isinstance(x, Point3) and isinstance(y, Point3):
13
+ # Cas où deux objets Point3 sont passés
14
+ a, b = x, y
15
+ self.x = b.x - a.x
16
+ self.y = b.y - a.y
17
+ self.z = b.z - a.z
18
+ elif y is None and z is None:
19
+ # Cas où un seul argument est passé (x, y, z par défaut à 0.0)
20
+ self.x = x
21
+ self.y = 0.0
22
+ self.z = 0.0
23
+ else:
24
+ # Cas où trois arguments sont passés
25
+ self.x = x
26
+ self.y = y
27
+ self.z = z
28
+
29
+ def toNumpy(self) -> np.ndarray:
30
+ return np.array([self.x, self.y, self.z], dtype=np.float32)
31
+
32
+ @staticmethod
33
+ def toDegree(rad: float) -> float:
34
+ return np.degrees(rad)
35
+
36
+ @staticmethod
37
+ def toRadian(deg: float) -> float:
38
+ return np.radians(deg)
39
+
40
+ @staticmethod
41
+ def CentreCercle3Point(a: 'Point3', b: 'Point3', c: 'Point3') -> 'Point3':
42
+ # Calculate the midpoints of AB and BC
43
+ mid_ab = Point3.linear(a, b, 0.5)
44
+ mid_bc = Point3.linear(b, c, 0.5)
45
+
46
+ # Calculate the normal vectors to AB and BC
47
+ ab = b.sub(a)
48
+ bc = c.sub(b)
49
+ normal_ab = Point3(-ab.y, ab.x, 0)
50
+ normal_bc = Point3(-bc.y, bc.x, 0)
51
+
52
+ # Solve for the intersection of the two lines
53
+ # Line 1: mid_ab + t * normal_ab
54
+ # Line 2: mid_bc + s * normal_bc
55
+ # We solve for t and s such that the two lines intersect
56
+ A = np.array([
57
+ [normal_ab.x, -normal_bc.x],
58
+ [normal_ab.y, -normal_bc.y]
59
+ ])
60
+ B = np.array([
61
+ mid_bc.x - mid_ab.x,
62
+ mid_bc.y - mid_ab.y
63
+ ])
64
+
65
+ try:
66
+ t, _ = np.linalg.solve(A, B)
67
+ except np.linalg.LinAlgError:
68
+ raise ValueError("The points are collinear and do not define a unique circle.")
69
+
70
+ # Calculate the center of the circle
71
+ center = Point3(
72
+ mid_ab.x + t * normal_ab.x,
73
+ mid_ab.y + t * normal_ab.y,
74
+ 0
75
+ )
76
+ return center
77
+
78
+ def equals(self, o: object) -> bool:
79
+ if not isinstance(o, Point3):
80
+ return False
81
+ return np.isclose(self.x, o.x, atol=self.EPSILON) and \
82
+ np.isclose(self.y, o.y, atol=self.EPSILON) and \
83
+ np.isclose(self.z, o.z, atol=self.EPSILON)
84
+
85
+ def get(self, i: int) -> float:
86
+ return [self.x, self.y, self.z][i]
87
+
88
+ def add(self, p: 'Point3') -> 'Point3':
89
+ # print(f"Adding Point3: ({self.x}, {self.y}, {self.z}) + ({p.x}, {p.y}, {p.z})")
90
+ return Point3(self.x + p.x, self.y + p.y, self.z + p.z)
91
+
92
+ def add_const(self, n: 'Point3') -> 'Point3':
93
+ return self.add(n)
94
+
95
+ def sub(self, p: 'Point3') -> 'Point3':
96
+ return Point3(self.x - p.x, self.y - p.y, self.z - p.z)
97
+
98
+ def scale(self, v: float) -> 'Point3':
99
+ # print(f"Scaling Point3: ({self.x}, {self.y}, {self.z}) by {v}")
100
+ return Point3(self.x * v, self.y * v, self.z * v)
101
+
102
+ def div(self, v: float) -> 'Point3':
103
+ return Point3(self.x / v, self.y / v, self.z / v)
104
+
105
+ def dot(self, p: 'Point3') -> float:
106
+ return self.x * p.x + self.y * p.y + self.z * p.z
107
+
108
+ def cross(self, v: 'Point3') -> 'Point3':
109
+ cross_product = np.cross([self.x, self.y, self.z], [v.x, v.y, v.z])
110
+ return Point3(*cross_product)
111
+
112
+ def norm(self) -> float:
113
+ return np.sqrt(self.x**2 + self.y**2 + self.z**2)
114
+
115
+ def norm2(self) -> float:
116
+ return self.x**2 + self.y**2 + self.z**2
117
+
118
+ def normalize(self):
119
+ n = self.norm()
120
+ if n > 0:
121
+ self.x /= n
122
+ self.y /= n
123
+ self.z /= n
124
+ return self
125
+
126
+ def distance(self, p: 'Point3') -> float:
127
+ return np.sqrt((self.x - p.x)**2 + (self.y - p.y)**2 + (self.z - p.z)**2)
128
+
129
+ def copy(self) -> 'Point3':
130
+ return Point3(self.x, self.y, self.z)
131
+
132
+ def __str__(self) -> str:
133
+ return f"Point3({self.x}, {self.y}, {self.z})"
134
+
135
+ @staticmethod
136
+ def middle(points: Union[List['Point3'], Collection['Point3'], 'Point3']) -> 'Point3':
137
+ if isinstance(points, Point3):
138
+ # Si un seul point est fourni, on le retourne directement
139
+ return points
140
+ elif isinstance(points, (list, set, tuple)):
141
+ # Si une collection de points est fournie, on calcule le barycentre
142
+ x_sum = sum(p.x for p in points)
143
+ y_sum = sum(p.y for p in points)
144
+ z_sum = sum(p.z for p in points)
145
+ count = len(points)
146
+ if count == 0:
147
+ raise ValueError("La collection de points est vide.")
148
+ return Point3(x_sum / count, y_sum / count, z_sum / count)
149
+ else:
150
+ raise TypeError("L'argument doit être un Point3 ou une collection de Point3.")
151
+
152
+ @staticmethod
153
+ def barycenter(a: 'Point3', ca: float, b: 'Point3', cb: float) -> 'Point3':
154
+ total_weight = ca + cb
155
+ if total_weight == 0:
156
+ raise ValueError("The sum of weights (ca + cb) must not be zero.")
157
+ x = (a.x * ca + b.x * cb) / total_weight
158
+ y = (a.y * ca + b.y * cb) / total_weight
159
+ z = (a.z * ca + b.z * cb) / total_weight
160
+ return Point3(x, y, z)
161
+
162
+ @staticmethod
163
+ def clamp(val: float, min_val: float, max_val: float) -> float:
164
+ return max(min(val, max_val), min_val)
165
+
166
+ def isInside(self, a: 'Point3', b: 'Point3') -> bool:
167
+ return a.x <= self.x <= b.x and a.y <= self.y <= b.y and a.z <= self.z <= b.z
168
+
169
+ def compareTo(self, o: 'Point3') -> int:
170
+ if self.equals(o):
171
+ return 0
172
+ return -1 if self.norm() < o.norm() else 1
173
+
174
+ @staticmethod
175
+ def min(a: 'Point3', b: 'Point3') -> 'Point3':
176
+ return Point3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z))
177
+
178
+ @staticmethod
179
+ def max(a: 'Point3', b: 'Point3') -> 'Point3':
180
+ return Point3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z))
181
+
182
+ @staticmethod
183
+ def linear(a: 'Point3', b: 'Point3', k: float) -> 'Point3':
184
+ return Point3(a.x + k * (b.x - a.x), a.y + k * (b.y - a.y), a.z + k * (b.z - a.z))
185
+
186
+ def __add__(self, other):
187
+ if isinstance(other, Point3):
188
+ return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
189
+ return NotImplemented
190
+
191
+ def __sub__(self, other):
192
+ if isinstance(other, Point3):
193
+ return Point3(self.x - other.x, self.y - other.y, self.z - other.z)
194
+ return NotImplemented
195
+
196
+ def __mul__(self, other):
197
+ if isinstance(other, (int, float)):
198
+ return Point3(self.x * other, self.y * other, self.z * other)
199
+ return NotImplemented
200
+
201
+ def __rmul__(self, other):
202
+ return self.__mul__(other)
203
+
204
+ def __truediv__(self, other):
205
+ if isinstance(other, (int, float)):
206
+ return Point3(self.x / other, self.y / other, self.z / other)
207
+ return NotImplemented
208
+
209
+ def __eq__(self, other):
210
+ if not isinstance(other, Point3):
211
+ return False
212
+ return self.equals(other)
213
+
214
+ def __neg__(self):
215
+ return Point3(-self.x, -self.y, -self.z)
216
+ def __iter__(self):
217
+ yield self.x
218
+ yield self.y
219
+ yield self.z
220
+ def __array__(self, dtype=None):
221
+ if dtype is None:
222
+ dtype = np.float32
223
+ return np.array([self.x, self.y, self.z], dtype=dtype)
224
+
225
+ # def __add__(self, other):
226
+ # if isinstance(other, Point3):
227
+ # return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
228
+ # raise TypeError("Unsupported operand type(s) for +: 'Point3' and '{}'".format(type(other).__name__))
229
+
230
+ # Initialize the ZERO constant
231
+ Point3.ZERO = Point3(0.0, 0.0, 0.0)