Commit ebf7a3e5 authored by pacome's avatar pacome
Browse files

Clean the Rectangle.geometry function, Fix npt=-1 in case just on point given

parent d8985cf9
......@@ -527,66 +527,24 @@ class Rectangle(General):
It returns True if the point is within the shape defined
by the function or False otherwise
'''
if len(x.shape) == 1:
ndim, npt = x.shape[0], -1
x = x[None, :]
else:
npt, ndim = x.shape
assert (ndim == 2 or ndim == 3)
x = np.asanyarray(x)
if len(x.shape) > 1:
if len(self.length) == 3:
if self.center is None:
return ((self.corner[0] <= x[:, 0])
* (x[:, 0] <= self.corner[0] + self.length[0])
* (self.corner[1] <= x[:, 1])
* (x[:, 1] <= self.corner[1] + self.length[1])
* (self.corner[2] <= x[:, 2])
* (x[:, 2] <= self.corner[2] + self.length[2]))
else:
return ((self.center[0] - self.length[0]/2 <= x[:, 0])
* (x[:, 0] <= self.center[0] + self.length[0]/2)
* (self.center[1] - self.length[1]/2 <= x[:, 1])
* (x[:, 1] <= self.center[1] + self.length[1]/2)
* (self.center[2] - self.length[2]/2 <= x[:, 2])
* (x[:, 2] <= self.center[2] + self.length[2]/2))
else:
if self.center is None:
return ((self.corner[0] <= x[:, 0])
* (x[:, 0] <= self.corner[0] + self.length[0])
* (self.corner[1] <= x[:, 1])
* (x[:, 1] <= self.corner[1] + self.length[1]))
else:
return ((self.center[0] - self.length[0]/2 <= x[:, 0])
* (x[:, 0] <= self.center[0] + self.length[0]/2)
* (self.center[1] - self.length[1]/2 <= x[:, 1])
* (x[:, 1] <= self.center[1] + self.length[1]/2))
if self.center is None:
isin = np.all(x <= self.corner + self.length, axis=1) \
* np.all(x >= self.corner, axis=1)
else:
if len(self.length) == 3:
if self.center is None:
return ((self.corner[0] <= x[0]
<= self.corner[0] + self.length[0])
and (self.corner[1] <= x[1]
<= self.corner[1] + self.length[1])
and (self.corner[2] <= x[2]
<= self.corner[2] + self.length[2]))
else:
return ((self.center[0] - self.length[0]/2 <= x[0]
<= self.center[0] + self.length[0]/2)
and (self.center[1] - self.length[0]/2 <= x[1]
<= self.center[1] + self.length[1]/2)
and (self.center[2] - self.length[0]/2 <= x[2]
<= self.center[2] + self.length[2]/2))
isin = np.all(x <= self.center + self.length/2, axis=1) \
* np.all(x >= self.center - self.length/2, axis=1)
else:
if self.center is None:
return ((self.corner[0] <= x[0]
<= self.corner[0] + self.length[0])
and (self.corner[1] <= x[1]
<= self.corner[1] + self.length[1]))
else:
return ((self.center[0] - self.length[0]/2 <= x[0]
<= self.center[0] + self.length[0]/2)
and (self.center[1] - self.length[0]/2 <= x[1]
<= self.center[1] + self.length[1]/2))
if npt is -1:
return isin[0]
else:
return isin
class Ellipsoid(General):
'''
......@@ -898,8 +856,7 @@ def rotate(x, angle, axis=None, center='self'):
if len(x.shape) == 2:
npt, ndim = x.shape
elif len(x.shape) == 1:
npt, ndim = 0, x.shape[0]
print(x.shape)
npt, ndim = -1, x.shape[0]
x = x[None, :]
else: raise ValueError
......@@ -925,7 +882,7 @@ def rotate(x, angle, axis=None, center='self'):
np.repeat([rot_mat], len(x), axis=0), x - center_mat)
+ center_mat)
if npt is 0:
if npt is -1:
return ret[0]
else:
return ret
......@@ -948,7 +905,7 @@ def reflect(x, axis):
'''
x = np.asarray(x)
if len(x.shape) == 1:
ndim, npt = x.shape[0], 1
ndim, npt = x.shape[0], -1
x = x[None, :]
else:
npt, ndim = x.shape
......@@ -978,7 +935,7 @@ def reflect(x, axis):
Matinv = np.linalg.inv(Mat)
transf = Mat.T @ mirror @ Matinv.T
ret = np.einsum('kij, kj -> ki', np.repeat([transf], len(x), axis=0), (x - Amat)) + Amat
if npt is 0:
if npt is -1:
return ret[0]
else:
return ret
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment