12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Drawing;
- using System.Text;
- using System.Threading.Tasks;
- namespace bbiwarg.Utility
- {
- /// <summary>
- /// Manages the size of a image.
- /// </summary>
- public class ImageSize
- {
- /// <summary>
- /// image width
- /// </summary>
- public int Width {get; private set;}
- /// <summary>
- /// image height
- /// </summary>
- public int Height {get; private set;}
- /// <summary>
- /// position in the image with maximum x and y values
- /// </summary>
- public Vector2D MaxPixel {get; private set;}
- /// <summary>
- /// the length of the longer image diagonal
- /// </summary>
- public float DiagonalLength { get { return MaxPixel.Length; } }
- /// <summary>
- /// number of pixels in the image
- /// </summary>
- public int NumPixels { get { return Width * Height; } }
- /// <summary>
- /// Constructs a ImageSize.
- /// </summary>
- /// <param name="width">image width</param>
- /// <param name="height">image height</param>
- public ImageSize(int width, int height) {
- Width = width;
- Height = height;
- MaxPixel = new Vector2D(width - 1, height - 1);
- }
- /// <summary>
- /// Computes an absolute point in the image.
- /// </summary>
- /// <param name="relativePoint">realtive point (x and y in [0,1])</param>
- /// <returns>absolute point</returns>
- public Vector2D getAbsolutePoint(Vector2D relativePoint) {
- return relativePoint.scale(MaxPixel);
- }
- /// <summary>
- /// Computes a relative point in the image.
- /// </summary>
- /// <param name="absolutePoint">absolute point in the image</param>
- /// <returns>realtive point (x and y in [0,1])</returns>
- public Vector2D getRelativePoint(Vector2D absolutePoint) {
- return new Vector2D(absolutePoint.X / Width, absolutePoint.Y / Height);
- }
- }
- }
|