Skip to content

Commit

Permalink
Remove java.desktop dependency from Code API.
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcsmith-net committed Oct 24, 2023
1 parent fc2b2a8 commit 52b39b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion praxiscore-code/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module org.praxislive.code {

requires java.compiler;
requires java.desktop;

requires transitive org.praxislive.core;
requires org.praxislive.base;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.praxislive.code.userapi;

import java.awt.geom.Point2D;
import java.util.ArrayList;

/**
Expand All @@ -47,6 +46,10 @@
*/
final class SplineEasing implements Easing {

private record Point(double x, double y) {

}

// Note: (x0,y0) and (x1,y1) are implicitly (0, 0) and (1,1) respectively
private double x1, y1, x2, y2;
private ArrayList lengths = new ArrayList();
Expand Down Expand Up @@ -78,15 +81,15 @@ public SplineEasing(double x1, double y1, double x2, double y2) {
double prevY = 0.0f;
double prevLength = 0.0f; // cumulative length
for (double t = 0.01f; t <= 1.0f; t += .01f) {
Point2D.Double xy = getXY(t);
Point xy = getXY(t);
double length = prevLength
+ (double) Math.sqrt((xy.x - prevX) * (xy.x - prevX)
+ (xy.y - prevY) * (xy.y - prevY));
+ (double) Math.sqrt((xy.x() - prevX) * (xy.x() - prevX)
+ (xy.y() - prevY) * (xy.y() - prevY));
LengthItem lengthItem = new LengthItem(length, t);
lengths.add(lengthItem);
prevLength = length;
prevX = xy.x;
prevY = xy.y;
prevX = xy.x();
prevY = xy.y();
}
// Now calculate the fractions so that we can access the lengths
// array with values in [0,1]. prevLength now holds the total
Expand All @@ -108,24 +111,21 @@ public SplineEasing(double x1, double y1, double x2, double y2) {
*
* @param t parametric value for spline calculation
*/
private Point2D.Double getXY(double t) {
Point2D.Double xy;
private Point getXY(double t) {
double invT = (1 - t);
double b1 = 3 * t * (invT * invT);
double b2 = 3 * (t * t) * invT;
double b3 = t * t * t;
xy = new Point2D.Double(
return new Point(
(b1 * x1) + (b2 * x2) + b3,
(b1 * y1) + (b2 * y2) + b3);
return xy;
}

/**
* Utility function: When we are evaluating the spline, we only care about
* the Y values. See {@link getXY getXY} for the details.
*/
private double getY(double t) {
Point2D.Double xy;
double invT = (1 - t);
double b1 = 3 * t * (invT * invT);
double b2 = 3 * (t * t) * invT;
Expand Down

0 comments on commit 52b39b9

Please sign in to comment.