isValidDropPosition method

bool isValidDropPosition({
  1. required Offset position,
  2. required Map<String, Offset> existingPositions,
  3. required Size nodeSize,
  4. String? excludeNodeId,
})

Check if a position is valid for dropping (e.g., not overlapping)

Implementation

bool isValidDropPosition({
  required Offset position,
  required Map<String, Offset> existingPositions,
  required Size nodeSize,
  String? excludeNodeId,
}) {
  final dragRect = Rect.fromLTWH(
    position.dx,
    position.dy,
    nodeSize.width,
    nodeSize.height,
  );

  // Check for overlaps with existing nodes
  for (final entry in existingPositions.entries) {
    if (entry.key == excludeNodeId) continue;

    final existingRect = Rect.fromLTWH(
      entry.value.dx,
      entry.value.dy,
      nodeSize.width,
      nodeSize.height,
    );

    if (dragRect.overlaps(existingRect)) {
      return false;
    }
  }

  return true;
}