add doc comments to the cubic curves

master
Evan Hemsley 2019-10-29 14:47:17 -07:00
parent 8ea37b1af4
commit 2a27263dc6
2 changed files with 173 additions and 12 deletions

View File

@ -3,13 +3,35 @@ using MoonTools.Core.Curve.Extensions;
namespace MoonTools.Core.Curve namespace MoonTools.Core.Curve
{ {
/// <summary>
/// A 2-dimensional Bezier curve defined by 4 points.
/// </summary>
public struct CubicBezierCurve2D public struct CubicBezierCurve2D
{ {
/// <summary>
/// The start point.
/// </summary>
public Vector2 p0; public Vector2 p0;
/// <summary>
/// The first control point.
/// </summary>
public Vector2 p1; public Vector2 p1;
/// <summary>
/// The second control point.
/// </summary>
public Vector2 p2; public Vector2 p2;
/// <summary>
/// The end point.
/// </summary>
public Vector2 p3; public Vector2 p3;
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
public CubicBezierCurve2D(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3) public CubicBezierCurve2D(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)
{ {
this.p0 = p0; this.p0 = p0;
@ -18,10 +40,42 @@ namespace MoonTools.Core.Curve
this.p3 = p3; this.p3 = p3;
} }
/// <summary>
/// Returns the curve coordinate given by t.
/// </summary>
/// <param name="t">A value between 0 and 1.</param>
public Vector2 Point(float t) => Point(p0, p1, p2, p3, t); public Vector2 Point(float t) => Point(p0, p1, p2, p3, t);
public Vector2 Point(float t, float minT, float maxT) => Point(p0, p1, p2, p3, t, minT, maxT);
/// <summary>
/// Returns the curve coordinate given by a normalized time value.
/// </summary>
/// <param name="t">A value between startTime and endTime.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public Vector2 Point(float t, float startTime, float endTime) => Point(p0, p1, p2, p3, t, startTime, endTime);
/// <summary>
/// Returns the instantaneous velocity on the curve given by t.
/// </summary>
/// <param name="t">A value between 0 and 1.</param>
public Vector2 Velocity(float t) => Velocity(p0, p1, p2, p3, t); public Vector2 Velocity(float t) => Velocity(p0, p1, p2, p3, t);
public Vector2 Velocity(float t, float minT, float maxT) => Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT));
/// <summary>
/// Returns the instantaneous velocity on the curve given by a normalized time value.
/// </summary>
/// <param name="t">A value between startTime and endTime.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public Vector2 Velocity(float t, float startTime, float endTime) => Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime));
/// <summary>
/// Returns the curve coordinate given by 4 points and a time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between 0 and 1.</param>
public static Vector2 Point(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t) public static Vector2 Point(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t)
{ {
return CubicBezierCurve3D.Point( return CubicBezierCurve3D.Point(
@ -33,11 +87,29 @@ namespace MoonTools.Core.Curve
).XY(); ).XY();
} }
public static Vector2 Point(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t, float minT, float maxT) /// <summary>
/// Returns the curve coordinate given by 4 points and a normalized time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between startTime and endTime.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public static Vector2 Point(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t, float startTime, float endTime)
{ {
return Point(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT)); return Point(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime));
} }
/// <summary>
/// Returns the instantaneous velocity given by 4 points and a time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between 0 and 1.</param>
public static Vector2 Velocity(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t) public static Vector2 Velocity(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t)
{ {
return CubicBezierCurve3D.Velocity( return CubicBezierCurve3D.Velocity(
@ -49,6 +121,16 @@ namespace MoonTools.Core.Curve
).XY(); ).XY();
} }
/// <summary>
/// Returns the instantaneous velocity given by 4 points and a normalized time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between startTime and endTime.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public static Vector2 Velocity(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t, float minT, float maxT) public static Vector2 Velocity(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t, float minT, float maxT)
{ {
return Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT)); return Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT));

View File

