|
|
@ -15,7 +15,7 @@ namespace ImageProcessor.Imaging.Helpers |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Provides reusable mathematical methods to apply to images.
|
|
|
/// Provides reusable mathematical methods to apply to images.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class ImageMaths |
|
|
public static class ImageMaths |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the bounding <see cref="Rectangle"/> from the given points.
|
|
|
/// Gets the bounding <see cref="Rectangle"/> from the given points.
|
|
|
@ -29,13 +29,13 @@ namespace ImageProcessor.Imaging.Helpers |
|
|
/// <returns>
|
|
|
/// <returns>
|
|
|
/// The bounding <see cref="Rectangle"/>.
|
|
|
/// The bounding <see cref="Rectangle"/>.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) |
|
|
public static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) |
|
|
{ |
|
|
{ |
|
|
return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); |
|
|
return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets a <see cref="Rectangle"/> centered within it's parent.
|
|
|
/// Gets a <see cref="Rectangle"/> representing the child centered relative to the parent.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="parent">
|
|
|
/// <param name="parent">
|
|
|
/// The parent <see cref="Rectangle"/>.
|
|
|
/// The parent <see cref="Rectangle"/>.
|
|
|
@ -46,17 +46,33 @@ namespace ImageProcessor.Imaging.Helpers |
|
|
/// <returns>
|
|
|
/// <returns>
|
|
|
/// The centered <see cref="Rectangle"/>.
|
|
|
/// The centered <see cref="Rectangle"/>.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public Rectangle CenteredRectangle(Rectangle parent, Rectangle child) |
|
|
public static RectangleF CenteredRectangle(Rectangle parent, Rectangle child) |
|
|
{ |
|
|
{ |
|
|
if (parent.Size.Width < child.Size.Width && parent.Size.Height < child.Size.Height) |
|
|
float x = (parent.Width - child.Width) / 2.0F; |
|
|
{ |
|
|
float y = (parent.Height - child.Height) / 2.0F; |
|
|
return parent; |
|
|
int width = child.Width; |
|
|
|
|
|
int height = child.Height; |
|
|
|
|
|
return new RectangleF(x, y, width, height); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int x = (parent.Width - child.Width) / 2; |
|
|
/// <summary>
|
|
|
int y = (parent.Height - child.Height) / 2; |
|
|
/// Returns the array of <see cref="Point"/> matching the bounds of the given rectangle.
|
|
|
|
|
|
/// </summary>
|
|
|
return new Rectangle(x, y, child.Width, child.Height); |
|
|
/// <param name="rectangle">
|
|
|
|
|
|
/// The <see cref="Rectangle"/> to return the points from.
|
|
|
|
|
|
/// </param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// The <see cref="Point"/> array.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public static Point[] ToPoints(Rectangle rectangle) |
|
|
|
|
|
{ |
|
|
|
|
|
return new[] |
|
|
|
|
|
{ |
|
|
|
|
|
new Point(rectangle.Left, rectangle.Top), |
|
|
|
|
|
new Point(rectangle.Right, rectangle.Top), |
|
|
|
|
|
new Point(rectangle.Right, rectangle.Bottom), |
|
|
|
|
|
new Point(rectangle.Left, rectangle.Bottom) |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|