/// <summary> /// Checks that drawed point or line in layer bounds, /// if not increase bounds to contains drawing /// </summary> /// <param name="points">Points of drawing</param> private void CheckLayerPostionAndSize(Point[] points) { if (HasNoLayers) { return; } var needToChangeSize = false; var halfThickness = Thickness / 2; var minX = points.Min(c => c.X) - halfThickness; var minY = points.Min(c => c.Y) - halfThickness; var maxX = points.Max(c => c.X) + halfThickness; var maxY = points.Max(c => c.Y) + halfThickness; var newPosition = SelectedLayer.Position; var newSize = SelectedLayer.Size; if (minX < SelectedLayer.Position.X) { newPosition.X = minX; needToChangeSize = true; } if (minY < SelectedLayer.Position.Y) { newPosition.Y = minY; needToChangeSize = true; } if (maxX >= SelectedLayer.Position.X + SelectedLayer.Size.Width) { newSize.Width = maxX - newPosition.X; needToChangeSize = true; } if (maxY >= SelectedLayer.Position.Y + SelectedLayer.Size.Height) { newSize.Height = maxY - newPosition.Y; needToChangeSize = true; } if (needToChangeSize) { var dx = SelectedLayer.Position.X - newPosition.X; var dy = SelectedLayer.Position.Y - newPosition.Y; newSize.Width += dx; newSize.Height += dy; SelectedLayer.ChangeSizeAndPosition(newPosition, newSize); } }