-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathOperationsExtensions.cs
50 lines (42 loc) · 1.44 KB
/
OperationsExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections.Generic;
using System.Windows;
namespace Nodify.Calculator
{
public static class OperationsExtensions
{
public static Rect GetBoundingBox(this IEnumerable<OperationViewModel> nodes, double padding = 0, int gridCellSize = 15)
{
var minX = double.MaxValue;
var minY = double.MaxValue;
var maxX = double.MinValue;
var maxY = double.MinValue;
const int width = 200; //node.Width
const int height = 100; //node.Height
foreach (var node in nodes)
{
if (node.Location.X < minX)
{
minX = node.Location.X;
}
if (node.Location.Y < minY)
{
minY = node.Location.Y;
}
var sizeX = node.Location.X + width;
if (sizeX > maxX)
{
maxX = sizeX;
}
var sizeY = node.Location.Y + height;
if (sizeY > maxY)
{
maxY = sizeY;
}
}
var result = new Rect(minX - padding, minY - padding, maxX - minX + padding * 2, maxY - minY + padding * 2);
result.X = (int)result.X / gridCellSize * gridCellSize;
result.Y = (int)result.Y / gridCellSize * gridCellSize;
return result;
}
}
}