Skip to content

Commit 439e410

Browse files
committed
fixed:only_linear argument was ignored in mirror
1 parent e0dacde commit 439e410

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

bbo/geometry.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def identity(shape: tuple | list | np.ndarray | numbers.Number | None = None):
603603
return RigidTransform(rotation=r, translation=np.zeros(shape=(*shape,3)))
604604

605605
@staticmethod
606-
def align_points(a:np.ndarray|list|dict, b:np.ndarray|list|dict, weights=None) -> (RigidTransform, float):
606+
def align_points(a:np.ndarray|list|dict, b:np.ndarray|list|dict, weights:None|np.ndarray|list|dict=None) -> (RigidTransform, float):
607607
"""
608608
Aligns two sets of points a and b using the Kabsch algorithm.
609609
:param a:
@@ -613,7 +613,6 @@ def align_points(a:np.ndarray|list|dict, b:np.ndarray|list|dict, weights=None) -
613613
"""
614614
if isinstance(a, dict) and isinstance(b, dict):
615615
common_keys = a.keys() & b.keys()
616-
print(a,b, common_keys)
617616
a = np.asarray([a[k] for k in common_keys])
618617
b = np.asarray([b[k] for k in common_keys])
619618
amean, bmean = np.average(a, weights=weights, axis=0, keepdims=True), np.average(b, weights=weights, axis=0, keepdims=True)
@@ -643,7 +642,6 @@ def to_dict(self):
643642
def apply(self, vec, only_linear=False):
644643
if isinstance(vec, Line):
645644
return Line(position=self.apply(vec.position), direction=self.apply(vec.direction, only_linear=True))
646-
647645
vec = apply_rot(self.rotation, vec)
648646
if not only_linear:
649647
vec += self.translation
@@ -1198,15 +1196,14 @@ def align_points(a:dict|list|np.ndarray, b:dict|list|np.ndarray, weights=None, k
11981196
bmean = np.average(b, weights=weights, axis=0, keepdims=True)
11991197
a0 = a - amean
12001198
b0 = b - bmean
1201-
1202-
rotation, rssd = Rotation.align_vectors(a0, b0, weights=weights)
1199+
bnorm = np.average(np.sum(b0 ** 2, axis=1), weights=weights)
1200+
prescale = np.sqrt(np.average(np.sum(a0 ** 2, axis=1), weights=weights) / bnorm)
1201+
rotation, rssd = Rotation.align_vectors(a0, b0 * prescale, weights=weights)
12031202

12041203
b0r = rotation.apply(b0)
12051204

12061205
num = np.average(np.sum(a0 * b0r, axis=1), weights=weights)
1207-
den = np.average(np.sum(b0r ** 2, axis=1), weights=weights)
1208-
1209-
scale = num / den
1206+
scale = num / bnorm
12101207

12111208
d = a.shape[1]
12121209
mat = np.eye(d + 1)
@@ -1336,15 +1333,17 @@ def apply_on_point(self, points):
13361333
res = np.dot(self.M, points.T).T + (self.normal * (self.tr * 2))[np.newaxis, :]
13371334
return res
13381335

1339-
def apply(self, points: np.ndarray|Line, only_linear=False):
1336+
def apply(self, points: np.ndarray|Line, only_linear=False) -> np.ndarray|Line:
13401337
if isinstance(points, Line):
13411338
return Line(direction=self.apply_on_vector(points.direction),
13421339
position=self.apply_on_point(points.position))
13431340
mirrored = np.dot(self.M, points.T).T
1341+
if only_linear:
1342+
return mirrored
13441343
translation = (self.normal * (self.tr * 2))
13451344
return mirrored + translation[tuple([slice(np.newaxis)] * (mirrored.ndim - translation.ndim))]
13461345

1347-
def apply_on_vector(self, vectors):
1346+
def apply_on_vector(self, vectors:np.ndarray) -> np.ndarray:
13481347
return np.dot(self.M, vectors.T).T
13491348

13501349
def __len__(self):

0 commit comments

Comments
 (0)