PageRenderTime 13ms CodeModel.GetById 3ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/DataSources/MultiDimensional/DataSource2DHelper.cs

#
C# | 51 lines | 43 code | 8 blank | 0 comment | 4 complexity | 6bfa30c145de2028dbc48e01c5ae6e8a MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Windows;
 6
 7namespace Microsoft.Research.DynamicDataDisplay.DataSources.MultiDimensional
 8{
 9	public static class DataSource2DHelper
10	{
11		public static Point[,] CreateUniformGrid(int width, int height, double gridWidth, double gridHeight)
12		{
13			return CreateUniformGrid(width, height, 0, 0, gridWidth / width, gridHeight / height);
14		}
15
16		public static Point[,] CreateUniformGrid(int width, int height, double xStart, double yStart, double xStep, double yStep)
17		{
18			Point[,] result = new Point[width, height];
19
20			double x = xStart;
21			for (int ix = 0; ix < width; ix++)
22			{
23				double y = yStart;
24				for (int iy = 0; iy < height; iy++)
25				{
26					result[ix, iy] = new Point(x, y);
27
28					y += yStep;
29				}
30				x += xStep;
31			}
32
33			return result;
34		}
35
36		public static Vector[,] CreateVectorData(int width, int height, Func<int, int, Vector> generator)
37		{
38			Vector[,] result = new Vector[width, height];
39
40			for (int ix = 0; ix < width; ix++)
41			{
42				for (int iy = 0; iy < height; iy++)
43				{
44					result[ix, iy] = generator(ix, iy);
45				}
46			}
47
48			return result;
49		}
50	}
51}