selectElementAtPoint<T extends PCanvasElement> method

List<T> selectElementAtPoint<T extends PCanvasElement>(
  1. Point point, {
  2. bool recursive = false,
})

Implementation

List<T> selectElementAtPoint<T extends PCanvasElement>(Point point,
    {bool recursive = false}) {
  var elements = this.elements;

  var sel = elements
      .whereType<T>()
      .where((e) => e.boundingBox.containsPoint(point))
      .toList();

  if (!recursive || sel.isEmpty) {
    return sel;
  }

  var subList = sel.whereType<PCanvasElementContainer>().expand((e) {
    var b = e.boundingBox;
    var p = Point(point.x - b.x, point.y - b.y);
    return e.selectElementAtPoint<T>(p, recursive: true);
  }).toList();

  return [...sel, ...subList];
}