using System.Linq;
using OpenNest.Geometry;
namespace OpenNest.Desktop.Interaction;
///
/// The areas View > Zoom To fits, as the WinForms plate view's: Fit takes the plate with its
/// parts, Plate the sheet alone and Selected the selected parts.
///
public static class PlateZoom
{
/// Zoom To > Fit (and the F key): the plate and every part on it, or null.
public static Box FitArea(Plate plate) => plate?.BoundingBox(true);
/// Zoom To > Plate: the sheet without its parts, or null.
public static Box PlateArea(Plate plate) => plate?.BoundingBox(false);
///
/// Zoom To > Selected: the selected parts on the plate (cut-offs left out, as WinForms),
/// or null when no part is selected.
///
public static Box SelectedArea(Plate plate, PlateSelection selection)
{
if (plate == null || selection == null)
return null;
var parts = selection.Parts.Where(plate.Parts.Contains).ToList();
return parts.Count == 0 ? null : parts.GetBoundingBox();
}
}