Skip to content

Commit 5b2769b

Browse files
committed
Merge pull request kivy#1797 from matham/scatter-fix
Fix scatter issues
2 parents a5b3954 + 3bc2c2d commit 5b2769b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

kivy/uix/scatter.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,29 @@ def transform_with_touch(self, touch):
415415
if len(self._touches) == 1:
416416
return changed
417417

418-
# we have more than one touch...
419-
points = [Vector(self._last_touch_pos[t]) for t in self._touches]
418+
# we have more than one touch... list of last known pos
419+
points = [Vector(self._last_touch_pos[t]) for t in self._touches
420+
if t is not touch]
421+
# add current touch last
422+
points.append(Vector(touch.pos))
420423

421424
# we only want to transform if the touch is part of the two touches
422-
# furthest apart! So first we find anchor, the point to transform
423-
# around as the touch farthest away from touch
424-
anchor = max(points, key=lambda p: p.distance(touch.pos))
425+
# farthest apart! So first we find anchor, the point to transform
426+
# around as another touch farthest away from current touch's pos
427+
anchor = max(points[:-1], key=lambda p: p.distance(touch.pos))
425428

426429
# now we find the touch farthest away from anchor, if its not the
427430
# same as touch. Touch is not one of the two touches used to transform
428431
farthest = max(points, key=anchor.distance)
429-
if points.index(farthest) != self._touches.index(touch):
432+
if farthest is not points[-1]:
430433
return changed
431434

432435
# ok, so we have touch, and anchor, so we can actually compute the
433436
# transformation
434437
old_line = Vector(*touch.ppos) - anchor
435438
new_line = Vector(*touch.pos) - anchor
439+
if not old_line.length(): # div by zero
440+
return changed
436441

437442
angle = radians(new_line.angle(old_line)) * self.do_rotation
438443
self.apply_transform(Matrix().rotate(angle, 0, 0, 1), anchor=anchor)

0 commit comments

Comments
 (0)