From 3ef03afd22b317a095db03eb0bd37e41fa15deb7 Mon Sep 17 00:00:00 2001 From: Richard Tingle <6330028+richardTingle@users.noreply.github.com> Date: Sat, 18 Dec 2021 15:19:23 +0000 Subject: [PATCH 1/4] #5 Add javadoc to the addControlPoint method --- .../com/epaga/particles/valuetypes/Curve.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/epaga/particles/valuetypes/Curve.java b/src/main/java/com/epaga/particles/valuetypes/Curve.java index 831c6a6..8cd194b 100644 --- a/src/main/java/com/epaga/particles/valuetypes/Curve.java +++ b/src/main/java/com/epaga/particles/valuetypes/Curve.java @@ -38,6 +38,10 @@ import java.util.LinkedList; import java.util.List; +/** + * The curve represents a continous function that parses through a number of control + * points. See {@link Curve#addControlPoint} for details on how these control points work + */ public class Curve implements Savable, Cloneable { private LinkedList points = new LinkedList<>(); @@ -45,6 +49,35 @@ public class Curve implements Savable, Cloneable { public Curve() { } + /** + * Adds a control point to the curve. The line will enter the control point with the following + * rules but may curve between control points so a continuous line is formed. + * + * Note that if the implied gradient entering the control point is different from the implied gradient exiting it then + * the gradient may sharply change (but the line itself will remain continuous). + * + * Between each pair of control points acts as an independent cubic Bézier curve defined by the following: + * + * anchor 1 - the 'point' of the first control point (the line will pass through this point) + * intermediate point 1 - the 'out' of the first control point (the line may not go through this point but it controls the initial direction the line exits anchor 1) + * intermediate point 2 - the 'in' of the second control point (the line may not go through this point but it controls the initial direction the line enters anchor 2) + * anchor 2 - the 'point' of the second control point (the line will pass through this point) + * + * Instinctively you can think of each section "trying" to go from anchor 1 -> intermediate point 1 -> intermediate point 2 -> anchor 2 + * but being smoothed using a quadratic curve such that it may not actually touch the intermediate points. + * + * Note; if this is the first control point the in doesn't matter and if its the last control point the out doesn't matter + * + * @param in + * the intermediate point immediately before this anchor point. + * This is a control point in Bézier curve terminology + * @param point + * the line will pass through this point. This is an anchor point in Bézier curve terminology + * @param out + * the intermediate point immediately after this anchor point. + * This is a control point in Bézier curve terminology + * @return this curve + */ public Curve addControlPoint(Vector2f in, Vector2f point, Vector2f out) { points.add(new ControlPoint(in, point, out)); sort(); @@ -82,13 +115,13 @@ public float getValue(float blendTime) { float perc = (blendTime - lastPoint.point.x) / (currentPoint.point.x - lastPoint.point.x); // get the midpoints of the 3 line segments - //float p1x = lastPoint.point.x - ((lastPoint.point.x - lastPoint.outControlPoint.x) * perc); + //what y should be according to the the line from lastPoint.point -> lastPoint.outControlPoint float p1y = lastPoint.point.y - ((lastPoint.point.y - lastPoint.outControlPoint.y) * perc); - //float p2x = lastPoint.outControlPoint.x - ((lastPoint.outControlPoint.x - currentPoint.inControlPoint.x) * perc); + //what y should be according to the the line from lastPoint.outControlPoint -> currentPoint.inControlPoint float p2y = lastPoint.outControlPoint.y - ((lastPoint.outControlPoint.y - currentPoint.inControlPoint.y) * perc); - //float p3x = currentPoint.inControlPoint.x - ((currentPoint.inControlPoint.x - currentPoint.point.x) * perc); + //what y should be according to the the line from lastPoint.outControlPoint -> currentPoint.inControlPoint float p3y = currentPoint.inControlPoint.y - ((currentPoint.inControlPoint.y - currentPoint.point.y) * perc); // now get the midpoints of the two segments From d207256f27d9e9f3cdc026a094b7f13869dae080 Mon Sep 17 00:00:00 2001 From: Richard Tingle <6330028+richardTingle@users.noreply.github.com> Date: Sat, 18 Dec 2021 16:45:14 +0000 Subject: [PATCH 2/4] #5 Improve javadoc to note that these aren't actually bezier curves --- src/main/java/com/epaga/particles/valuetypes/Curve.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/epaga/particles/valuetypes/Curve.java b/src/main/java/com/epaga/particles/valuetypes/Curve.java index 8cd194b..6e3436a 100644 --- a/src/main/java/com/epaga/particles/valuetypes/Curve.java +++ b/src/main/java/com/epaga/particles/valuetypes/Curve.java @@ -56,7 +56,7 @@ public Curve() { * Note that if the implied gradient entering the control point is different from the implied gradient exiting it then * the gradient may sharply change (but the line itself will remain continuous). * - * Between each pair of control points acts as an independent cubic Bézier curve defined by the following: + * Between each pair of control points acts as an independent cubic Bézier-like curve defined by the following: * * anchor 1 - the 'point' of the first control point (the line will pass through this point) * intermediate point 1 - the 'out' of the first control point (the line may not go through this point but it controls the initial direction the line exits anchor 1) @@ -67,6 +67,9 @@ public Curve() { * but being smoothed using a quadratic curve such that it may not actually touch the intermediate points. * * Note; if this is the first control point the in doesn't matter and if its the last control point the out doesn't matter + * + * Note; these are Bézier-like curve but not Bézier curves due to the requirement that X must always move forwards + * (as it often represents time) * * @param in * the intermediate point immediately before this anchor point. From b73537e75ecce9800f8f9a5e07553caf1b0400bc Mon Sep 17 00:00:00 2001 From: Richard Tingle <6330028+richardTingle@users.noreply.github.com> Date: Sun, 19 Dec 2021 15:53:35 +0000 Subject: [PATCH 3/4] #5 Restore commented out code, as I now see what it's hinting at; that the X of the control points currently do nothing, but should --- src/main/java/com/epaga/particles/valuetypes/Curve.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/epaga/particles/valuetypes/Curve.java b/src/main/java/com/epaga/particles/valuetypes/Curve.java index 6e3436a..3474b1a 100644 --- a/src/main/java/com/epaga/particles/valuetypes/Curve.java +++ b/src/main/java/com/epaga/particles/valuetypes/Curve.java @@ -118,12 +118,15 @@ public float getValue(float blendTime) { float perc = (blendTime - lastPoint.point.x) / (currentPoint.point.x - lastPoint.point.x); // get the midpoints of the 3 line segments + //float p1x = lastPoint.point.x - ((lastPoint.point.x - lastPoint.outControlPoint.x) * perc); //what y should be according to the the line from lastPoint.point -> lastPoint.outControlPoint float p1y = lastPoint.point.y - ((lastPoint.point.y - lastPoint.outControlPoint.y) * perc); + //float p2x = lastPoint.outControlPoint.x - ((lastPoint.outControlPoint.x - currentPoint.inControlPoint.x) * perc); //what y should be according to the the line from lastPoint.outControlPoint -> currentPoint.inControlPoint float p2y = lastPoint.outControlPoint.y - ((lastPoint.outControlPoint.y - currentPoint.inControlPoint.y) * perc); + //float p3x = currentPoint.inControlPoint.x - ((currentPoint.inControlPoint.x - currentPoint.point.x) * perc); //what y should be according to the the line from lastPoint.outControlPoint -> currentPoint.inControlPoint float p3y = currentPoint.inControlPoint.y - ((currentPoint.inControlPoint.y - currentPoint.point.y) * perc); From e802f29127139580a3a965ac371ed238392be19b Mon Sep 17 00:00:00 2001 From: Richard Tingle <6330028+richardTingle@users.noreply.github.com> Date: Tue, 21 Dec 2021 11:27:46 +0000 Subject: [PATCH 4/4] #5 Seems that -> isn't allowed in the javadoc (Although intelliJ was fine with it) --- src/main/java/com/epaga/particles/valuetypes/Curve.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/epaga/particles/valuetypes/Curve.java b/src/main/java/com/epaga/particles/valuetypes/Curve.java index 3474b1a..fbb0c69 100644 --- a/src/main/java/com/epaga/particles/valuetypes/Curve.java +++ b/src/main/java/com/epaga/particles/valuetypes/Curve.java @@ -63,7 +63,7 @@ public Curve() { * intermediate point 2 - the 'in' of the second control point (the line may not go through this point but it controls the initial direction the line enters anchor 2) * anchor 2 - the 'point' of the second control point (the line will pass through this point) * - * Instinctively you can think of each section "trying" to go from anchor 1 -> intermediate point 1 -> intermediate point 2 -> anchor 2 + * Instinctively you can think of each section "trying" to go from anchor 1 to intermediate point 1 to intermediate point 2 to anchor 2 * but being smoothed using a quadratic curve such that it may not actually touch the intermediate points. * * Note; if this is the first control point the in doesn't matter and if its the last control point the out doesn't matter @@ -119,15 +119,15 @@ public float getValue(float blendTime) { // get the midpoints of the 3 line segments //float p1x = lastPoint.point.x - ((lastPoint.point.x - lastPoint.outControlPoint.x) * perc); - //what y should be according to the the line from lastPoint.point -> lastPoint.outControlPoint + //what y should be according to the the line from lastPoint.point to lastPoint.outControlPoint float p1y = lastPoint.point.y - ((lastPoint.point.y - lastPoint.outControlPoint.y) * perc); //float p2x = lastPoint.outControlPoint.x - ((lastPoint.outControlPoint.x - currentPoint.inControlPoint.x) * perc); - //what y should be according to the the line from lastPoint.outControlPoint -> currentPoint.inControlPoint + //what y should be according to the the line from lastPoint.outControlPoint to currentPoint.inControlPoint float p2y = lastPoint.outControlPoint.y - ((lastPoint.outControlPoint.y - currentPoint.inControlPoint.y) * perc); //float p3x = currentPoint.inControlPoint.x - ((currentPoint.inControlPoint.x - currentPoint.point.x) * perc); - //what y should be according to the the line from lastPoint.outControlPoint -> currentPoint.inControlPoint + //what y should be according to the the line from lastPoint.outControlPoint to currentPoint.inControlPoint float p3y = currentPoint.inControlPoint.y - ((currentPoint.inControlPoint.y - currentPoint.point.y) * perc); // now get the midpoints of the two segments