def METHOD_NAME(self, layer, event):
    pos = self._get_mouse_coordinates(event)
    dims_displayed = self._dims_displayed
    if event.button == 1:  # left mouse click
        orig_pos = pos.copy()
        # recenter the point in the center of the image pixel
        pos[dims_displayed] = np.floor(pos[dims_displayed]) + 0.5
        if not self.overlay.points:
            self._first_point_pos = np.array(event.pos)
        prev_point = (
            self.overlay.points[-2] if self._num_points > 1 else None
        )
        # Add a new point only if it differs from the previous one
        if prev_point is None or np.linalg.norm(pos - prev_point) > 0:
            self.overlay.points = self.overlay.points[:-1] + [
                pos.tolist(),
                # add some epsilon to avoid points duplication,
                # the latest point is used only for visualization of the cursor
                (orig_pos + 1e-3).tolist(),
            ]
    elif event.button == 2 and self._num_points > 0:  # right mouse click
        if self._num_points < 3:
            self.overlay.points = []
        else:
            self.overlay.points = self.overlay.points[:-2] + [pos.tolist()]