Added tons of xml-comments.

This commit is contained in:
DarthAffe committed 2015-10-17 16:57:50 +02:00
1 parent 57ad0f30e2
commit 6de1087c1f
23 files changed
+422 -51

No files matched your search

+56
View File
@@ -5,32 +5,64 @@ using System.Drawing;
namespace CUE.NET.Helper
{
/// <summary>
/// Offers some extensions and helper-methods for color related things.
/// </summary>
public static class ColorHelper
{
#region byte/float conversion
/// <summary>
/// Converts the alpha-value of the <see cref="Color"/> to an float value int the range [0..1].
/// </summary>
/// <param name="color">The color to take the alpha-value from.</param>
/// <returns>The float-value in the range of [0..1]</returns>
public static float GetFloatA(this Color color)
{
return color.A / 255f;
}
/// <summary>
/// Converts the red-value of the <see cref="Color"/> to an float value int the range [0..1].
/// </summary>
/// <param name="color">The color to take the red-value from.</param>
/// <returns>The float-value in the range of [0..1]</returns>
public static float GetFloatR(this Color color)
{
return color.R / 255f;
}
/// <summary>
/// Converts the green-value of the <see cref="Color"/> to an float value int the range [0..1].
/// </summary>
/// <param name="color">The color to take the green-value from.</param>
/// <returns>The float-value in the range of [0..1]</returns>
public static float GetFloatG(this Color color)
{
return color.G / 255f;
}
/// <summary>
/// Converts the blue-value of the <see cref="Color"/> to an float value int the range [0..1].
/// </summary>
/// <param name="color">The color to take the blue-value from.</param>
/// <returns>The float-value in the range of [0..1]</returns>
public static float GetFloatB(this Color color)
{
return color.B / 255f;
}
/// <summary>
/// Creates a <see cref="Color"/> object from the respective rgb-float-values in the range [0..1].
/// </summary>
/// <param name="a">The alpha-value in the range [0..1].</param>
/// <param name="r">The red-value in the range [0..1].</param>
/// <param name="g">The green-value in the range [0..1].</param>
/// <param name="b">The blue-value in the range [0..1].</param>
/// <returns>The color-object created representing the given values.</returns>
public static Color CreateColorFromFloat(float a, float r, float g, float b)
{
// ReSharper disable once ExceptionNotDocumentedOptional
return Color.FromArgb(GetIntColorFromFloat(a), GetIntColorFromFloat(r), GetIntColorFromFloat(g), GetIntColorFromFloat(b));
}
@@ -45,6 +77,12 @@ namespace CUE.NET.Helper
#region Blending
/// <summary>
/// Blends two colors.
/// </summary>
/// <param name="bg">The background-color.</param>
/// <param name="fg">The foreground-color</param>
/// <returns>The resulting color.</returns>
public static Color Blend(this Color bg, Color fg)
{
if (fg.A == 255)
@@ -65,6 +103,11 @@ namespace CUE.NET.Helper
#region RGB/HSV conversion
// https://en.wikipedia.org/wiki/HSL_and_HSV
/// <summary>
/// Gets the saturation-value (HSV-color space) of the color.
/// </summary>
/// <param name="color">The color to take the saturation from.</param>
/// <returns>The saturation-value (HSV-color space) of the color.</returns>
public static float GetHSVSaturation(this Color color)
{
int max = Math.Max(color.R, Math.Max(color.G, color.B));
@@ -75,12 +118,25 @@ namespace CUE.NET.Helper
// ReSharper restore RedundantCast
}
/// <summary>
/// Gets the value-value (HSV-color space) of the color.
/// </summary>
/// <param name="color">The color to take the value from.</param>
/// <returns>The value-value (HSV-color space) of the color.</returns>
public static float GetHSVValue(this Color color)
{
return Math.Max(color.R, Math.Max(color.G, color.B)) / 255f;
}
// Based on http://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both/6930407#6930407 as of 27.09.2015
/// <summary>
/// Creates a <see cref="Color"/> object from the respective hsv-float-values in the range [0..1].
/// </summary>
/// <param name="hue">The hue of the color.</param>
/// <param name="saturation">The saturation of the color.</param>
/// <param name="value">The value of the color.</param>
/// <param name="alpha">The alpha of the color.</param>
/// <returns>The color-object created representing the given values.</returns>
public static Color ColorFromHSV(float hue, float saturation, float value, byte alpha = 255)
{
if (saturation <= 0.0)
+22 -2
View File
@@ -5,9 +5,19 @@ using System.Drawing;
namespace CUE.NET.Helper
{
/// <summary>
/// Offers some extensions and helper-methods for gradient related things.
/// </summary>
public static class GradientHelper
{
// Based on https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/
/// <summary>
/// Calculates the offset of an given point on an gradient.
/// </summary>
/// <param name="startPoint">The start point of the gradient.</param>
/// <param name="endPoint">The end point of the gradient.</param>
/// <param name="point">The point on the gradient to which the offset is calculated.</param>
/// <returns>The offset of the point on the gradient.</returns>
public static float CalculateLinearGradientOffset(PointF startPoint, PointF endPoint, PointF point)
{
PointF intersectingPoint;
@@ -17,7 +27,7 @@ namespace CUE.NET.Helper
else if (startPoint.X.Equals(endPoint.X)) // Vertical case
intersectingPoint = new PointF(startPoint.X, point.Y);
else // Diagnonal case
else // Diagonal case
{
float slope = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X);
float orthogonalSlope = -1 / slope;
@@ -39,8 +49,12 @@ namespace CUE.NET.Helper
// Based on https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/
/// <summary>
/// Returns the signed magnitude of a point on a vector
/// Returns the signed magnitude of a point on a vector.
/// </summary>
/// <param name="point">The point on the vector of which the magnitude should be calculated.</param>
/// <param name="origin">The origin of the vector.</param>
/// <param name="direction">The direction of the vector.</param>
/// <returns>The signed magnitude of a point on a vector.</returns>
public static float CalculateDistance(PointF point, PointF origin, PointF direction)
{
float distance = CalculateDistance(point, origin);
@@ -52,6 +66,12 @@ namespace CUE.NET.Helper
? -distance : distance;
}
/// <summary>
/// Calculated the distance between two points.
/// </summary>
/// <param name="point1">The first point.</param>
/// <param name="point2">The second point.</param>
/// <returns>The distance between the two points.</returns>
public static float CalculateDistance(PointF point1, PointF point2)
{
return (float)Math.Sqrt((point1.Y - point2.Y) * (point1.Y - point2.Y) + (point1.X - point2.X) * (point1.X - point2.X));
+36 -5
View File
@@ -4,13 +4,27 @@ using System.Drawing;
namespace CUE.NET.Helper
{
/// <summary>
/// Offers some extensions and helper-methods for rectangle related things.
/// </summary>
public static class RectangleHelper
{
/// <summary>
/// Calculates the center-point of a rectangle.
/// </summary>
/// <param name="rectangle">The rectangle.</param>
/// <returns>The center point of the rectangle.</returns>
public static PointF GetCenter(this RectangleF rectangle)
{
return new PointF(rectangle.Left + rectangle.Width / 2f, rectangle.Top + rectangle.Height / 2f);
}
/// <summary>
/// Creates a rectangle from two corner points.
/// </summary>
/// <param name="point1">The first point.</param>
/// <param name="point2">The second points.</param>
/// <returns>The rectangle created from the two points.</returns>
public static RectangleF CreateRectangleFromPoints(PointF point1, PointF point2)
{
float posX = Math.Min(point1.X, point2.X);
@@ -21,16 +35,27 @@ namespace CUE.NET.Helper
return new RectangleF(posX, posY, width, height);
}
public static RectangleF CreateRectangleFromRectangles(RectangleF point1, RectangleF point2)
/// <summary>
/// Creates a rectangle containing two other rectangles.
/// </summary>
/// <param name="rectangle1">The first rectangle.</param>
/// <param name="rectangle2">The second rectangle.</param>
/// <returns>The rectangle created from the two rectangles.</returns>
public static RectangleF CreateRectangleFromRectangles(RectangleF rectangle1, RectangleF rectangle2)
{
float posX = Math.Min(point1.X, point2.X);
float posY = Math.Min(point1.Y, point2.Y);
float width = Math.Max(point1.X + point1.Width, point2.X + point2.Width) - posX;
float height = Math.Max(point1.Y + point1.Height, point2.Y + point2.Height) - posY;
float posX = Math.Min(rectangle1.X, rectangle2.X);
float posY = Math.Min(rectangle1.Y, rectangle2.Y);
float width = Math.Max(rectangle1.X + rectangle1.Width, rectangle2.X + rectangle2.Width) - posX;
float height = Math.Max(rectangle1.Y + rectangle1.Height, rectangle2.Y + rectangle2.Height) - posY;
return new RectangleF(posX, posY, width, height);
}
/// <summary>
/// Creates a rectangle containing n other rectangles.
/// </summary>
/// <param name="rectangles">The list of rectangles.</param>
/// <returns>The rectangle created from the rectangles.</returns>
public static RectangleF CreateRectangleFromRectangles(IEnumerable<RectangleF> rectangles)
{
float posX = float.MaxValue;
@@ -49,6 +74,12 @@ namespace CUE.NET.Helper
return CreateRectangleFromPoints(new PointF(posX, posY), new PointF(posX2, posY2));
}
/// <summary>
/// Calculates the percentage of the intersection of two rectangles.
/// </summary>
/// <param name="rect">The rectangle from which the percentage should be calculated.</param>
/// <param name="referenceRect">The intersecting rectangle.</param>
/// <returns>The percentage of the intersection.</returns>
public static float CalculateIntersectPercentage(RectangleF rect, RectangleF referenceRect)
{
if (rect.IsEmpty || referenceRect.IsEmpty) return 0;