mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Added missing operators and documentation
This commit is contained in:
parent
1d727e16b0
commit
ac8ec602dd
@ -56,6 +56,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
private Rectangle _deviceRectangle;
|
||||
/// <inheritdoc />
|
||||
public Rectangle DeviceRectangle
|
||||
{
|
||||
get => _deviceRectangle;
|
||||
|
||||
@ -29,10 +29,14 @@ namespace RGB.NET.Core
|
||||
Size Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the actual <see cref="Size"/> (scaled and rotated) of the <see cref="IRGBDevice"/>.
|
||||
/// Gets the actual <see cref="Size"/> of the <see cref="IRGBDevice"/>.
|
||||
/// This includes the <see cref="Scale"/>.
|
||||
/// </summary>
|
||||
Size ActualSize { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Rectangle"/> representing the logical location of the <see cref="DeviceRectangle"/> relative to the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
Rectangle DeviceRectangle { get; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
37
RGB.NET.Core/Extensions/PointExtensions.cs
Normal file
37
RGB.NET.Core/Extensions/PointExtensions.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
public static class PointExtensions
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Point"/> by the given amount.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/> to move.</param>
|
||||
/// <param name="x">The x-ammount to move.</param>
|
||||
/// <param name="y">The y-ammount to move.</param>
|
||||
/// <returns>The new location of the point.</returns>
|
||||
public static Point Translate(this Point point, double x = 0, double y = 0) => new Point(point.X + x, point.Y + y);
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified <see cref="Point"/> by the given amuont around the given origin.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/> to rotate.</param>
|
||||
/// <param name="rotation">The rotation.</param>
|
||||
/// <param name="origin">The origin to rotate around. [0,0] if not set.</param>
|
||||
/// <returns>The new location of the point.</returns>
|
||||
public static Point Rotate(this Point point, Rotation rotation, Point origin = new Point())
|
||||
{
|
||||
double sin = Math.Sin(rotation.Radians);
|
||||
double cos = Math.Cos(rotation.Radians);
|
||||
|
||||
point = new Point(point.X - origin.X, point.Y - origin.Y);
|
||||
point = new Point((point.X * cos) - (point.Y * sin), (point.X * sin) + (point.Y * cos));
|
||||
return new Point(point.X + origin.X, point.Y + origin.Y); ;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ namespace RGB.NET.Core
|
||||
/// Determines if the specified <see cref="Point"/> is contained within this <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/> to test.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns><c>true</c> if the rectangle contains the given point; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this Rectangle rect, Point point) => rect.Contains(point.X, point.Y);
|
||||
|
||||
/// <summary>
|
||||
@ -98,33 +98,49 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="x">The X-location to test.</param>
|
||||
/// <param name="y">The Y-location to test.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns><c>true</c> if the rectangle contains the given coordinates; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this Rectangle rect, double x, double y) => (rect.Location.X <= x) && (x < (rect.Location.X + rect.Size.Width))
|
||||
&& (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.Size.Height));
|
||||
&& (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.Size.Height));
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the specified <see cref="Rectangle"/> is contained within this <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to test.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns><c>true</c> if the rectangle contains the given rect; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this Rectangle rect, Rectangle rect2) => (rect.Location.X <= rect2.Location.X) && ((rect2.Location.X + rect2.Size.Width) <= (rect.Location.X + rect.Size.Width))
|
||||
&& (rect.Location.Y <= rect2.Location.Y) && ((rect2.Location.Y + rect2.Size.Height) <= (rect.Location.Y + rect.Size.Height));
|
||||
|
||||
public static Point Translate(this Point point, double x = 0, double y = 0) => new Point(point.X + x, point.Y + y);
|
||||
|
||||
public static Point Rotate(this Point point, Rotation rotation, Point origin = new Point())
|
||||
{
|
||||
double sin = Math.Sin(rotation.Radians);
|
||||
double cos = Math.Cos(rotation.Radians);
|
||||
|
||||
point = new Point(point.X - origin.X, point.Y - origin.Y);
|
||||
point = new Point((point.X * cos) - (point.Y * sin), (point.X * sin) + (point.Y * cos));
|
||||
return new Point(point.X + origin.X, point.Y + origin.Y); ;
|
||||
}
|
||||
&& (rect.Location.Y <= rect2.Location.Y) && ((rect2.Location.Y + rect2.Size.Height) <= (rect.Location.Y + rect.Size.Height));
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Rectangle"/> by the given amount.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
|
||||
/// <param name="point">The amount to move.</param>
|
||||
/// <returns>The moved rectangle.</returns>
|
||||
public static Rectangle Translate(this Rectangle rect, Point point) => rect.Translate(point.X, point.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Rectangle"/> by the given amount.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
|
||||
/// <param name="x">The x-ammount to move.</param>
|
||||
/// <param name="y">The y-ammount to move.</param>
|
||||
/// <returns>The moved rectangle.</returns>
|
||||
public static Rectangle Translate(this Rectangle rect, double x = 0, double y = 0) => new Rectangle(rect.Location.Translate(x, y), rect.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified <see cref="Rectangle"/> by the given amuont around the given origin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The returned array of <see cref="Point"/> is filled with the new locations of the rectangle clockwise starting from the top left:
|
||||
/// [0] = top left
|
||||
/// [1] = top right
|
||||
/// [2] = bottom right
|
||||
/// [3] = bottom left
|
||||
/// </remarks>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to rotate.</param>
|
||||
/// <param name="rotation">The rotation.</param>
|
||||
/// <param name="origin">The origin to rotate around. [0,0] if not set.</param>
|
||||
/// <returns>A array of <see cref="Point"/> containing the new locations of the corners of the original rectangle.</returns>
|
||||
public static Point[] Rotate(this Rectangle rect, Rotation rotation, Point origin = new Point())
|
||||
{
|
||||
Point[] points = {
|
||||
|
||||
@ -46,6 +46,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
private Point _location;
|
||||
/// <summary>
|
||||
/// Gets or sets the relative location of the <see cref="Led"/>.
|
||||
/// </summary>
|
||||
public Point Location
|
||||
{
|
||||
get => _location;
|
||||
@ -60,6 +63,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
private Size _size;
|
||||
/// <summary>
|
||||
/// Gets or sets the size of the <see cref="Led"/>.
|
||||
/// </summary>
|
||||
public Size Size
|
||||
{
|
||||
get => _size;
|
||||
@ -74,6 +80,10 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
private Point _actualLocation;
|
||||
/// <summary>
|
||||
/// Gets the actual location of the <see cref="Led"/>.
|
||||
/// This includes device-scaling and rotation.
|
||||
/// </summary>
|
||||
public Point ActualLocation
|
||||
{
|
||||
get => _actualLocation;
|
||||
@ -81,6 +91,10 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
private Size _actualSize;
|
||||
/// <summary>
|
||||
/// Gets the actual location of the <see cref="Led"/>.
|
||||
/// This includes device-scaling.
|
||||
/// </summary>
|
||||
public Size ActualSize
|
||||
{
|
||||
get => _actualSize;
|
||||
|
||||
@ -149,6 +149,12 @@ namespace RGB.NET.Core
|
||||
return new Point(point1.X / point2.X, point1.Y / point2.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the multiplication of the <see cref="Point"/> and the provided <see cref="Scale"/>.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/>.</param>
|
||||
/// <param name="scale">The <see cref="Scale"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the multiplication of the <see cref="Point"/> and the provided <see cref="Scale"/>.</returns>
|
||||
public static Point operator *(Point point, Scale scale) => new Point(point.X * scale.Horizontal, point.Y * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
using System;
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an angular rotation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("[{Degrees}°]")]
|
||||
public struct Rotation
|
||||
{
|
||||
#region Constants
|
||||
@ -14,15 +22,29 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the angle in degrees.
|
||||
/// </summary>
|
||||
public double Degrees { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the angle in radians.
|
||||
/// </summary>
|
||||
public double Radians { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a bool indicating if the rotation is > 0.
|
||||
/// </summary>
|
||||
public bool IsRotated => !Degrees.EqualsInTolerance(0);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rotation"/> class using the provided values.
|
||||
/// </summary>
|
||||
/// <param name="scale">The rotation in degrees.</param>
|
||||
public Rotation(double degrees)
|
||||
: this(degrees, degrees * DEGREES_RADIANS_CONVERSION)
|
||||
{ }
|
||||
@ -37,18 +59,102 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Rotation out of the given degree-angle.
|
||||
/// </summary>
|
||||
/// <param name="degrees">The angle in degrees.</param>
|
||||
/// <returns>The new rotation.</returns>
|
||||
public static Rotation FromDegrees(double degrees) => new Rotation(degrees);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Rotation out of the given radian-angle.
|
||||
/// </summary>
|
||||
/// <param name="degrees">The angle in radians.</param>
|
||||
/// <returns>The new rotation.</returns>
|
||||
public static Rotation FromRadians(double radians) => new Rotation(radians * RADIANS_DEGREES_CONVERSION, radians);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified <see cref="Rotation" /> is equivalent to this <see cref="Rotation" />.
|
||||
/// </summary>
|
||||
/// <param name="other">The rotation to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="other" /> is equivalent to this <see cref="Rotation" />; otherwise, <c>false</c>.</returns>
|
||||
public bool Equals(Rotation other) => Degrees.EqualsInTolerance(other.Degrees);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Rotation" /> and is equivalent to this <see cref="Rotation" />.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Rotation" /> equivalent to this <see cref="Rotation" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object obj) => obj is Rotation other && Equals(other);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash code for this <see cref="Rotation" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Rotation" />.</returns>
|
||||
public override int GetHashCode() => Degrees.GetHashCode();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Rotation" /> are equal.
|
||||
/// </summary>
|
||||
/// <param name="rotation1">The first <see cref="Rotation" /> to compare.</param>
|
||||
/// <param name="rotation2">The second <see cref="Rotation" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="rotation1" /> and <paramref name="rotation2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(Rotation rotation1, Rotation rotation2) => rotation1.Equals(rotation2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Rotation" /> are equal.
|
||||
/// </summary>
|
||||
/// <param name="rotation1">The first <see cref="Rotation" /> to compare.</param>
|
||||
/// <param name="rotation2">The second <see cref="Rotation" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="rotation1" /> and <paramref name="rotation2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(Rotation rotation1, Rotation rotation2) => !(rotation1 == rotation2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="rotation">The <see cref="Rotation"/>.</param>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <returns>A new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.</returns>
|
||||
public static Rotation operator +(Rotation rotation, double value) => new Rotation(rotation.Degrees + value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="rotation">The <see cref="Rotation"/>.</param>
|
||||
/// <param name="value">The value to substract.</param>
|
||||
/// <returns>A new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.</returns>
|
||||
public static Rotation operator -(Rotation rotation, double value) => new Rotation(rotation.Degrees - value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="rotation">The <see cref="Rotation"/>.</param>
|
||||
/// <param name="value">The value to multiply with.</param>
|
||||
/// <returns>A new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.</returns>
|
||||
public static Rotation operator *(Rotation rotation, double value) => new Rotation(rotation.Degrees * value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="rotation">The <see cref="Rotation"/>.</param>
|
||||
/// <param name="value">The value to device with.</param>
|
||||
/// <returns>A new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.</returns>
|
||||
public static Rotation operator /(Rotation rotation, double value) => value.EqualsInTolerance(0) ? new Rotation(0) : new Rotation(rotation.Degrees / value);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a double to a <see cref="Rotation" />.
|
||||
/// </summary>
|
||||
/// <param name="rotation">The rotation in degrees to convert.</param>
|
||||
public static implicit operator Rotation(double rotation) => new Rotation(rotation);
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Rotation" /> to a double representing the rotation in degrees.
|
||||
/// </summary>
|
||||
/// <param name="rotation">The rotatio to convert.</param>
|
||||
public static implicit operator double(Rotation rotation) => rotation.Degrees;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,19 +1,44 @@
|
||||
namespace RGB.NET.Core
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a scaling.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("[Horizontal: {Horizontal}, Vertical: {Vertical}]")]
|
||||
public struct Scale
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal scaling value.
|
||||
/// </summary>
|
||||
public double Horizontal { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical scaling value.
|
||||
/// </summary>
|
||||
public double Vertical { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Scale"/> class using the provided values.
|
||||
/// </summary>
|
||||
/// <param name="scale">The value used for horizontal and vertical scaling. 0 if not set.</param>
|
||||
public Scale(double scale = 1.0) : this(scale, scale)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Scale"/> class using the provided values.
|
||||
/// </summary>
|
||||
/// <param name="horizontal">The value used for horizontal scaling.</param>
|
||||
/// <param name="vertical">The value used for vertical scaling.</param>
|
||||
public Scale(double horizontal, double vertical)
|
||||
{
|
||||
this.Horizontal = horizontal;
|
||||
@ -24,10 +49,31 @@
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified <see cref="Scale"/> is equivalent to this <see cref="Scale" />.
|
||||
/// </summary>
|
||||
/// <param name="other">The scale to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="other" /> is equivalent to this <see cref="Scale" />; otherwise, <c>false</c>.</returns>
|
||||
public bool Equals(Scale other) => Horizontal.EqualsInTolerance(other.Horizontal) && Vertical.EqualsInTolerance(other.Vertical);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Scale" /> and is equivalent to this <see cref="Scale" />.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Scale" /> equivalent to this <see cref="Scale" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object obj) => obj is Scale other && Equals(other);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash code for this <see cref="Scale" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Scale" />.</returns>
|
||||
public override int GetHashCode() { unchecked { return (Horizontal.GetHashCode() * 397) ^ Vertical.GetHashCode(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Deconstructs the scale into the horizontal and vertical value.
|
||||
/// </summary>
|
||||
/// <param name="horizontalScale">The horizontal scaling value.</param>
|
||||
/// <param name="verticalScale">The vertical scaling value.</param>
|
||||
public void Deconstruct(out double horizontalScale, out double verticalScale)
|
||||
{
|
||||
horizontalScale = Horizontal;
|
||||
@ -38,8 +84,60 @@
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Scale" /> are equal.
|
||||
/// </summary>
|
||||
/// <param name="scale1">The first <see cref="Scale" /> to compare.</param>
|
||||
/// <param name="scale2">The second <see cref="Scale" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="scale1" /> and <paramref name="scale2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(Scale scale1, Scale scale2) => scale1.Equals(scale2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Scale" /> are equal.
|
||||
/// </summary>
|
||||
/// <param name="scale1">The first <see cref="Scale" /> to compare.</param>
|
||||
/// <param name="scale2">The second <see cref="Scale" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="scale1" /> and <paramref name="scale2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(Scale scale1, Scale scale2) => !(scale1 == scale2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Scale"/> representing the addition of the <see cref="Scale"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="scale">The <see cref="Scale"/>.</param>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <returns>A new <see cref="Scale"/> representing the addition of the <see cref="Scale"/> and the provided value.</returns>
|
||||
public static Scale operator +(Scale scale, double value) => new Scale(scale.Horizontal + value, scale.Vertical + value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="scale">The <see cref="Scale"/>.</param>
|
||||
/// <param name="value">The value to substract.</param>
|
||||
/// <returns>A new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.</returns>
|
||||
public static Scale operator -(Scale scale, double value) => new Scale(scale.Horizontal - value, scale.Vertical - value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="scale">The <see cref="Scale"/>.</param>
|
||||
/// <param name="value">The value to multiply with.</param>
|
||||
/// <returns>A new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.</returns>
|
||||
public static Scale operator *(Scale scale, double value) => new Scale(scale.Horizontal * value, scale.Vertical * value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.
|
||||
/// </summary>
|
||||
/// <param name="scale">The <see cref="Scale"/>.</param>
|
||||
/// <param name="value">The value to device with.</param>
|
||||
/// <returns>A new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.</returns>
|
||||
public static Scale operator /(Scale scale, double value) => value.EqualsInTolerance(0) ? new Scale(0) : new Scale(scale.Horizontal / value, scale.Vertical / value);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a double to a <see cref="Scale" />.
|
||||
/// </summary>
|
||||
/// <param name="scale">The scale value to convert.</param>
|
||||
public static implicit operator Scale(double scale) => new Scale(scale);
|
||||
public static implicit operator Scale((double horizontal, double vertical) scale) => new Scale(scale.horizontal, scale.vertical);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -94,6 +94,11 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deconstructs the size into the width and height value.
|
||||
/// </summary>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
public void Deconstruct(out double width, out double height)
|
||||
{
|
||||
width = Width;
|
||||
@ -178,6 +183,12 @@ namespace RGB.NET.Core
|
||||
/// <returns>A new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.</returns>
|
||||
public static Size operator /(Size size, double factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.
|
||||
/// </summary>
|
||||
/// <param name="size">The <see cref="Size"/> to scale.</param>
|
||||
/// <param name="scale">The scaling factor.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.</returns>
|
||||
public static Size operator *(Size size, Scale scale) => new Size(size.Width * scale.Horizontal, size.Height * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user