@ -2,13 +2,35 @@ using System.Numerics;
namespace MoonTools.Core.Curve namespace MoonTools.Core.Curve
{ {
/// <summary>
/// A 3-dimensional Bezier curve defined by 4 points.
/// </summary>
public struct CubicBezierCurve3D public struct CubicBezierCurve3D
{ {
/// <summary>
/// The start point.
/// </summary>
public Vector3 p0; public Vector3 p0;
/// <summary>
/// The first control point.
/// </summary>
public Vector3 p1; public Vector3 p1;
/// <summary>
/// The second control point.
/// </summary>
public Vector3 p2; public Vector3 p2;
/// <summary>
/// The end point.
/// </summary>
public Vector3 p3; public Vector3 p3;
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
public CubicBezierCurve3D(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) public CubicBezierCurve3D(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
{ {
this.p0 = p0; this.p0 = p0;
@ -17,14 +39,42 @@ namespace MoonTools.Core.Curve
this.p3 = p3; this.p3 = p3;
} }
/// <summary>
/// Returns the curve coordinate given by t.
/// </summary>
/// <param name="t">A value between 0 and 1.</param>
public Vector3 Point(float t) => Point(p0, p1, p2, p3, t); public Vector3 Point(float t) => Point(p0, p1, p2, p3, t);
public Vector3 Point(float t, float minT, float maxT) => Point(p0, p1, p2, p3, t, minT, maxT); /// <summary>
/// Returns the curve coordinate given by a normalized time value.
/// </summary>
/// <param name="t"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public Vector3 Point(float t, float startTime, float endTime) => Point(p0, p1, p2, p3, t, startTime, endTime);
/// <summary>
/// Returns the instantaneous velocity on the curve given by t.
/// </summary>
/// <param name="t">A value between 0 and 1.</param>
public Vector3 Velocity(float t) => Velocity(p0, p1, p2, p3, t); public Vector3 Velocity(float t) => Velocity(p0, p1, p2, p3, t);
public Vector3 Velocity(float t, float minT, float maxT) => Velocity(p0, p1, p2, p3, t, minT, maxT); /// <summary>
/// Returns the instantaneous velocity on the curve given by a normalized time value.
/// </summary>
/// <param name="t">A value between 0 and 1.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public Vector3 Velocity(float t, float startTime, float endTime) => Velocity(p0, p1, p2, p3, t, startTime, endTime);
/// <summary>
/// Returns the curve coordinate given by 4 points and a time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between 0 and 1.</param>
public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{ {
ArgumentChecker.CheckT(t); ArgumentChecker.CheckT(t);
@ -35,12 +85,30 @@ namespace MoonTools.Core.Curve
t * t * t * p3; t * t * t * p3;
} }
public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float minT, float maxT) /// <summary>
/// Returns the curve coordinate given by 4 points and a normalized time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between startTime and endTime.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float startTime, float endTime)
{ {
ArgumentChecker.CheckT(t, minT, maxT); ArgumentChecker.CheckT(t, startTime, endTime);
return Point(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT)); return Point(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime));
} }
/// <summary>
/// Returns the instantaneous velocity given by 4 points and a time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between 0 and 1.</param>
public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{ {
ArgumentChecker.CheckT(t); ArgumentChecker.CheckT(t);
@ -50,10 +118,21 @@ namespace MoonTools.Core.Curve
3f * t * t * (p3 - p2); 3f * t * t * (p3 - p2);
} }
public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float minT, float maxT) /// <summary>
/// Returns the instantaneous velocity given by 4 points and a normalized time value.
/// </summary>
/// <param name="p0">The start point.</param>
/// <param name="p1">The first control point.</param>
/// <param name="p2">The second control point.</param>
/// <param name="p3">The end point.</param>
/// <param name="t">A value between startTime and endTime.</param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float startTime, float endTime)
{ {
ArgumentChecker.CheckT(t, minT, maxT); ArgumentChecker.CheckT(t, startTime, endTime);
return Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT)); return Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime));
} }
} }
} }