RoomPlanScanQuality.fromScan constructor

RoomPlanScanQuality.fromScan(
  1. ScanResult scan
)

Builds user-facing suggestions from the scan's detected geometry.

Implementation

factory RoomPlanScanQuality.fromScan(ScanResult scan) {
  final room = scan.room;
  final confidences = <Confidence>[
    ...room.walls.map((item) => item.confidence),
    ...room.objects.map((item) => item.confidence),
    ...room.doors.map((item) => item.confidence),
    ...room.windows.map((item) => item.confidence),
    ...room.openings.map((item) => item.confidence),
  ];
  final lowCount = confidences.where((value) => value == Confidence.low).length;
  final tips = <String>[];

  if (room.walls.isEmpty) {
    tips.add('No walls were detected. Scan again and keep the room boundaries in view.');
  } else if (room.walls.length < 3) {
    tips.add('Few walls were detected. Review the outline and scan any missing sides again.');
  }

  if (confidences.isNotEmpty && lowCount / confidences.length >= 0.3) {
    tips.add('Several detections have low confidence. Review the plan and rescan unclear areas.');
  } else if (lowCount > 0) {
    tips.add('Some detections have low confidence. Check those details before relying on them.');
  }

  if (tips.isEmpty) {
    tips.add('Review the plan for missed details and verify critical measurements on site.');
  }

  return RoomPlanScanQuality(
    wallCount: room.walls.length,
    elementCount: confidences.length,
    lowConfidenceCount: lowCount,
    suggestions: List.unmodifiable(tips),
  );
}