egeometry 0.2.1__py3-none-any.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.
- egeometry/__init__.py +17 -0
- egeometry/_drectangle2d.py +73 -0
- egeometry/_frectangle2d.py +73 -0
- egeometry/py.typed +0 -0
- egeometry-0.2.1.dist-info/METADATA +10 -0
- egeometry-0.2.1.dist-info/RECORD +7 -0
- egeometry-0.2.1.dist-info/WHEEL +4 -0
egeometry/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# generated from codegen/templates/__init__.py
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"DRectangle2d",
|
|
7
|
+
"DRectangle2dOverlappable",
|
|
8
|
+
"FRectangle2d",
|
|
9
|
+
"FRectangle2dOverlappable",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# egeometry
|
|
14
|
+
from ._drectangle2d import DRectangle2d
|
|
15
|
+
from ._drectangle2d import DRectangle2dOverlappable
|
|
16
|
+
from ._frectangle2d import FRectangle2d
|
|
17
|
+
from ._frectangle2d import FRectangle2dOverlappable
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# generated from codegen/templates/_rectangle2d.py
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = ["DRectangle2d", "DRectangle2dOverlappable"]
|
|
6
|
+
|
|
7
|
+
# emath
|
|
8
|
+
from emath import DVector2
|
|
9
|
+
|
|
10
|
+
# python
|
|
11
|
+
from typing import Protocol
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DRectangle2dOverlappable(Protocol):
|
|
15
|
+
def overlaps_d_rectangle(self, other: DRectangle2d) -> bool:
|
|
16
|
+
...
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DRectangle2d:
|
|
20
|
+
__slots__ = ["_extent", "_position", "_size"]
|
|
21
|
+
|
|
22
|
+
def __init__(self, position: DVector2, size: DVector2):
|
|
23
|
+
if size <= DVector2(0):
|
|
24
|
+
raise ValueError("each size dimension must be > 0")
|
|
25
|
+
self._position = position
|
|
26
|
+
self._size = size
|
|
27
|
+
self._extent = self._position + self._size
|
|
28
|
+
|
|
29
|
+
def __eq__(self, other: object) -> bool:
|
|
30
|
+
if not isinstance(other, DRectangle2d):
|
|
31
|
+
return False
|
|
32
|
+
return self._position == other._position and self._size == other._size
|
|
33
|
+
|
|
34
|
+
def overlaps(self, other: DVector2 | DRectangle2dOverlappable) -> bool:
|
|
35
|
+
if isinstance(other, DVector2):
|
|
36
|
+
return self.overlaps_d_vector_2(other)
|
|
37
|
+
try:
|
|
38
|
+
other_overlaps = other.overlaps_d_rectangle
|
|
39
|
+
except AttributeError:
|
|
40
|
+
raise TypeError(other)
|
|
41
|
+
return other_overlaps(self)
|
|
42
|
+
|
|
43
|
+
def overlaps_d_rectangle(self, other: DRectangle2d) -> bool:
|
|
44
|
+
return not (
|
|
45
|
+
self._position.x >= other._extent.x
|
|
46
|
+
or self._extent.x <= other._position.x
|
|
47
|
+
or self._position.y >= other._extent.y
|
|
48
|
+
or self._extent.y <= other._position.y
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def overlaps_d_vector_2(self, other: DVector2) -> bool:
|
|
52
|
+
return (
|
|
53
|
+
other.x >= self._position.x
|
|
54
|
+
and other.x < self._extent.x
|
|
55
|
+
and other.y >= self._position.y
|
|
56
|
+
and other.y < self._extent.y
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def bounding_box(self) -> DRectangle2d:
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def extent(self) -> DVector2:
|
|
65
|
+
return self._extent
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def position(self) -> DVector2:
|
|
69
|
+
return self._position
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def size(self) -> DVector2:
|
|
73
|
+
return self._size
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# generated from codegen/templates/_rectangle2d.py
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = ["FRectangle2d", "FRectangle2dOverlappable"]
|
|
6
|
+
|
|
7
|
+
# emath
|
|
8
|
+
from emath import FVector2
|
|
9
|
+
|
|
10
|
+
# python
|
|
11
|
+
from typing import Protocol
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FRectangle2dOverlappable(Protocol):
|
|
15
|
+
def overlaps_f_rectangle(self, other: FRectangle2d) -> bool:
|
|
16
|
+
...
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FRectangle2d:
|
|
20
|
+
__slots__ = ["_extent", "_position", "_size"]
|
|
21
|
+
|
|
22
|
+
def __init__(self, position: FVector2, size: FVector2):
|
|
23
|
+
if size <= FVector2(0):
|
|
24
|
+
raise ValueError("each size dimension must be > 0")
|
|
25
|
+
self._position = position
|
|
26
|
+
self._size = size
|
|
27
|
+
self._extent = self._position + self._size
|
|
28
|
+
|
|
29
|
+
def __eq__(self, other: object) -> bool:
|
|
30
|
+
if not isinstance(other, FRectangle2d):
|
|
31
|
+
return False
|
|
32
|
+
return self._position == other._position and self._size == other._size
|
|
33
|
+
|
|
34
|
+
def overlaps(self, other: FVector2 | FRectangle2dOverlappable) -> bool:
|
|
35
|
+
if isinstance(other, FVector2):
|
|
36
|
+
return self.overlaps_f_vector_2(other)
|
|
37
|
+
try:
|
|
38
|
+
other_overlaps = other.overlaps_f_rectangle
|
|
39
|
+
except AttributeError:
|
|
40
|
+
raise TypeError(other)
|
|
41
|
+
return other_overlaps(self)
|
|
42
|
+
|
|
43
|
+
def overlaps_f_rectangle(self, other: FRectangle2d) -> bool:
|
|
44
|
+
return not (
|
|
45
|
+
self._position.x >= other._extent.x
|
|
46
|
+
or self._extent.x <= other._position.x
|
|
47
|
+
or self._position.y >= other._extent.y
|
|
48
|
+
or self._extent.y <= other._position.y
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def overlaps_f_vector_2(self, other: FVector2) -> bool:
|
|
52
|
+
return (
|
|
53
|
+
other.x >= self._position.x
|
|
54
|
+
and other.x < self._extent.x
|
|
55
|
+
and other.y >= self._position.y
|
|
56
|
+
and other.y < self._extent.y
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def bounding_box(self) -> FRectangle2d:
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def extent(self) -> FVector2:
|
|
65
|
+
return self._extent
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def position(self) -> FVector2:
|
|
69
|
+
return self._position
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def size(self) -> FVector2:
|
|
73
|
+
return self._size
|
egeometry/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: egeometry
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Python geometry library.
|
|
5
|
+
Author: Erik Soma
|
|
6
|
+
Author-email: stillusingirc@gmail.com
|
|
7
|
+
Requires-Python: >=3.12,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Requires-Dist: emath (>=0.1.12,<0.2.0)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
egeometry/__init__.py,sha256=SsclWI_qTz9ubAZkrAERpwPDohTEUJm16y622Yv3Z_c,417
|
|
2
|
+
egeometry/_drectangle2d.py,sha256=bfBv2pSqizKExcQeLBWVA1-PxXoM_IHxk1LVr99DTyw,2150
|
|
3
|
+
egeometry/_frectangle2d.py,sha256=9z-HQtmfi2GawVfdQRxB5NBpUHufDyNvhkv0FnXtA9U,2150
|
|
4
|
+
egeometry/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
egeometry-0.2.1.dist-info/METADATA,sha256=SsaEyfxcaBCEXXr_ttm1o-4KO7K_4iW1jjsBshX56Ag,310
|
|
6
|
+
egeometry-0.2.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
7
|
+
egeometry-0.2.1.dist-info/RECORD,,
|