mirror of https://github.com/oliverbooth/X10D
Add Point.IsOnLine (#64)
This commit is contained in:
parent
2e8626a32b
commit
02cc897426
|
@ -6,6 +6,8 @@
|
|||
- X10D: Added `Circle`, `CircleF`, `Cuboid`, `Ellipse`, `EllipseF`, `Line3D`, `Line`, `LineF`, `Polygon`, `PolygonF`, `Polyhedron`, and `Sphere`, to complement System.Drawing structs such as `Point` and `Rectangle`
|
||||
- X10D: Added `DirectoryInfo.Clear([bool])`
|
||||
- X10D: Added `IList<T>.RemoveRange(Range)`
|
||||
- X10D: Added `Point.IsOnLine(LineF)`, `Point.IsOnLine(PointF, PointF)`, and `Point.IsOnLine(Vector2, Vector2)`
|
||||
- X10D: Added `PointF.IsOnLine(LineF)`, `PointF.IsOnLine(PointF, PointF)`, and `PointF.IsOnLine(Vector2, Vector2)`
|
||||
- X10D: Added `Point.ToSize()`
|
||||
- X10D: Added `Point.ToSizeF()`
|
||||
- X10D: Added `Point.ToVector2()`
|
||||
|
@ -17,6 +19,7 @@
|
|||
- X10D: Added `Size.ToVector2()`
|
||||
- X10D: Added `Quaternion.Multiply(Vector3)` - this functions as an equivalent to Unity's `Quaternion * Vector3` operator
|
||||
- X10D: Added `Vector2.Deconstruct()`
|
||||
- X10D: Added `Vector2.IsOnLine(LineF)`, `Vector2.IsOnLine(PointF, PointF)`, and `Vector2.IsOnLine(Vector2, Vector2)`
|
||||
- X10D: Added `Vector2.ToPointF()`
|
||||
- X10D: Added `Vector2.ToSizeF()`
|
||||
- X10D: Added `Vector3.Deconstruct()`
|
||||
|
@ -39,6 +42,8 @@
|
|||
- X10D.Unity: Added `Size.ToUnityVector2Int()`
|
||||
- X10D.Unity: Added `SizeF.ToUnityVector2()`
|
||||
- X10D.Unity: Added `Vector2.Deconstruct()`
|
||||
- X10D.Unity: Added `Vector2.IsOnLine(LineF)`, `Vector2.IsOnLine(PointF, PointF)`, and `Vector2.IsOnLine(Vector2, Vector2)`
|
||||
- X10D.Unity: Added `Vector2Int.IsOnLine(LineF)`, `Vector2Int.IsOnLine(PointF, PointF)`, `Vector2Int.IsOnLine(Vector2, Vector2)`, and `Vector2Int.IsOnLine(Vector2Int, Vector2Int)`
|
||||
- X10D.Unity: Added `Vector2.ToSystemPointF()`
|
||||
- X10D.Unity: Added `Vector2.ToSystemSizeF()`
|
||||
- X10D.Unity: Added `Vector2Int.Deconstruct()`
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using X10D.Drawing;
|
||||
using X10D.Unity.Numerics;
|
||||
|
||||
namespace X10D.Unity.Drawing;
|
||||
|
||||
|
@ -10,6 +12,23 @@ namespace X10D.Unity.Drawing;
|
|||
/// </summary>
|
||||
public static class PointFExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="PointF" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this PointF point, Vector2 start, Vector2 end)
|
||||
{
|
||||
return point.IsOnLine(start.ToSystemVector(), end.ToSystemVector());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current <see cref="Point" /> to a <see cref="Vector2" />.
|
||||
/// </summary>
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using X10D.Drawing;
|
||||
using X10D.Numerics;
|
||||
|
||||
namespace X10D.Unity.Numerics;
|
||||
|
||||
|
@ -22,6 +24,56 @@ public static class Vector2Extensions
|
|||
y = vector.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="line">The line on which the point may lie.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="line" />; otherwise
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2 point, LineF line)
|
||||
{
|
||||
return point.ToSystemVector().IsOnLine(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2 point, PointF start, PointF end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2 point, Vector2 start, Vector2 end)
|
||||
{
|
||||
return point.ToSystemVector().IsOnLine(start.ToSystemVector(), end.ToSystemVector());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current <see cref="Vector2" /> into a <see cref="PointF" />.
|
||||
/// </summary>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using X10D.Drawing;
|
||||
|
||||
namespace X10D.Unity.Numerics;
|
||||
|
||||
|
@ -22,6 +23,73 @@ public static class Vector2IntExtensions
|
|||
y = vector.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2Int" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="line">The line on which the point may lie.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="line" />; otherwise
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2Int point, LineF line)
|
||||
{
|
||||
return point.ToSystemPoint().IsOnLine(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2Int" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2Int point, PointF start, PointF end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2Int" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2Int point, Vector2Int start, Vector2Int end)
|
||||
{
|
||||
return point.ToSystemPoint().IsOnLine(new LineF(start.ToSystemVector(), end.ToSystemVector()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2Int" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsOnLine(this Vector2Int point, Vector2 start, Vector2 end)
|
||||
{
|
||||
return point.ToSystemPoint().IsOnLine(new LineF(start.ToSystemVector(), end.ToSystemVector()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current <see cref="Vector2Int" /> into a <see cref="Point" />.
|
||||
/// </summary>
|
||||
|
|
|
@ -10,6 +10,68 @@ namespace X10D.Drawing;
|
|||
/// </summary>
|
||||
public static class PointExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Point" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="line">The line on which the point may lie.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="line" />; otherwise
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this Point point, LineF line)
|
||||
{
|
||||
return ((PointF)point).IsOnLine(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Point" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this Point point, PointF start, PointF end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Point" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this Point point, Vector2 start, Vector2 end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current <see cref="Point" /> to a <see cref="Size" />.
|
||||
/// </summary>
|
||||
|
|
|
@ -10,6 +10,71 @@ namespace X10D.Drawing;
|
|||
/// </summary>
|
||||
public static class PointFExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="PointF" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="line">The line on which the point may lie.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="line" />; otherwise
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this PointF point, LineF line)
|
||||
{
|
||||
(float x1, float x2) = (line.Start.X, line.End.X);
|
||||
(float y1, float y2) = (line.Start.Y, line.End.Y);
|
||||
(float x, float y) = (point.X, point.Y);
|
||||
return System.Math.Abs((y2 - y1) * (x - x2) - (y - y2) * (x2 - x1)) < float.Epsilon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="PointF" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this PointF point, PointF start, PointF end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="PointF" /> lies on the specified <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this PointF point, Vector2 start, Vector2 end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current <see cref="PointF" /> to a <see cref="SizeF" />.
|
||||
/// </summary>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using X10D.Drawing;
|
||||
|
||||
namespace X10D.Numerics;
|
||||
|
||||
|
@ -22,6 +23,71 @@ public static class Vector2Extensions
|
|||
y = vector.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="line">The line on which the point may lie.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="line" />; otherwise
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this Vector2 point, LineF line)
|
||||
{
|
||||
(float x1, float x2) = (line.Start.X, line.End.X);
|
||||
(float y1, float y2) = (line.Start.Y, line.End.Y);
|
||||
(float x, float y) = (point.X, point.Y);
|
||||
return System.Math.Abs((y2 - y1) * (x - x2) - (y - y2) * (x2 - x1)) < float.Epsilon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this Vector2 point, PointF start, PointF end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the current <see cref="Vector2" /> lies on the specified line.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="start">The starting point of the line.</param>
|
||||
/// <param name="end">The ending point of the line.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="point" /> lies on the line defined by <paramref name="start" /> and
|
||||
/// <paramref name="end" />; otherwise <see langword="false" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static bool IsOnLine(this Vector2 point, Vector2 start, Vector2 end)
|
||||
{
|
||||
return point.IsOnLine(new LineF(start, end));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current <see cref="Vector2" /> to a <see cref="PointF" />.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue