예제 #1
0
    public static void Rotate(IEnumerable <BaseShapeViewModel> shapes, decimal angle, IHistory?history)
    {
        var groupBox = new GroupBox(shapes.ToList());

        if (groupBox.Boxes.Length <= 0)
        {
            return;
        }

        var boxes = groupBox.Boxes.ToList();

        var previous = new List <(PointShapeViewModel point, decimal x, decimal y)>();
        var next     = new List <(PointShapeViewModel point, decimal x, decimal y)>();

        var radians = angle * (decimal)Math.PI / 180m;
        var centerX = groupBox.Bounds.CenterX;
        var centerY = groupBox.Bounds.CenterY;

        foreach (var point in boxes.SelectMany(box => box.Points).Distinct())
        {
            PointUtil.Rotate(point, radians, centerX, centerY, out var x, out var y);
            previous.Add((point, (decimal)point.X, (decimal)point.Y));
            next.Add((point, x, y));
            point.X = (double)x;
            point.Y = (double)y;
        }

        history?.Snapshot(previous, next, (p) => previous.ForEach(p =>
        {
            p.point.X = (double)p.x;
            p.point.Y = (double)p.y;
        }));
    }