namespace OpenNest.Desktop; /// /// The Edit Plate dialog's quadrant picker: a square split in four, the plate origin's /// quadrant numbered as on a graph (1 upper right, 2 upper left, 3 lower left, 4 lower right). /// Coordinates are the control's, y growing down. /// public static class QuadrantPick { /// when it is 1 to 4, otherwise 1, as the picker accepts it. public static int Normalize(int value) => value is >= 1 and <= 4 ? value : 1; /// The quadrant a click at (, ) picks. public static int At(double x, double y, double width, double height) { var left = x < width / 2; var top = y < height / 2; return left ? (top ? 2 : 3) : (top ? 1 : 4); } /// /// The highlighted cell of : its left and top edges and size, /// in the control's coordinates. /// public static (double X, double Y, double Width, double Height) Cell(int quadrant, double width, double height) { var midX = width / 2; var midY = height / 2; return Normalize(quadrant) switch { 1 => (midX, 0, width - midX, midY), 2 => (0, 0, midX, midY), 3 => (0, midY, midX, height - midY), _ => (midX, midY, width - midX, height - midY), }; } }