code: private void computeSelection(Viewer viewer, Cursor cursor, SelectorModel model)
      {
          final double viewX = viewer.getX() + viewer.getViewX();
          final double viewY = viewer.getY() - viewer.getViewY();
          final double currentX = UtilMath.clamp(cursor.getX(), viewX, viewX + viewer.getWidth());
          final double currentY = UtilMath.clamp(cursor.getY(), viewY, viewY + viewer.getHeight());
  
          double selectX = startX;
          double selectY = startY;
  
          // Viewer Y axis is inverted compared to screen axis
          model.setSelectRawY(selectY);
          model.setSelectRawH(startY - currentY);
  
          double selectW = currentX - startX;
          if (selectW < 0)
          {
              selectX += selectW;
              selectW = -selectW;
          }
  
          double selectH = currentY - startY;
          if (selectH < 0)
          {
              selectY += selectH;
              selectH = -selectH;
          }
          model.getSelectionArea().set(selectX, selectY, selectW, selectH);
      }
docs: Compute the selection from cursor location.
  
  @param viewer The viewer reference.
  @param cursor The cursor reference.
  @param model The selector model.