From 2a27263dc634430b2c1110fd98868801dede578d Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Tue, 29 Oct 2019 14:47:17 -0700 Subject: [PATCH] add doc comments to the cubic curves --- Curve/CubicBezierCurve2D.cs | 90 +++++++++++++++++++++++++++++++++-- Curve/CubicBezierCurve3D.cs | 95 +++++++++++++++++++++++++++++++++---- 2 files changed, 173 insertions(+), 12 deletions(-) diff --git a/Curve/CubicBezierCurve2D.cs b/Curve/CubicBezierCurve2D.cs index ac5b61a..9f3f710 100644 --- a/Curve/CubicBezierCurve2D.cs +++ b/Curve/CubicBezierCurve2D.cs @@ -3,13 +3,35 @@ using MoonTools.Core.Curve.Extensions; namespace MoonTools.Core.Curve { + /// + /// A 2-dimensional Bezier curve defined by 4 points. + /// public struct CubicBezierCurve2D { + /// + /// The start point. + /// public Vector2 p0; + + /// + /// The first control point. + /// public Vector2 p1; + + /// + /// The second control point. + /// public Vector2 p2; + + /// + /// The end point. + /// public Vector2 p3; + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. public CubicBezierCurve2D(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3) { this.p0 = p0; @@ -18,10 +40,42 @@ namespace MoonTools.Core.Curve this.p3 = p3; } + /// + /// Returns the curve coordinate given by t. + /// + /// A value between 0 and 1. 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); + + /// + /// Returns the curve coordinate given by a normalized time value. + /// + /// A value between startTime and endTime. + /// + /// + public Vector2 Point(float t, float startTime, float endTime) => Point(p0, p1, p2, p3, t, startTime, endTime); + + /// + /// Returns the instantaneous velocity on the curve given by t. + /// + /// A value between 0 and 1. 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)); + + /// + /// Returns the instantaneous velocity on the curve given by a normalized time value. + /// + /// A value between startTime and endTime. + /// + /// + public Vector2 Velocity(float t, float startTime, float endTime) => Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime)); + + /// + /// Returns the curve coordinate given by 4 points and a time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between 0 and 1. public static Vector2 Point(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t) { return CubicBezierCurve3D.Point( @@ -33,11 +87,29 @@ namespace MoonTools.Core.Curve ).XY(); } - public static Vector2 Point(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t, float minT, float maxT) + /// + /// Returns the curve coordinate given by 4 points and a normalized time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between startTime and endTime. + /// + /// + 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)); } + /// + /// Returns the instantaneous velocity given by 4 points and a time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between 0 and 1. public static Vector2 Velocity(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t) { return CubicBezierCurve3D.Velocity( @@ -49,6 +121,16 @@ namespace MoonTools.Core.Curve ).XY(); } + /// + /// Returns the instantaneous velocity given by 4 points and a normalized time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between startTime and endTime. + /// + /// 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)); diff --git a/Curve/CubicBezierCurve3D.cs b/Curve/CubicBezierCurve3D.cs index eebaf37..4bc27af 100644 --- a/Curve/CubicBezierCurve3D.cs +++ b/Curve/CubicBezierCurve3D.cs @@ -2,13 +2,35 @@ using System.Numerics; namespace MoonTools.Core.Curve { + /// + /// A 3-dimensional Bezier curve defined by 4 points. + /// public struct CubicBezierCurve3D { + /// + /// The start point. + /// public Vector3 p0; + + /// + /// The first control point. + /// public Vector3 p1; + + /// + /// The second control point. + /// public Vector3 p2; + + /// + /// The end point. + /// public Vector3 p3; + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. public CubicBezierCurve3D(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) { this.p0 = p0; @@ -17,14 +39,42 @@ namespace MoonTools.Core.Curve this.p3 = p3; } + /// + /// Returns the curve coordinate given by t. + /// + /// A value between 0 and 1. 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); + /// + /// Returns the curve coordinate given by a normalized time value. + /// + /// + /// + /// + public Vector3 Point(float t, float startTime, float endTime) => Point(p0, p1, p2, p3, t, startTime, endTime); + /// + /// Returns the instantaneous velocity on the curve given by t. + /// + /// A value between 0 and 1. 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); + /// + /// Returns the instantaneous velocity on the curve given by a normalized time value. + /// + /// A value between 0 and 1. + /// + /// + public Vector3 Velocity(float t, float startTime, float endTime) => Velocity(p0, p1, p2, p3, t, startTime, endTime); + /// + /// Returns the curve coordinate given by 4 points and a time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between 0 and 1. public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) { ArgumentChecker.CheckT(t); @@ -35,12 +85,30 @@ namespace MoonTools.Core.Curve t * t * t * p3; } - public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float minT, float maxT) + /// + /// Returns the curve coordinate given by 4 points and a normalized time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between startTime and endTime. + /// + /// + public static Vector3 Point(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float startTime, float endTime) { - ArgumentChecker.CheckT(t, minT, maxT); - return Point(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT)); + ArgumentChecker.CheckT(t, startTime, endTime); + return Point(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime)); } + /// + /// Returns the instantaneous velocity given by 4 points and a time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between 0 and 1. public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) { ArgumentChecker.CheckT(t); @@ -50,10 +118,21 @@ namespace MoonTools.Core.Curve 3f * t * t * (p3 - p2); } - public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float minT, float maxT) + /// + /// Returns the instantaneous velocity given by 4 points and a normalized time value. + /// + /// The start point. + /// The first control point. + /// The second control point. + /// The end point. + /// A value between startTime and endTime. + /// + /// + /// + public static Vector3 Velocity(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, float startTime, float endTime) { - ArgumentChecker.CheckT(t, minT, maxT); - return Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, minT, maxT)); + ArgumentChecker.CheckT(t, startTime, endTime); + return Velocity(p0, p1, p2, p3, TimeHelper.Normalized(t, startTime, endTime)); } } } \ No newline at end of file