hitTestSelection method

EntitySelectionHit? hitTestSelection(
  1. Offset sourcePoint, {
  2. required double cameraScale,
})

The chrome region of the selected entity under sourcePoint, or null when nothing is selected or the point misses. Outset and handle targets are screen points divided by cameraScale — the product of the viewer and host camera scales — so they cover a constant on-screen area at any zoom.

Implementation

EntitySelectionHit? hitTestSelection(
  Offset sourcePoint, {
  required double cameraScale,
}) {
  final entity = selectedEntity;
  if (entity == null) return null;

  final bounds = _bounds(entity);
  final local = _toEntityLocal(entity, sourcePoint);
  final handle = entitySelectionViewHandleSize / cameraScale;
  Rect handleAt(double x) =>
      Rect.fromCenter(center: Offset(x, 0), width: handle, height: handle);

  if (handleAt(bounds.left).contains(local)) {
    return EntitySelectionHit.leftHandle;
  }
  if (handleAt(bounds.right).contains(local)) {
    return EntitySelectionHit.rightHandle;
  }
  if (bounds
      .inflate(entitySelectionFrameOutset / cameraScale)
      .contains(local)) {
    return EntitySelectionHit.frame;
  }
  return null;
}