def merge_gestures(self, g, other):
        '''Merges two gestures together, the oldest one is retained and the
        newer one gets the `GestureContainer.was_merged` flag raised.'''
        # Swap order depending on gesture age (the merged gesture gets
        # the color from the oldest one of the two).
        swap = other._create_time < g._create_time
        a = swap and other or g
        b = swap and g or other

        # Apply the outer limits of bbox to the merged gesture
        abbox = a.bbox
        bbbox = b.bbox
        if bbbox['minx'] < abbox['minx']:
            abbox['minx'] = bbbox['minx']
        if bbbox['miny'] < abbox['miny']:
            abbox['miny'] = bbbox['miny']
        if bbbox['maxx'] > abbox['maxx']:
            abbox['maxx'] = bbbox['maxx']
        if bbbox['maxy'] > abbox['maxy']:
            abbox['maxy'] = bbbox['maxy']

        # Now transfer the coordinates from old to new gesture;
        # FIXME: This can probably be copied more efficiently?
        astrokes = a._strokes
        lw = self.line_width
        a_id = a.id
        col = a.color

        self.canvas.remove_group(b.id)
        canv_add = self.canvas.add
        for uid, old in b._strokes.items():
            # FIXME: Can't figure out how to change group= for existing Line()
            new_line = Line(
                points=old.points,
                width=old.width,
                group=a_id)
            astrokes[uid] = new_line
            if lw:
                canv_add(Color(col[0], col[1], col[2], mode='rgb', group=a_id))
                canv_add(new_line)

        b.active = False
        b.was_merged = True
        a.active_strokes += b.active_strokes
        a._update_time = Clock.get_time()
        return a
dataset/ETHPy150Open kivy/kivy/kivy/uix/gesturesurface.py/GestureSurface.merge_gestures/original