From 26c5193fdd876d0aa9db9cc1defe33a0bd9b49c2 Mon Sep 17 00:00:00 2001 From: Karl Zschiebsch Date: Wed, 5 Jul 2023 19:57:35 +0200 Subject: [PATCH] Remove unused dependencies --- pom.xml | 28 +- src/main/java/io/scvis/entity/Animation.java | 10 + src/main/java/io/scvis/entity/Damageble.java | 12 +- .../java/io/scvis/entity/Destroyable.java | 2 + src/main/java/io/scvis/entity/Parent.java | 2 + src/main/java/io/scvis/geometry/Area.java | 57 ++-- src/main/java/io/scvis/geometry/Border2D.java | 22 +- src/main/java/io/scvis/geometry/Border3D.java | 9 +- .../java/io/scvis/geometry/Kinetic2D.java | 113 +++++--- .../java/io/scvis/geometry/Kinetic3D.java | 95 +++++-- src/main/java/io/scvis/geometry/Layout2D.java | 80 ++++-- src/main/java/io/scvis/geometry/Layout3D.java | 101 ++++++-- .../io/scvis/geometry/Positionable2D.java | 17 +- .../io/scvis/geometry/Positionable3D.java | 17 +- src/main/java/io/scvis/geometry/Shape.java | 243 ++++++++++++------ src/main/java/io/scvis/geometry/Vector2D.java | 16 +- src/main/java/io/scvis/geometry/Vector3D.java | 15 +- .../java/io/scvis/proto/Corresponding.java | 1 + .../java/io/scvis/proto/ExchangeHelper.java | 5 - .../java/io/scvis/proto/Identifiable.java | 4 - src/main/java/io/scvis/proto/Mapper.java | 6 +- src/main/java/io/scvis/proto/Reference.java | 3 +- 22 files changed, 566 insertions(+), 292 deletions(-) diff --git a/pom.xml b/pom.xml index 3d1dd89..504a80b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 io.scvis scvis @@ -12,33 +14,12 @@ ${project.javaVersion} + com.google.code.findbugs jsr305 3.0.2 - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - 2.14.1 - - - - org.slf4j - slf4j-api - 2.0.7 - - - org.slf4j - slf4j-simple - 2.0.7 - - - org.pf4j - pf4j-update - 2.3.0 - org.junit.jupiter @@ -69,7 +50,6 @@ - \ No newline at end of file diff --git a/src/main/java/io/scvis/entity/Animation.java b/src/main/java/io/scvis/entity/Animation.java index ffd2ed7..d515496 100644 --- a/src/main/java/io/scvis/entity/Animation.java +++ b/src/main/java/io/scvis/entity/Animation.java @@ -2,6 +2,11 @@ import javax.annotation.OverridingMethodsMustInvokeSuper; +/** + * The Animation interface represents an entity that can be animated. + * + * @author karlz + */ public interface Animation extends Entity { @OverridingMethodsMustInvokeSuper @@ -10,5 +15,10 @@ default void update(double deltaT) { animate(deltaT); } + /** + * This method is called to perform the animation based on the elapsed time. + * + * @param deltaT The elapsed time since the last update. + */ void animate(double deltaT); } diff --git a/src/main/java/io/scvis/entity/Damageble.java b/src/main/java/io/scvis/entity/Damageble.java index 0f3493f..43af6f8 100644 --- a/src/main/java/io/scvis/entity/Damageble.java +++ b/src/main/java/io/scvis/entity/Damageble.java @@ -1,6 +1,16 @@ package io.scvis.entity; -public interface Damageble { +/** + * The Damageble interface represents an entity that can be damaged. + * + * @author karlz + */ +public interface Damageble extends Destroyable { + /** + * This method is called to apply damage to the entity. + * + * @param damage The amount of damage to be applied. + */ void damage(double damage); } diff --git a/src/main/java/io/scvis/entity/Destroyable.java b/src/main/java/io/scvis/entity/Destroyable.java index cfee8f5..8aefba9 100644 --- a/src/main/java/io/scvis/entity/Destroyable.java +++ b/src/main/java/io/scvis/entity/Destroyable.java @@ -2,6 +2,8 @@ /** * The Destroyable interface represents an object that can be destroyed. + * + * @author karlz */ public interface Destroyable { diff --git a/src/main/java/io/scvis/entity/Parent.java b/src/main/java/io/scvis/entity/Parent.java index a704363..355ab4b 100644 --- a/src/main/java/io/scvis/entity/Parent.java +++ b/src/main/java/io/scvis/entity/Parent.java @@ -6,6 +6,8 @@ /** * The Parent interface represents an entity that updates its childrens. + * + * @author karlz */ public interface Parent extends Entity { diff --git a/src/main/java/io/scvis/geometry/Area.java b/src/main/java/io/scvis/geometry/Area.java index d1e770d..9a7dbb9 100644 --- a/src/main/java/io/scvis/geometry/Area.java +++ b/src/main/java/io/scvis/geometry/Area.java @@ -5,36 +5,41 @@ import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - import io.scvis.geometry.Shape.Polygon; import io.scvis.proto.Mapper; -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonSerialize -@JsonDeserialize +/** + * The Area class represents a 2D area defined by a collection of borders. + * + * @author karlz + * @see Border2D + */ public final class Area implements Border2D { - @JsonProperty("outsides") - @Nonnull - private final List outsides; - @JsonProperty("insides") - @Nonnull - private final List insides; - @JsonCreator - public Area(@JsonProperty("outsides") List outsides, - @JsonProperty("insides") List insides) { + private static final long serialVersionUID = 3359561327999324550L; + + private final @Nonnull List outsides; + private final @Nonnull List insides; + + /** + * Constructs an Area object with the given outside and inside borders. + * + * @param outsides The list of outside borders. + * @param insides The list of inside borders. + */ + public Area(@Nonnull List outsides, @Nonnull List insides) { this.outsides = outsides; this.insides = insides; } - public Area(Border2D border2D) { - outsides = List.of(border2D); - insides = List.of(); + /** + * Constructs an Area object with a single border. + * + * @param border2D The single border of the area. + */ + public Area(@Nonnull Border2D border2D) { + outsides = new ArrayList<>(List.of(border2D)); + insides = new ArrayList<>(); } @Override @@ -83,11 +88,21 @@ public Vector2D centroid() { return new Polygon(centers).centroid(); } + /** + * Returns the list of outside borders of the area. + * + * @return The list of outside borders. + */ @Nonnull public List getOutsides() { return outsides; } + /** + * Returns the list of inside borders of the area. + * + * @return The list of inside borders. + */ @Nonnull public List getInsides() { return insides; diff --git a/src/main/java/io/scvis/geometry/Border2D.java b/src/main/java/io/scvis/geometry/Border2D.java index 6628507..481fd0a 100644 --- a/src/main/java/io/scvis/geometry/Border2D.java +++ b/src/main/java/io/scvis/geometry/Border2D.java @@ -1,19 +1,10 @@ package io.scvis.geometry; +import java.io.Serializable; + import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonSubTypes.Type; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import io.scvis.geometry.Shape.Circle; -import io.scvis.geometry.Shape.Polygon; -import io.scvis.geometry.Shape.Rectangle; - /** * The Border2D interface represents a 2D border or shape in geometry. It * provides methods for containment, intersection, translation, rotation, and @@ -21,14 +12,7 @@ * * @author karlz */ -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") -@JsonSubTypes({ @Type(value = Polygon.class, name = "Polygon"), @Type(value = Rectangle.class, name = "Rectangle"), - @Type(value = Circle.class, name = "Circle"), @Type(value = Area.class, name = "Area"), - @Type(value = Kinetic2D.class, name = "Kinetic") }) -@JsonSerialize -@JsonDeserialize -public interface Border2D { +public interface Border2D extends Serializable { /** * Checks if the specified point is contained within the border. * diff --git a/src/main/java/io/scvis/geometry/Border3D.java b/src/main/java/io/scvis/geometry/Border3D.java index 8318236..69d17e8 100644 --- a/src/main/java/io/scvis/geometry/Border3D.java +++ b/src/main/java/io/scvis/geometry/Border3D.java @@ -1,11 +1,10 @@ package io.scvis.geometry; +import java.io.Serializable; + import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - /** * The Border3D interface represents a 3D border or shape in geometry. It * provides methods for containment, intersection, translation, rotation, and @@ -13,9 +12,7 @@ * * @author karlz */ -@JsonSerialize -@JsonDeserialize -public interface Border3D { +public interface Border3D extends Serializable { /** * Checks if the specified point is contained within the border. * diff --git a/src/main/java/io/scvis/geometry/Kinetic2D.java b/src/main/java/io/scvis/geometry/Kinetic2D.java index 8dc7c60..080f017 100644 --- a/src/main/java/io/scvis/geometry/Kinetic2D.java +++ b/src/main/java/io/scvis/geometry/Kinetic2D.java @@ -3,88 +3,143 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - import io.scvis.entity.Kinetic; import io.scvis.proto.Identifiable; -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonSerialize -@JsonDeserialize +/** + * The Kinetic2D abstract class represents a 2D kinetic entity with motion and + * velocity. + * + * @author karlz + */ public abstract class Kinetic2D extends Layout2D implements Kinetic, Identifiable { - @JsonProperty(value = "acceleration", index = 17) - private Vector2D acceleration = Vector2D.ZERO; - @JsonProperty(value = "velocity", index = 18) - private Vector2D velocity = Vector2D.ZERO; - - @JsonCreator - public Kinetic2D(@JsonProperty("local") @Nonnull Border2D local, - @JsonProperty("position") @Nonnull Vector2D position, @JsonProperty("rotation") double rotation, - @JsonProperty("acceleration") Vector2D acceleration, @JsonProperty("velocity") Vector2D velocity) { + private static final long serialVersionUID = -426988271831404911L; + + private @Nonnull Vector2D acceleration = Vector2D.ZERO; + private @Nonnull Vector2D velocity = Vector2D.ZERO; + + /** + * Constructs a Kinetic2D object with the specified local border, position, + * rotation, acceleration, and velocity. + * + * @param local The local border of the kinetic entity. + * @param position The position of the kinetic entity. + * @param rotation The rotation angle of the kinetic entity. + * @param acceleration The acceleration vector of the kinetic entity. + * @param velocity The velocity vector of the kinetic entity. + */ + protected Kinetic2D(@Nonnull Border2D local, @Nonnull Vector2D position, double rotation, Vector2D acceleration, + Vector2D velocity) { super(local, position, rotation); this.acceleration = acceleration; this.velocity = velocity; } - @JsonProperty(value = "destination", index = 16) @Nullable private Vector2D destination = null; + /** + * Checks if the kinetic entity has a destination. + * + * @return True if the kinetic entity has a destination, false otherwise. + */ public boolean hasDestination() { return destination != null; } + /** + * Returns the destination vector of the kinetic entity. + * + * @return The destination vector of the kinetic entity. + */ @Nonnull public Vector2D getDestination() { - final Vector2D destination = this.destination; - if (destination != null) - return destination; + final Vector2D checked = this.destination; + if (checked != null) + return checked; return getPosition(); } + /** + * Sets the destination vector of the kinetic entity. + * + * @param destination The destination vector to set. + */ public void setDestination(@Nullable Vector2D destination) { this.destination = destination; } - @JsonIgnore @Nullable private Border2D target = null; + /** + * Checks if the kinetic entity has a target border. + * + * @return True if the kinetic entity has a target border, false otherwise. + */ public boolean hasTarget() { return target != null; } + /** + * Returns the target border of the kinetic entity. + * + * @return The target border of the kinetic entity. + */ @Nonnull public Border2D getTarget() { - final Border2D target = this.target; - if (target != null) - return target; + final Border2D checked = this.target; + if (checked != null) + return checked; return this; } + /** + * Sets the target border of the kinetic entity. + * + * @param target The target border to set. + */ public void setTarget(@Nullable Border2D target) { this.target = target; } + /** + * + * Returns the acceleration vector of the kinetic entity. + * + * @return The acceleration vector of the kinetic entity. + */ + @Nonnull public Vector2D getAcceleration() { return acceleration; } - public void setAcceleration(Vector2D acceleration) { + /** + * Sets the acceleration vector of the kinetic entity. + * + * @param acceleration The acceleration vector to set. + */ + public void setAcceleration(@Nonnull Vector2D acceleration) { this.acceleration = acceleration; } + /** + * Returns the velocity vector of the kinetic entity. + * + * @return The velocity vector of the kinetic entity. + */ + @Nonnull public Vector2D getVelocity() { return velocity; } - public void setVelocity(Vector2D velocity) { + /** + * Sets the velocity vector of the kinetic entity. + * + * @param velocity The velocity vector to set. + */ + public void setVelocity(@Nonnull Vector2D velocity) { this.velocity = velocity; } } diff --git a/src/main/java/io/scvis/geometry/Kinetic3D.java b/src/main/java/io/scvis/geometry/Kinetic3D.java index 811aa06..c567f4c 100644 --- a/src/main/java/io/scvis/geometry/Kinetic3D.java +++ b/src/main/java/io/scvis/geometry/Kinetic3D.java @@ -3,38 +3,57 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - import io.scvis.entity.Kinetic; import io.scvis.proto.Identifiable; +/** + * The Kinetic3D abstract class represents a 3D kinetic entity with motion and + * velocity. + * + * @author karlz + */ public abstract class Kinetic3D extends Layout3D implements Kinetic, Identifiable { - @JsonProperty(value = "acceleration", index = 17) - private Vector3D acceleration = Vector3D.ZERO; - @JsonProperty(value = "velocity", index = 18) - private Vector3D velocity = Vector3D.ZERO; - - @JsonCreator - protected Kinetic3D(@JsonProperty("local") @Nonnull Border3D local, - @JsonProperty("position") @Nonnull Vector3D position, @JsonProperty("rotationA") double rotationA, - @JsonProperty("rotationB") double rotationB, @JsonProperty("acceleration") Vector3D acceleration, - @JsonProperty("velocity") Vector3D velocity) { + private static final long serialVersionUID = -6421069856222021884L; + + private @Nonnull Vector3D acceleration = Vector3D.ZERO; + private @Nonnull Vector3D velocity = Vector3D.ZERO; + + /** + * Constructs a Kinetic3D object with the specified local border, position, + * rotation angles, acceleration, and velocity. + * + * @param local The local border of the kinetic entity. + * @param position The position of the kinetic entity. + * @param rotationA The rotation angle A of the kinetic entity. + * @param rotationB The rotation angle B of the kinetic entity. + * @param acceleration The acceleration vector of the kinetic entity. + * @param velocity The velocity vector of the kinetic entity. + */ + protected Kinetic3D(@Nonnull Border3D local, @Nonnull Vector3D position, double rotationA, double rotationB, + @Nonnull Vector3D acceleration, @Nonnull Vector3D velocity) { super(local, position, rotationA, rotationB); this.acceleration = acceleration; this.velocity = velocity; } - @JsonProperty(value = "destination", index = 16) @Nullable private Vector3D destination = null; + /** + * Checks if the kinetic entity has a destination. + * + * @return True if the kinetic entity has a destination, false otherwise. + */ public boolean hasDestination() { return destination != null; } + /** + * Returns the destination vector of the kinetic entity. + * + * @return The destination vector of the kinetic entity. + */ @Nonnull public Vector3D getDestination() { // Check for nonnull @@ -44,18 +63,32 @@ public Vector3D getDestination() { return getPosition(); } + /** + * Sets the destination vector of the kinetic entity. + * + * @param destination The destination vector to set. + */ public void setDestination(@Nullable Vector3D destination) { this.destination = destination; } - @JsonIgnore @Nullable private Border3D target = null; + /** + * Checks if the kinetic entity has a target border. + * + * @return True if the kinetic entity has a target border, false otherwise. + */ public boolean hasTarget() { return target != null; } + /** + * Returns the target border of the kinetic entity. + * + * @return The target border of the kinetic entity. + */ @Nonnull public Border3D getTarget() { // Check for nonnull @@ -65,23 +98,51 @@ public Border3D getTarget() { return this; } + /** + * Sets the target border of the kinetic entity. + * + * @param target The target border to set. + */ public void setTarget(@Nullable Border3D target) { this.target = target; } + /** + * Returns the acceleration vector of the kinetic entity. + * + * @return The acceleration vector of the kinetic entity. + */ + @Nonnull public Vector3D getAcceleration() { return acceleration; } + /** + * Sets the acceleration vector of the kinetic entity. + * + * @param acceleration The acceleration vector to set. + */ + @Nonnull public void setAcceleration(Vector3D acceleration) { this.acceleration = acceleration; } + /** + * Returns the velocity vector of the kinetic entity. + * + * @return The velocity vector of the kinetic entity. + */ + @Nonnull public Vector3D getVelocity() { return velocity; } - public void setVelocity(Vector3D velocity) { + /** + * Sets the velocity vector of the kinetic entity. + * + * @param velocity The velocity vector to set. + */ + public void setVelocity(@Nonnull Vector3D velocity) { this.velocity = velocity; } } diff --git a/src/main/java/io/scvis/geometry/Layout2D.java b/src/main/java/io/scvis/geometry/Layout2D.java index c0a203b..de3b98c 100644 --- a/src/main/java/io/scvis/geometry/Layout2D.java +++ b/src/main/java/io/scvis/geometry/Layout2D.java @@ -3,35 +3,32 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonSerialize -@JsonDeserialize -public class Layout2D implements Border2D, Cloneable { - - @JsonProperty(value = "local", index = 5) - @Nonnull - private final Border2D local; +/** + * The Layout2D class represents a 2D layout with position and rotation. + * + * @author karlz + */ +public class Layout2D implements Border2D, Positionable2D, Cloneable { + + private static final long serialVersionUID = 7896521163278027263L; + + private final @Nonnull Border2D local; - @JsonIgnore @CheckForNull private Border2D parent; - @JsonProperty(value = "position", index = 6) - @Nonnull - private Vector2D position = Vector2D.ZERO; - @JsonProperty(value = "rotation", index = 7) + private @Nonnull Vector2D position; private double rotation = 0; - @JsonCreator - public Layout2D(@JsonProperty("local") @Nonnull Border2D local, - @JsonProperty("position") @Nonnull Vector2D position, @JsonProperty("rotation") double rotation) { + /** + * Constructs a Layout2D object with the specified local border, position, and + * rotation. + * + * @param local The local border of the layout. + * @param position The position of the layout. + * @param rotation The rotation angle of the layout. + */ + public Layout2D(@Nonnull Border2D local, @Nonnull Vector2D position, double rotation) { this.local = local; this.position = position; this.rotation = rotation; @@ -42,10 +39,21 @@ public Layout2D clone() { return new Layout2D(local); } + /** + * Constructs a Layout2D object with the specified local border. + * + * @param local The local border of the layout. + */ public Layout2D(@Nonnull Border2D local) { this.local = local; + this.position = Vector2D.ZERO; } + /** + * + * Applies the transformation to the layout. Recalculates the parent border if + * there are changes. + */ public void applyTransformation() { if (changed || parent == null) { this.parent = local.translate(position).rotate(rotation); @@ -65,7 +73,6 @@ public boolean intersects(@Nonnull Border2D border2D) { return parent.intersects(border2D); } - @JsonIgnore protected boolean changed; @Override @@ -97,31 +104,52 @@ public Vector2D centroid() { return parent.centroid(); } - @JsonIgnore + /** + * Returns the local border of the layout. + * + * @return The local border of the layout. + */ public Border2D getBorderInLocal() { return local; } - @JsonIgnore + /** + * Returns the parent border of the layout. Applies the transformation before + * returning the parent border. + * + * @return The parent border of the layout. + */ public Border2D getBorderInParent() { applyTransformation(); return parent; } + @Override @Nonnull public Vector2D getPosition() { return position; } + @Override public void setPosition(@Nonnull Vector2D position) { this.changed = true; this.position = position; } + /** + * Returns the rotation angle of the layout. + * + * @return The rotation angle of the layout. + */ public double getRotation() { return rotation; } + /** + * Sets the rotation angle of the layout. Sets the changed flag to true. + * + * @param rotation The rotation angle to set. + */ public void setRotation(double rotation) { this.changed = true; this.rotation = rotation; diff --git a/src/main/java/io/scvis/geometry/Layout3D.java b/src/main/java/io/scvis/geometry/Layout3D.java index 408acc3..412e2a2 100644 --- a/src/main/java/io/scvis/geometry/Layout3D.java +++ b/src/main/java/io/scvis/geometry/Layout3D.java @@ -1,32 +1,40 @@ package io.scvis.geometry; +import java.io.Serializable; + import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; +/** + * The Layout3D class represents a 3D layout with position and rotations around + * two axes. + * + * @author karlz + */ +public class Layout3D implements Border3D, Cloneable, Serializable { + + private static final long serialVersionUID = -4505235043373481208L; -public class Layout3D implements Border3D, Cloneable { - @JsonProperty(value = "local", index = 5) @Nonnull private final Border3D local; - @JsonIgnore @CheckForNull private transient Border3D parent; - @JsonProperty(value = "position", index = 6) @Nonnull - private Vector3D position = Vector3D.ZERO; - @JsonProperty(value = "rotationA", index = 7) - private double rotationA = 0; - @JsonProperty(value = "rotationB", index = 7) - private double rotationB = 0; - - @JsonCreator - public Layout3D(@JsonProperty("local") @Nonnull Border3D local, - @JsonProperty("position") @Nonnull Vector3D position, @JsonProperty("rotationA") double rotationA, - @JsonProperty("rotationB") double rotationB) { + private Vector3D position; + private double rotationA; + private double rotationB; + + /** + * Constructs a Layout3D object with the specified local border, position, and + * rotations. + * + * @param local The local border of the layout. + * @param position The position of the layout. + * @param rotationA The rotation around the first axis. + * @param rotationB The rotation around the second axis. + */ + public Layout3D(@Nonnull Border3D local, @Nonnull Vector3D position, double rotationA, double rotationB) { this.local = local; this.position = position; this.rotationA = rotationA; @@ -38,10 +46,21 @@ public Layout3D clone() { return new Layout3D(local); } + /** + * + * Constructs a Layout3D object with the specified local border. + * + * @param local The local border of the layout. + */ public Layout3D(@Nonnull Border3D local) { this.local = local; + this.position = Vector3D.ZERO; } + /** + * Applies the transformation to the layout. Recalculates the parent border if + * there are changes. + */ public void applyTransformation() { if (changed || parent == null) { this.parent = local.translate(position).rotate(rotationA, rotationB); @@ -61,7 +80,6 @@ public boolean intersects(@Nonnull Border3D border3D) { return parent.intersects(border3D); } - @JsonIgnore protected transient boolean changed; @Override @@ -94,40 +112,83 @@ public Vector3D centroid() { return parent.centroid(); } - @JsonIgnore + /** + * Returns the local border of the layout. + * + * @return The local border of the layout. + */ + @Nonnull public Border3D getBorderInLocal() { return local; } - @JsonIgnore + /** + * Returns the parent border of the layout. Applies the transformation before + * returning the parent border. + * + * @return The parent border of the layout. + */ + @Nonnull public Border3D getBorderInParent() { applyTransformation(); return parent; } + /** + * Returns the position of the layout. + * + * @return The position of the layout. + */ @Nonnull public Vector3D getPosition() { return position; } + /** + * Sets the position of the layout. Sets the changed flag to true. + * + * @param position The position to set. + */ public void setPosition(@Nonnull Vector3D position) { this.changed = true; this.position = position; } + /** + * Returns the rotation angle around the first axis of the layout. + * + * @return The rotation angle around the first axis of the layout. + */ public double getRotationA() { return rotationA; } + /** + * Sets the rotation angle around the first axis of the layout. Sets the changed + * flag to true. + * + * @param rotationA The rotation angle to set. + */ public void setRotationA(double rotationA) { this.changed = true; this.rotationA = rotationA; } + /** + * Returns the rotation angle around the second axis of the layout. + * + * @return The rotation angle around the second axis of the layout. + */ public double getRotationB() { return rotationB; } + /** + * Sets the rotation angle around the second axis of the layout. Sets the + * changed flag to true. + * + * @param rotationB The rotation angle to set. + */ public void setRotationB(double rotationB) { this.changed = true; this.rotationB = rotationB; diff --git a/src/main/java/io/scvis/geometry/Positionable2D.java b/src/main/java/io/scvis/geometry/Positionable2D.java index fa0947d..7bcf6ba 100644 --- a/src/main/java/io/scvis/geometry/Positionable2D.java +++ b/src/main/java/io/scvis/geometry/Positionable2D.java @@ -2,10 +2,25 @@ import javax.annotation.Nonnull; +/** + * A positionable is an object or entity that has the capability of being placed + * or located in various positions within a given 2d space or coordinate system. + * + * @author karlz + */ public interface Positionable2D { - + /** + * Returns the position of the object in 2D space. + * + * @return The position of the object. + */ @Nonnull Vector2D getPosition(); + /** + * Sets the position of the object in 2D space. + * + * @param position The position to set. + */ void setPosition(@Nonnull Vector2D position); } diff --git a/src/main/java/io/scvis/geometry/Positionable3D.java b/src/main/java/io/scvis/geometry/Positionable3D.java index 0f9da33..8680ecd 100644 --- a/src/main/java/io/scvis/geometry/Positionable3D.java +++ b/src/main/java/io/scvis/geometry/Positionable3D.java @@ -2,10 +2,25 @@ import javax.annotation.Nonnull; +/** + * A positionable is an object or entity that has the capability of being placed + * or located in various positions within a given 3d space or coordinate system. + * + * @author karlz + */ public interface Positionable3D { - + /** + * Returns the position of the object in 3D space. + * + * @return The position of the object. + */ @Nonnull Vector3D getPosition(); + /** + * Sets the position of the object in 3D space. + * + * @param position The position to set. + */ void setPosition(@Nonnull Vector3D position); } diff --git a/src/main/java/io/scvis/geometry/Shape.java b/src/main/java/io/scvis/geometry/Shape.java index 7e9689d..f5b69b1 100644 --- a/src/main/java/io/scvis/geometry/Shape.java +++ b/src/main/java/io/scvis/geometry/Shape.java @@ -1,31 +1,49 @@ package io.scvis.geometry; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonSerialize -@JsonDeserialize +/** + * In mathematics and geometry, a shape refers to the form or configuration of + * an object or figure. It is a fundamental concept used to describe and + * classify objects based on their physical appearance. + *

+ * A shape in 2D space is a flat, two-dimensional figure that is defined by its + * boundaries or outlines. + * + * @author karlz + */ public abstract class Shape implements Border2D { + private static final long serialVersionUID = 1430329205714811390L; + + /** + * Returns the zero vector. This method is used to define functional interfaces + * such as Supplier. + * + *

+ * Shape::zero + * + * @return the zero vector + */ + private static final Vector2D zero() { + return Vector2D.ZERO; + } + protected Vector2D center; + /** + * Retrieves the center of this shape. + * + * @return the center vector + */ @Nonnull public Vector2D getCenter() { return centroid(); } - @JsonIgnore private transient int hash = 0; @Override @@ -40,26 +58,27 @@ public String toString() { return "UnknownShape [center = " + center + ", class = " + getClass() + ", hash = " + hashCode() + "]"; } - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) - @JsonSerialize - @JsonDeserialize + /** + * Represents a polygon shape. + */ public static class Polygon extends Shape { - @JsonProperty("points") - @Nonnull - private final List points; - @JsonProperty("minX") + + private static final long serialVersionUID = -3362147056076306244L; + + private final @Nonnull List points; private final double minX; - @JsonProperty("minY") private final double minY; - @JsonProperty("maxX") private final double maxX; - @JsonProperty("maxY") private final double maxY; - @JsonCreator - protected Polygon(@JsonProperty("points") @Nonnull List points, @JsonProperty("minX") double minX, - @JsonProperty("minY") double minY, @JsonProperty("maxX") double maxX, - @JsonProperty("maxY") double maxY) { + /** + * Creates a polygon with the given points, minX, minY, . + * + * @param points the points of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + */ + protected Polygon(@Nonnull List points, double minX, double minY, double maxX, double maxY) { this.points = points; this.minX = minX; this.minY = minY; @@ -67,15 +86,32 @@ protected Polygon(@JsonProperty("points") @Nonnull List points, @JsonP this.maxY = maxY; } + /** + * Constructs a polygon with the specified list of points. + * + * @param points the points of the polygon + */ public Polygon(@Nonnull List points) { this.points = points; - minX = pick(points, (a, b) -> (int) (a.getX() - b.getX())).getX(); - minY = pick(points, (a, b) -> (int) (a.getY() - b.getY())).getY(); - maxX = pick(points, (a, b) -> (int) (b.getX() - a.getX())).getX(); - maxY = pick(points, (a, b) -> (int) (b.getY() - a.getY())).getY(); - } - - private static boolean contains(List polygon, Vector2D vector2D) { + minX = points.stream().max((a, b) -> (int) (a.getX() - b.getX())).orElseGet(Shape::zero).getX(); + minY = points.stream().max((a, b) -> (int) (a.getY() - b.getY())).orElseGet(Shape::zero).getY(); + maxX = points.stream().max((a, b) -> (int) (b.getX() - a.getX())).orElseGet(Shape::zero).getX(); + maxY = points.stream().max((a, b) -> (int) (b.getY() - a.getY())).orElseGet(Shape::zero).getY(); + } + + /** + * Checks whether a given vector is inside or outside a simple polygon using the + * Jordan test. + * + * This method counts the number of intersections for a ray passing from the + * exterior of the polygon to any point: If odd, it shows that the point lies + * inside the polygon; if even, the point lies outside the polygon. + * + * @param polygon the list of vectors defining the polygon. + * @param vector2D the vector or point to check. + * @return true if the vector is inside, false otherwise. + */ + public static boolean contains(List polygon, Vector2D vector2D) { boolean inside = false; for (int i = 0; i < polygon.size(); i++) { int j = (i + 1) % polygon.size(); @@ -85,13 +121,19 @@ private static boolean contains(List polygon, Vector2D vector2D) { return inside; } - private static boolean crosses(Vector2D a, Vector2D b, Vector2D vector2D) { + /** + * Checks if a ray passing from the exterior of the polygon crosses a line AB of + * the polygon. + * + * @param a the point a of the line. + * @param b the point b of the line. + * @param vector2D the tested point. + * @return true if the ray crosses the line AB + */ + public static boolean crosses(Vector2D a, Vector2D b, Vector2D vector2D) { if (vector2D.getY() == a.getY() && a.getY() == b.getY()) - if (a.getX() <= vector2D.getX() && vector2D.getX() <= b.getX() - || b.getX() <= vector2D.getX() && vector2D.getX() <= a.getX()) - return true; - else - return false; + return a.getX() <= vector2D.getX() && vector2D.getX() <= b.getX() + || b.getX() <= vector2D.getX() && vector2D.getX() <= a.getX(); if (vector2D.getY() == a.getY() && vector2D.getX() == b.getX()) return true; if (a.getY() > b.getY()) { @@ -103,18 +145,7 @@ private static boolean crosses(Vector2D a, Vector2D b, Vector2D vector2D) { return false; double x = (a.getX() - vector2D.getX()) * (b.getY() - vector2D.getY()) - (a.getY() - vector2D.getY()) * (b.getX() - vector2D.getX()); - if (x < 0) - return false; - else - return true; - } - - private static T pick(List list, Comparator comparator) { - if (list.isEmpty()) - return null; - List temp = new ArrayList<>(list); - temp.sort(comparator); - return temp.get(0); + return (x >= 0); } @Override @@ -131,14 +162,12 @@ public boolean intersects(@Nonnull Border2D border2D) { if (border2D instanceof Polygon) { Polygon poly = (Polygon) border2D; for (Vector2D point : poly.getPoints()) - if (point != null) - if (contains(point)) - return true; + if (point != null && (contains(point))) + return true; } for (Vector2D point : getPoints()) - if (point != null) - if (contains(point)) - return true; + if (point != null && (contains(point))) + return true; return false; } @@ -151,10 +180,10 @@ public Polygon translate(@Nonnull Vector2D v) { @Override @Nonnull public Polygon translate(double x, double y) { - List points = new ArrayList<>(); + List translated = new ArrayList<>(); for (Vector2D point : this.points) - points.add(point.add(x, y)); - return new Polygon(points); + translated.add(point.add(x, y)); + return new Polygon(translated); } @Override @@ -166,11 +195,11 @@ public Polygon rotate(double a) { @Override @Nonnull public Polygon rotate(@Nonnull Vector2D center, double a) { - List points = new ArrayList<>(); + List rotated = new ArrayList<>(); Vector2D centroid = center; for (Vector2D point : this.points) - points.add(point.subtract(centroid).rotate(a).add(centroid)); - return new Polygon(points); + rotated.add(point.subtract(centroid).rotate(a).add(centroid)); + return new Polygon(rotated); } @Override @@ -179,7 +208,8 @@ public Vector2D centroid() { /* Checked */ final Vector2D center = this.center; if (center == null) { - double x = 0, y = 0; + double x = 0; + double y = 0; for (Vector2D vector2D : points) { x += vector2D.getX(); y += vector2D.getY(); @@ -189,6 +219,11 @@ public Vector2D centroid() { return center; } + /** + * Retrieves the points of the polygon. + * + * @return the points of the polygon + */ @Nonnull public List getPoints() { return points; @@ -201,30 +236,38 @@ public String toString() { } } - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) - @JsonSerialize - @JsonDeserialize + /** + * Represents a rectangle shape. + */ public static class Rectangle extends Polygon { - @JsonProperty("width") + + private static final long serialVersionUID = 4703005267556298683L; + private final double width; - @JsonProperty("height") private final double height; - @JsonCreator - protected Rectangle(@JsonProperty("points") @Nonnull List points, @JsonProperty("minX") double minX, - @JsonProperty("minY") double minY, @JsonProperty("maxX") double maxX, @JsonProperty("maxY") double maxY, - @JsonProperty("width") double width, @JsonProperty("height") double height) { - super(points, minX, minY, maxX, maxY); - this.width = width; - this.height = height; - } - - public Rectangle(@Nonnull List points, double width, double height) { + /** + * Creates a rectangle with the given points, width, and height. + * + * @param points the points of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + */ + private Rectangle(@Nonnull List points, double width, double height) { super(points); + if (points.size() != 4) + throw new IllegalArgumentException("A rectangle must always have 4 points, not " + points.size()); this.width = width; this.height = height; } + /** + * Creates a rectangle with the given width and height, with the bottom-left + * corner at (0,0). + * + * @param width the width of the rectangle + * @param height the height of the rectangle + */ public Rectangle(double width, double height) { super(new ArrayList<>(List.of(new Vector2D(0, 0), new Vector2D(width, 0), new Vector2D(width, height), new Vector2D(0, height))), 0, 0, width, height); @@ -232,6 +275,14 @@ public Rectangle(double width, double height) { this.height = height; } + /** + * Creates a rectangle with the given starting and ending coordinates. + * + * @param startX the x-coordinate of the starting point + * @param startY the y-coordinate of the starting point + * @param endX the x-coordinate of the ending point + * @param endY the y-coordinate of the ending point + */ public Rectangle(double startX, double startY, double endX, double endY) { super(new ArrayList<>(List.of(new Vector2D(startX, startY), new Vector2D(endX, startY), new Vector2D(endX, endY), new Vector2D(startX, endY))), startX, startY, endX, endY); @@ -268,10 +319,20 @@ public Rectangle rotate(@Nonnull Vector2D center, double a) { return new Rectangle(points, width, height); } + /** + * Retrieves the width of the rectangle. + * + * @return the width of the rectangle + */ public double getWidth() { return width; } + /** + * Retrieves the height of the rectangle. + * + * @return the height of the rectangle + */ public double getHeight() { return height; } @@ -282,15 +343,22 @@ public String toString() { } } - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) - @JsonSerialize - @JsonDeserialize + /** + * Represents a circle shape. + */ public static class Circle extends Shape { - @JsonProperty("radius") + + private static final long serialVersionUID = 172519286642315942L; + private final double radius; - @JsonCreator - public Circle(@JsonProperty("center") @Nonnull Vector2D center, @JsonProperty("radius") double radius) { + /** + * Creates a circle with the given center and radius. + * + * @param center + * @param radius + */ + public Circle(@Nonnull Vector2D center, double radius) { this.center = center; this.radius = radius; } @@ -333,6 +401,11 @@ public Vector2D centroid() { return center; } + /** + * Retrieves the radius of the circle. + * + * @return the radius of the circle. + */ public double getRadius() { return radius; } diff --git a/src/main/java/io/scvis/geometry/Vector2D.java b/src/main/java/io/scvis/geometry/Vector2D.java index dff47ae..8d464e9 100644 --- a/src/main/java/io/scvis/geometry/Vector2D.java +++ b/src/main/java/io/scvis/geometry/Vector2D.java @@ -4,36 +4,25 @@ import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - /** * The Vector2D class represents a 2-dimensional vector in geometry. * * @author karlz */ -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonSerialize -@JsonDeserialize public class Vector2D implements Serializable { private static final long serialVersionUID = -9019588241960612260L; public static final @Nonnull Vector2D ZERO = new Vector2D(0.0, 0.0); - + /** * The x coordinate of the vector.} */ - @JsonProperty("x") private final double x; /** * The y coordinate of the vector.} */ - @JsonProperty("y") private final double y; /** @@ -42,8 +31,7 @@ public class Vector2D implements Serializable { * @param x the x coordinate * @param y the y coordinate */ - @JsonCreator - public Vector2D(@JsonProperty("x") double x, @JsonProperty("y") double y) { + public Vector2D(double x, double y) { this.x = x; this.y = y; } diff --git a/src/main/java/io/scvis/geometry/Vector3D.java b/src/main/java/io/scvis/geometry/Vector3D.java index 68906eb..cbc6b6c 100644 --- a/src/main/java/io/scvis/geometry/Vector3D.java +++ b/src/main/java/io/scvis/geometry/Vector3D.java @@ -4,20 +4,11 @@ import javax.annotation.Nonnull; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - /** * The Vector3D class represents a 3-dimensional vector in geometry. * * @author karlz */ -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -@JsonSerialize -@JsonDeserialize public class Vector3D implements Serializable { private static final long serialVersionUID = -4200231978633862588L; @@ -27,19 +18,16 @@ public class Vector3D implements Serializable { /** * The x coordinate of the vector.} */ - @JsonProperty("x") private final double x; /** * The y coordinate of the vector.} */ - @JsonProperty("y") private final double y; /** * The z coordinate of the vector.} */ - @JsonProperty("z") private final double z; /** @@ -49,8 +37,7 @@ public class Vector3D implements Serializable { * @param y the y coordinate * @param z the z coordinate */ - @JsonCreator - public Vector3D(@JsonProperty("x") double x, @JsonProperty("y") double y, @JsonProperty("z") double z) { + public Vector3D(double x, double y, double z) { this.x = x; this.y = y; this.z = z; diff --git a/src/main/java/io/scvis/proto/Corresponding.java b/src/main/java/io/scvis/proto/Corresponding.java index 8a0e0a6..6740acd 100644 --- a/src/main/java/io/scvis/proto/Corresponding.java +++ b/src/main/java/io/scvis/proto/Corresponding.java @@ -7,6 +7,7 @@ * associated value of type T. * * @param the type of the associated value + * @author karlz */ public interface Corresponding { /** diff --git a/src/main/java/io/scvis/proto/ExchangeHelper.java b/src/main/java/io/scvis/proto/ExchangeHelper.java index 66c056c..ebe46dc 100644 --- a/src/main/java/io/scvis/proto/ExchangeHelper.java +++ b/src/main/java/io/scvis/proto/ExchangeHelper.java @@ -1,12 +1,7 @@ package io.scvis.proto; -import javax.annotation.Nonnull; - public interface ExchangeHelper { - @Nonnull - Tree getContainer(); - interface DispatchHelper extends ExchangeHelper, Corresponding { } diff --git a/src/main/java/io/scvis/proto/Identifiable.java b/src/main/java/io/scvis/proto/Identifiable.java index 7bcfaa1..ec5d112 100644 --- a/src/main/java/io/scvis/proto/Identifiable.java +++ b/src/main/java/io/scvis/proto/Identifiable.java @@ -1,7 +1,5 @@ package io.scvis.proto; -import com.fasterxml.jackson.annotation.JsonIgnore; - /** * The Identifiable interface represents an object that can be identified with a * id and type. @@ -14,7 +12,6 @@ public interface Identifiable { * * @return the type as a string */ - @JsonIgnore default String getType() { return getClass().getSimpleName(); } @@ -24,7 +21,6 @@ default String getType() { * * @return the ID as a hexadecimal string */ - @JsonIgnore default String getId() { return Integer.toHexString(hashCode()); } diff --git a/src/main/java/io/scvis/proto/Mapper.java b/src/main/java/io/scvis/proto/Mapper.java index b58edc4..76ebb05 100644 --- a/src/main/java/io/scvis/proto/Mapper.java +++ b/src/main/java/io/scvis/proto/Mapper.java @@ -6,18 +6,18 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * A mapper is a function that maps every element of a collection to their * associated value. - * - * @author karlz * * @param the input key type * @param the generated value type - * + * @author karlz * @see Function * @see Collection + * @see Stream */ @FunctionalInterface public interface Mapper extends Function { diff --git a/src/main/java/io/scvis/proto/Reference.java b/src/main/java/io/scvis/proto/Reference.java index c342b8f..038304c 100644 --- a/src/main/java/io/scvis/proto/Reference.java +++ b/src/main/java/io/scvis/proto/Reference.java @@ -4,9 +4,8 @@ * The Reference interface represents an object that can be updated with a new * reference. * - * @author karlz - * * @param the type of the reference + * @author karlz */ public interface Reference { /**