private void RebuildUI() { if (DataSource == null) { //todo: clear return; } panel.Children.Clear(); int width = DataSource.Width; int height = DataSource.Height; bounds = DataSource.Grid.GetGridBounds(); fieldWrapper = new UniformFieldWrapper(DataSource.Data, width, height); List<Point[]> tracks = new List<Point[]>(pointsNum); for (int i = 0; i < pointsNum; i++) { var track = new List<Point>(); var start = rnd.NextPoint(bounds.XMin, bounds.XMax, bounds.YMin, bounds.YMax); track.Add(start); int maxLength = Math.Max(width, height); var position = start; double length = 0; do { var K1 = fieldWrapper.GetVector(position); K1.Normalize(); //var shift = K1; var K2 = fieldWrapper.GetVector(position + (K1 / 2).DecreaseLength(width, height)); K2.Normalize(); var K3 = fieldWrapper.GetVector(position + (K2 / 2).DecreaseLength(width, height)); K3.Normalize(); var K4 = fieldWrapper.GetVector(position + K3.DecreaseLength(width, height)); K4.Normalize(); var shift = ((K1 + 2 * K2 + 2 * K3 + K4) / 6); //shift.Normalize(); if (shift.X.IsNaN() || shift.Y.IsNaN()) break; var next = position + shift; track.Add(next); if (!OccupyCells(position, next, bounds)) break; position = next; length += shift.Length; } while (length < maxLength); Polyline line = new Polyline { Stroke = Brushes.Orange, StrokeThickness = 1, Stretch = Stretch.Fill, Points = new PointCollection(track), Effect = new DropShadowEffect { Color = Colors.Black, Direction = 245, BlurRadius = 3 } }; ViewportPanel.SetViewportBounds(line, track.GetBounds()); panel.Children.Add(line); } }
private void RebuildUI() { if (DataSource == null) { //todo: clear return; } panel.Children.Clear(); int width = DataSource.Width; int height = DataSource.Height; bounds = DataSource.Grid.GetGridBounds(); fieldWrapper = new UniformFieldWrapper(DataSource.Data, width, height); List <Point[]> tracks = new List <Point[]>(pointsNum); for (int i = 0; i < pointsNum; i++) { var track = new List <Point>(); var start = rnd.NextPoint(bounds.XMin, bounds.XMax, bounds.YMin, bounds.YMax); track.Add(start); int maxLength = Math.Max(width, height); var position = start; double length = 0; do { var K1 = fieldWrapper.GetVector(position); K1.Normalize(); //var shift = K1; var K2 = fieldWrapper.GetVector(position + (K1 / 2).DecreaseLength(width, height)); K2.Normalize(); var K3 = fieldWrapper.GetVector(position + (K2 / 2).DecreaseLength(width, height)); K3.Normalize(); var K4 = fieldWrapper.GetVector(position + K3.DecreaseLength(width, height)); K4.Normalize(); var shift = ((K1 + 2 * K2 + 2 * K3 + K4) / 6); //shift.Normalize(); if (shift.X.IsNaN() || shift.Y.IsNaN()) { break; } var next = position + shift; track.Add(next); if (!OccupyCells(position, next, bounds)) { break; } position = next; length += shift.Length; } while (length < maxLength); Polyline line = new Polyline { Stroke = Brushes.Orange, StrokeThickness = 1, Stretch = Stretch.Fill, Points = new PointCollection(track), Effect = new DropShadowEffect { Color = Colors.Black, Direction = 245, BlurRadius = 3 } }; ViewportPanel.SetViewportBounds(line, track.GetBounds()); panel.Children.Add(line); } }