Skip to content

Commit 04f2cf3

Browse files
committed
enh: enabled tolerance for Shapes as argument
Signed-off-by: Nick Papior <[email protected]>
1 parent e605a26 commit 04f2cf3

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

sisl/shape/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def toCuboid(self):
8383
""" Create a cuboid which is surely encompassing the *full* shape """
8484
return self.toEllipsoid().toCuboid()
8585

86-
def within(self, other):
86+
def within(self, other, *args, **kwargs):
8787
""" Return ``True`` if `other` is fully within `self`
8888
8989
If `other` is an array, an array will be returned for each of these.
@@ -92,20 +92,24 @@ def within(self, other):
9292
----------
9393
other : array_like
9494
the array/object that is checked for containment
95+
*args :
96+
passed directly to `within_index`
97+
**kwargs :
98+
passed directly to `within_index`
9599
"""
96100
other = _a.asarrayd(other)
97101
ndim = other.ndim
98102
other.shape = (-1, 3)
99103

100-
idx = self.within_index(other)
104+
idx = self.within_index(other, *args, **kwargs)
101105
# Initialize a boolean array with all false
102106
within = np.zeros(len(other), dtype=bool)
103107
within[idx] = True
104108
if ndim == 1 and other.size == 3:
105109
return within[0]
106110
return within
107111

108-
def within_index(self, other):
112+
def within_index(self, other, *args, **kwargs):
109113
""" Return indices of the elements of `other` that are within the shape """
110114
raise NotImplementedError('within_index has not been implemented in: '+self.__class__.__name__)
111115

@@ -303,7 +307,7 @@ def __init__(self, *args, **kwargs):
303307
M = np.finfo(np.float64).max / 100
304308
self._center = np.array([M, M, M], np.float64)
305309

306-
def within_index(self, other):
310+
def within_index(self, other), *args, **kwargs:
307311
""" Always returns a zero length array """
308312
return np.empty(0, dtype=np.int32)
309313

sisl/shape/ellipsoid.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,21 @@ def set_center(self, center):
123123
""" Change the center of the object """
124124
super().__init__(center)
125125

126-
def within_index(self, other):
127-
""" Return indices of the points that are within the shape """
126+
def within_index(self, other, tol=1.e-12):
127+
r""" Return indices of the points that are within the shape
128+
129+
Parameters
130+
----------
131+
other : array_like
132+
the object that is checked for containment
133+
tol : float, optional
134+
absolute tolerance for boundaries
135+
"""
128136
other = _a.asarrayd(other)
129137
other.shape = (-1, 3)
130138

131139
# First check
132140
tmp = dot(other - self.center[None, :], self._iv)
133-
tol = 1.e-12
134141

135142
# Get indices where we should do the more
136143
# expensive exact check of being inside shape

sisl/shape/prism4.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,20 @@ def toCuboid(self):
115115
""" Return a copy of itself """
116116
return self.copy()
117117

118-
def within_index(self, other):
118+
def within_index(self, other, tol=1.e-12):
119119
""" Return indices of the `other` object which are contained in the shape
120120
121121
Parameters
122122
----------
123123
other : array_like
124124
the object that is checked for containment
125+
tol : float, optional
126+
absolute tolerance for boundaries
125127
"""
126128
other = _a.asarrayd(other).reshape(-1, 3)
127129

128130
# Offset origo
129131
tmp = dot(other - self.origo[None, :], self._iv)
130-
tol = 1.e-12
131132

132133
# First reject those that are definitely not inside
133134
# The proximity is 1e-12 of the inverse cell.

0 commit comments

Comments
 (0)