PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. namespace Microsoft.Research.DynamicDataDisplay.DataSources.MultiDimensional
  7. {
  8. public static class DataSource2DHelper
  9. {
  10. public static Point[,] CreateUniformGrid(int width, int height, double gridWidth, double gridHeight)
  11. {
  12. return CreateUniformGrid(width, height, 0, 0, gridWidth / width, gridHeight / height);
  13. }
  14. public static Point[,] CreateUniformGrid(int width, int height, double xStart, double yStart, double xStep, double yStep)
  15. {
  16. Point[,] result = new Point[width, height];
  17. double x = xStart;
  18. for (int ix = 0; ix < width; ix++)
  19. {
  20. double y = yStart;
  21. for (int iy = 0; iy < height; iy++)
  22. {
  23. result[ix, iy] = new Point(x, y);
  24. y += yStep;
  25. }
  26. x += xStep;
  27. }
  28. return result;
  29. }
  30. public static Vector[,] CreateVectorData(int width, int height, Func<int, int, Vector> generator)
  31. {
  32. Vector[,] result = new Vector[width, height];
  33. for (int ix = 0; ix < width; ix++)
  34. {
  35. for (int iy = 0; iy < height; iy++)
  36. {
  37. result[ix, iy] = generator(ix, iy);
  38. }
  39. }
  40. return result;
  41. }
  42. }
  43. }