ImageSize.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. namespace BBIWARG.Utility
  2. {
  3. /// <summary>
  4. /// Manages the size of a image.
  5. /// </summary>
  6. public class ImageSize
  7. {
  8. /// <summary>
  9. /// the length of the longer image diagonal
  10. /// </summary>
  11. public float DiagonalLength { get { return MaxPixel.Length; } }
  12. /// <summary>
  13. /// image height
  14. /// </summary>
  15. public int Height { get; private set; }
  16. /// <summary>
  17. /// position in the image with maximum x and y values
  18. /// </summary>
  19. public Vector2D MaxPixel { get; private set; }
  20. /// <summary>
  21. /// number of pixels in the image
  22. /// </summary>
  23. public int NumPixels { get { return Width * Height; } }
  24. /// <summary>
  25. /// image width
  26. /// </summary>
  27. public int Width { get; private set; }
  28. /// <summary>
  29. /// Constructs a ImageSize.
  30. /// </summary>
  31. /// <param name="width">image width</param>
  32. /// <param name="height">image height</param>
  33. public ImageSize(int width, int height)
  34. {
  35. Width = width;
  36. Height = height;
  37. MaxPixel = new Vector2D(width - 1, height - 1);
  38. }
  39. /// <summary>
  40. /// Computes an absolute point in the image.
  41. /// </summary>
  42. /// <param name="relativePoint">relative point (x and y in [0,1])</param>
  43. /// <returns>absolute point</returns>
  44. public Vector2D getAbsolutePoint(Vector2D relativePoint)
  45. {
  46. return relativePoint.scale(MaxPixel);
  47. }
  48. /// <summary>
  49. /// Computes a relative point in the image.
  50. /// </summary>
  51. /// <param name="absolutePoint">absolute point in the image</param>
  52. /// <returns>relative point (x and y in [0,1])</returns>
  53. public Vector2D getRelativePoint(Vector2D absolutePoint)
  54. {
  55. return new Vector2D(absolutePoint.X / Width, absolutePoint.Y / Height);
  56. }
  57. }
  58. }