Added javadoc

This commit is contained in:
Tinglyyy
2026-02-10 22:30:57 +01:00
parent 59d72537b9
commit 2d47dfc28c
2 changed files with 77 additions and 48 deletions

View File

@@ -102,16 +102,18 @@ public class AnimationPath extends ArrayList<KeyFrame> {
case LINEAR -> switch (nextMethod) { case LINEAR -> switch (nextMethod) {
case LINEAR -> CombinedPathMethod.LINEAR; case LINEAR -> CombinedPathMethod.LINEAR;
case EASE_IN -> CombinedPathMethod.LINEAR_EASE_IN; case EASE_IN -> CombinedPathMethod.LINEAR_EASE_IN;
case EASE_OUT -> CombinedPathMethod.LINEAR_EASE_OUT; // Removed this case, as ease-out doesn't make sense right before a keyframe
// case EASE_OUT -> CombinedPathMethod.LINEAR_EASE_OUT;
default -> throw new IllegalStateException("Unexpected value: " + nextMethod); default -> throw new IllegalStateException("Unexpected value: " + nextMethod);
}; };
case EASE_IN -> switch (nextMethod) { // Removed this case, as ease-in doesn't make sense right after a keyframe
case LINEAR -> CombinedPathMethod.EASE_IN_LINEAR; // case EASE_IN -> switch (nextMethod) {
case EASE_IN -> CombinedPathMethod.EASE_IN; // case LINEAR -> CombinedPathMethod.EASE_IN_LINEAR;
case EASE_OUT -> CombinedPathMethod.EASE_OUT_LINEAR; // case EASE_IN -> CombinedPathMethod.EASE_IN;
default -> throw new IllegalStateException("Unexpected value: " + nextMethod); // case EASE_OUT -> CombinedPathMethod.EASE_OUT_LINEAR;
}; // default -> throw new IllegalStateException("Unexpected value: " + nextMethod);
// };
case EASE_OUT -> switch (nextMethod) { case EASE_OUT -> switch (nextMethod) {
case LINEAR -> CombinedPathMethod.EASE_OUT_LINEAR; case LINEAR -> CombinedPathMethod.EASE_OUT_LINEAR;
@@ -122,57 +124,37 @@ public class AnimationPath extends ArrayList<KeyFrame> {
default -> throw new IllegalStateException("Unexpected value: " + currentMethod); default -> throw new IllegalStateException("Unexpected value: " + currentMethod);
}; };
boolean overHalf = transition > 0.5; double threshold = Math.min(current.transition(), next.transition());
if(overHalf) boolean thresholdReached;
if(current.transition() < next.transition())
thresholdReached = transition > threshold;
else
thresholdReached = transition <= next.transition();
if(thresholdReached)
transition = 2 * transition - 1; transition = 2 * transition - 1;
transition = switch (method) { transition = switch (method) {
case LINEAR -> transition; case LINEAR -> transition;
case LINEAR_EASE_IN -> overHalf ? easeIn(subIterator) : transition; case LINEAR_EASE_IN -> thresholdReached ? easeIn(subIterator) : transition;
case EASE_IN -> easeIn(subIterator); // case EASE_IN -> easeIn(subIterator);
case EASE_IN_LINEAR -> overHalf ? transition : easeIn(subIterator);
case LINEAR_EASE_OUT -> overHalf ? easeOut(subIterator) : transition;
case EASE_OUT -> easeOut(subIterator); case EASE_OUT -> easeOut(subIterator);
case EASE_OUT_LINEAR -> overHalf ? transition : easeOut(subIterator); case EASE_OUT_LINEAR -> thresholdReached ? transition : easeOut(subIterator);
case EASE_OUT_AND_IN -> overHalf ? easeOut(subIterator) : easeIn(subIterator); case EASE_OUT_AND_IN -> thresholdReached ? easeOut(subIterator) : easeIn(subIterator);
}; };
System.out.println(method + " " + transition + " - linear: " + linear(subIterator)); System.out.println(method + " " + transition + " - linear: " + linear(subIterator));
return inBetween(current, next, transition, overHalf); return inBetween(current, next, transition, thresholdReached);
// KeyFrame.PathMethod method;
//
// // Translate EASE_IN_AND_OUT to its respective currently relevant counterpart
//
// //TODO: non-linear keyframes can't behandled this way. This just makes it bug around
//
// if(transition < 0.5)
// method = current.pathMethod().equals(KeyFrame.PathMethod.EASE_IN_AND_OUT) ?
// KeyFrame.PathMethod.EASE_OUT : current.pathMethod();
// else
// method = next.pathMethod().equals(KeyFrame.PathMethod.EASE_IN_AND_OUT) ?
// KeyFrame.PathMethod.EASE_OUT : next.pathMethod();
//
// // Else-case would be linear, which doesn't change anything
//
// if(method.equals(KeyFrame.PathMethod.EASE_IN))
// transition = this.easeIn(subIterator);
//
// else if(method.equals(KeyFrame.PathMethod.EASE_OUT))
// transition = this.easeOut(subIterator);
//
// return inBetween(current, next, transition, method);
} }
@@ -324,9 +306,7 @@ public class AnimationPath extends ArrayList<KeyFrame> {
private enum CombinedPathMethod { private enum CombinedPathMethod {
LINEAR, LINEAR,
LINEAR_EASE_IN, LINEAR_EASE_IN,
EASE_IN, // EASE_IN,
EASE_IN_LINEAR,
LINEAR_EASE_OUT,
EASE_OUT, EASE_OUT,
EASE_OUT_LINEAR, EASE_OUT_LINEAR,
EASE_OUT_AND_IN; EASE_OUT_AND_IN;

View File

@@ -7,18 +7,67 @@ package org.openautonomousconnection.oacswing.animated;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public record KeyFrame(Point position, int width, int height, PathMethod pathMethod) { /**
* Record that contains certain vectors and factors for animating in {@link AnimatedComponent}
* @param position positional vector (where is the object at this moment?)
* @param width first transformational vector (how wide is the object at this moment)
* @param height second transformational vector (how tall is the object at this moment)
* @param pathMethod how the path from this KeyFrame to the next should look like
* @param transition adds to pathMethod in how much of the path should be defined by this decision (default 0% for linear and 50% for all other methods)
*/
public record KeyFrame(Point position, int width, int height, PathMethod pathMethod, double transition) {
public KeyFrame(Point position, int width, int height) { /**
this(position, width, height, PathMethod.LINEAR); * Record that contains certain vectors and factors for animating in {@link AnimatedComponent}.
* @param position positional vector (where is the object at this moment?)
* @param width first transformational vector (how wide is the object at this moment)
* @param height second transformational vector (how tall is the object at this moment)
* @param pathMethod how the path from this KeyFrame to the next should look like
*/
public KeyFrame(Point position, int width, int height, PathMethod pathMethod) {
this(position, width, height, pathMethod, pathMethod.equals(PathMethod.LINEAR) ? 0 : 0.5);
} }
/**
* Record that contains certain vectors and factors for animating in {@link AnimatedComponent}.
* Defaults pathMethod to linear and transition percentage to 0%
* @param position positional vector (where is the object at this moment?)
* @param width first transformational vector (how wide is the object at this moment)
* @param height second transformational vector (how tall is the object at this moment)
*/
public KeyFrame(Point position, int width, int height) {
this(position, width, height, PathMethod.LINEAR, 0);
}
/**
* Record that contains certain vectors and factors for animating in {@link AnimatedComponent}.
* @param component component that contains necessary vectors
* @param pathMethod how the path from this KeyFrame to the next should look like
* @param transition adds to pathMethod in how much of the path should be defined by this decision (default 50%)
*/
public KeyFrame(JComponent component, PathMethod pathMethod, double transition) {
this(
new Point(component.getX(), component.getY()),
component.getBounds().width, component.getBounds().height, pathMethod, transition);
}
/**
* Record that contains certain vectors and factors for animating in {@link AnimatedComponent}.
* @param component component that contains necessary vectors
* @param pathMethod how the path from this KeyFrame to the next should look like
*/
public KeyFrame(JComponent component, PathMethod pathMethod) { public KeyFrame(JComponent component, PathMethod pathMethod) {
this( this(
new Point(component.getX(), component.getY()), new Point(component.getX(), component.getY()),
component.getBounds().width, component.getBounds().height, pathMethod); component.getBounds().width, component.getBounds().height, pathMethod,
pathMethod.equals(PathMethod.LINEAR) ? 0 : 0.5);
} }
/**
* Record that contains certain vectors and factors for animating in {@link AnimatedComponent}.
* Defaults pathMethod to linear and transition percentage to 50%
* @param component component that contains necessary vectors
*/
public KeyFrame(JComponent component) { public KeyFrame(JComponent component) {
this(component, PathMethod.LINEAR); this(component, PathMethod.LINEAR);
} }