def snap_image(self, coordinate_name):
        """Snap image by align it with the moving area."""
        rect = self.rect

        current_pos = getattr(rect, coordinate_name)

        pos = getattr(MOVE_AREA, coordinate_name)

        dx, dy = pos - Vector2(current_pos)

        if rect.width <= MOVE_AREA.width:
            dx = 0

        else:

            if dx < 0:
                dx = max(dx, MOVE_AREA.right - rect.right)

            elif dx > 0:
                dx = min(dx, MOVE_AREA.left - rect.left)

        if rect.height <= MOVE_AREA.height:
            dy = 0

        else:

            if dy < 0:
                dy = max(dy, MOVE_AREA.bottom - rect.bottom)

            elif dy > 0:
                dy = min(dy, MOVE_AREA.top - rect.top)

        if dx or dy:
            rect.move_ip(dx, dy)
        else:
            return

        self.response_draw()
Snap image by align it with the moving area.
nodezator/surfsman/viewer/op.py