From c68a344a39f481f4fce8ab5db85f34d6aadc2593 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Tue, 20 Jun 2023 09:24:49 -0500 Subject: [PATCH] Update --- {Commons => Bukkit}/.gitignore | 0 {Paper => Bukkit}/build.gradle | 2 +- .../simplexdev/paper/DataConverter.java | 12 +- {Paper => Caravan}/.gitignore | 0 Caravan/build.gradle | 19 ++ .../github/simplexdev/caravan/CaravanAPI.java | 5 + .../github/simplexdev/caravan/api/Graph.java | 4 + .../github/simplexdev/caravan/api/Mapper.java | 12 + .../caravan/api/curve/GenericCurve.java | 31 +++ .../simplexdev/caravan/api/curve/Helix.java | 25 ++ .../simplexdev/caravan/api/curve/Torus.java | 11 + .../simplexdev/caravan/base/Caravan.java | 11 + .../simplexdev/caravan/spatial/Point.java | 65 +++++ Commons/build.gradle | 10 - .../simplexdev/polarize/api/IPoint3D.java | 30 --- .../simplexdev/polarize/math/Point2D.java | 24 -- .../simplexdev/polarize/math/Point3D.java | 30 --- Converter/.gitignore | 42 +++ Converter/build.gradle | 15 ++ .../polarize/api/rotation/IAxisAngle.java | 19 ++ .../polarize/api/rotation}/IQuaternion.java | 4 +- .../polarize/api/spatial}/IPoint2D.java | 9 +- .../polarize/api/spatial/IPoint3D.java | 86 ++++++ .../polarize/api/spatial}/IScalar.java | 4 +- .../polarize/api/spatial}/IVector.java | 33 ++- .../polarize/api/spatial/IVertex.java | 5 + .../simplexdev/polarize/api/units/Phi.java | 8 + .../simplexdev/polarize/api/units/Point.java | 244 ++++++++++++++++++ .../simplexdev/polarize/api/units/Radius.java | 8 + .../simplexdev/polarize/api/units/Theta.java | 8 + .../polarize/cartesian/CartesianUnit.java | 11 +- .../polarize/cartesian/CartesianVector.java | 4 +- .../polarize/cartesian/Point2D.java | 25 ++ .../polarize/cartesian/Point3D.java | 102 ++++++++ .../simplexdev/polarize/cartesian/Vertex.java | 24 ++ .../polarize/log/PolarizeLogger.java | 31 +++ .../simplexdev/polarize/math/AxisAngle.java | 54 ++++ .../simplexdev/polarize/math/Quaternion.java | 2 +- .../polarize/math/ScalarTriple.java | 39 +++ .../math/function/ArchimedeanSpiral.java | 36 +++ .../math/function/FibonacciLattice.java | 28 ++ .../polarize/math/function/Integral.java | 51 ++++ .../polarize/math/function/TriFunction.java | 6 + .../simplexdev/polarize/polar/Delta.java | 0 .../simplexdev/polarize/polar/PolarUnit.java | 0 .../simplexdev/polarize/polar/Scalar.java | 4 +- .../polarize/polar/SphericalUnit.java | 4 +- .../polarize/util/Interpolator.java | 4 +- .../simplexdev/polarize/util/Polarizer.java | 167 ++++++++++-- .../simplexdev/polarize/util/Rotator.java | 93 ++++--- .../simplexdev/polarize/util/Utilities.java | 1 + .../polarize/math/FibonacciLatticeTest.java | 23 ++ .../simplexdev/polarize/math/Point3DTest.java | 20 ++ build.gradle | 2 +- settings.gradle | 6 +- 55 files changed, 1325 insertions(+), 188 deletions(-) rename {Commons => Bukkit}/.gitignore (100%) rename {Paper => Bukkit}/build.gradle (88%) rename {Paper => Bukkit}/src/main/java/io/github/simplexdev/paper/DataConverter.java (87%) rename {Paper => Caravan}/.gitignore (100%) create mode 100644 Caravan/build.gradle create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/CaravanAPI.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/api/Graph.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/api/Mapper.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/GenericCurve.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Helix.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Torus.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/base/Caravan.java create mode 100644 Caravan/src/main/java/io/github/simplexdev/caravan/spatial/Point.java delete mode 100644 Commons/build.gradle delete mode 100644 Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint3D.java delete mode 100644 Commons/src/main/java/io/github/simplexdev/polarize/math/Point2D.java delete mode 100644 Commons/src/main/java/io/github/simplexdev/polarize/math/Point3D.java create mode 100644 Converter/.gitignore create mode 100644 Converter/build.gradle create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IAxisAngle.java rename {Commons/src/main/java/io/github/simplexdev/polarize/api => Converter/src/main/java/io/github/simplexdev/polarize/api/rotation}/IQuaternion.java (97%) rename {Commons/src/main/java/io/github/simplexdev/polarize/api => Converter/src/main/java/io/github/simplexdev/polarize/api/spatial}/IPoint2D.java (69%) create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint3D.java rename {Commons/src/main/java/io/github/simplexdev/polarize/api => Converter/src/main/java/io/github/simplexdev/polarize/api/spatial}/IScalar.java (95%) rename {Commons/src/main/java/io/github/simplexdev/polarize/api => Converter/src/main/java/io/github/simplexdev/polarize/api/spatial}/IVector.java (77%) create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVertex.java rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java (81%) create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/api/units/Point.java rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java (80%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java (68%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java (77%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java (96%) create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point2D.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point3D.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Vertex.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/log/PolarizeLogger.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/math/AxisAngle.java rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java (97%) create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/math/ScalarTriple.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/math/function/ArchimedeanSpiral.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/math/function/FibonacciLattice.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/math/function/Integral.java create mode 100644 Converter/src/main/java/io/github/simplexdev/polarize/math/function/TriFunction.java rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/polar/Delta.java (100%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/polar/PolarUnit.java (100%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java (94%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java (97%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java (99%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java (58%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/util/Rotator.java (60%) rename {Commons => Converter}/src/main/java/io/github/simplexdev/polarize/util/Utilities.java (99%) create mode 100644 Converter/src/test/java/io/github/simplexdev/polarize/math/FibonacciLatticeTest.java create mode 100644 Converter/src/test/java/io/github/simplexdev/polarize/math/Point3DTest.java diff --git a/Commons/.gitignore b/Bukkit/.gitignore similarity index 100% rename from Commons/.gitignore rename to Bukkit/.gitignore diff --git a/Paper/build.gradle b/Bukkit/build.gradle similarity index 88% rename from Paper/build.gradle rename to Bukkit/build.gradle index c8780a6..1d0f509 100644 --- a/Paper/build.gradle +++ b/Bukkit/build.gradle @@ -14,7 +14,7 @@ repositories { dependencies { compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT' - implementation project(':Commons') + implementation project(':Converter') } test { diff --git a/Paper/src/main/java/io/github/simplexdev/paper/DataConverter.java b/Bukkit/src/main/java/io/github/simplexdev/paper/DataConverter.java similarity index 87% rename from Paper/src/main/java/io/github/simplexdev/paper/DataConverter.java rename to Bukkit/src/main/java/io/github/simplexdev/paper/DataConverter.java index 5e56049..fcfe42e 100644 --- a/Paper/src/main/java/io/github/simplexdev/paper/DataConverter.java +++ b/Bukkit/src/main/java/io/github/simplexdev/paper/DataConverter.java @@ -1,12 +1,12 @@ package io.github.simplexdev.paper; -import io.github.simplexdev.polarize.api.IPoint2D; -import io.github.simplexdev.polarize.api.IPoint3D; -import io.github.simplexdev.polarize.api.IScalar; -import io.github.simplexdev.polarize.api.IVector; +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.spatial.IScalar; +import io.github.simplexdev.polarize.api.spatial.IVector; import io.github.simplexdev.polarize.cartesian.CartesianVector; -import io.github.simplexdev.polarize.math.Point2D; -import io.github.simplexdev.polarize.math.Point3D; +import io.github.simplexdev.polarize.cartesian.Point2D; +import io.github.simplexdev.polarize.cartesian.Point3D; import io.github.simplexdev.polarize.polar.Scalar; import org.bukkit.Location; import org.bukkit.World; diff --git a/Paper/.gitignore b/Caravan/.gitignore similarity index 100% rename from Paper/.gitignore rename to Caravan/.gitignore diff --git a/Caravan/build.gradle b/Caravan/build.gradle new file mode 100644 index 0000000..14a7a0f --- /dev/null +++ b/Caravan/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'io.github.simplexdev' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/CaravanAPI.java b/Caravan/src/main/java/io/github/simplexdev/caravan/CaravanAPI.java new file mode 100644 index 0000000..bf8d171 --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/CaravanAPI.java @@ -0,0 +1,5 @@ +package io.github.simplexdev.caravan; + +public interface CaravanAPI { + +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/api/Graph.java b/Caravan/src/main/java/io/github/simplexdev/caravan/api/Graph.java new file mode 100644 index 0000000..c9b2751 --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/api/Graph.java @@ -0,0 +1,4 @@ +package io.github.simplexdev.caravan.api; + +public interface Graph { +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/api/Mapper.java b/Caravan/src/main/java/io/github/simplexdev/caravan/api/Mapper.java new file mode 100644 index 0000000..9dbc7e6 --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/api/Mapper.java @@ -0,0 +1,12 @@ +package io.github.simplexdev.caravan.api; + +import io.github.simplexdev.caravan.api.curve.GenericCurve; +import io.github.simplexdev.caravan.spatial.Point; + +import java.util.Set; + +public interface Mapper { + Set generateCurve(T curve); + + +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/GenericCurve.java b/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/GenericCurve.java new file mode 100644 index 0000000..99caa0b --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/GenericCurve.java @@ -0,0 +1,31 @@ +package io.github.simplexdev.caravan.api.curve; + +import io.github.simplexdev.caravan.spatial.Point; + +import java.util.LinkedHashSet; + +public interface GenericCurve { + LinkedHashSet linkedPoints(); + + default void addPoint(Point point) { + linkedPoints().add(point); + } + + default void removePoint(Point point) { + linkedPoints().remove(point); + } + + default void clearPoints() { + linkedPoints().clear(); + } + + default boolean containsPoint(Point point) { + return linkedPoints().contains(point); + } + + default void addPoints(Point... points) { + for (Point point : points) { + addPoint(point); + } + } +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Helix.java b/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Helix.java new file mode 100644 index 0000000..0e3bfdf --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Helix.java @@ -0,0 +1,25 @@ +package io.github.simplexdev.caravan.api.curve; + +import io.github.simplexdev.caravan.spatial.Point; + +public interface Helix extends GenericCurve { + double getRadius(); + + double getDistance(); + + default double getX(double pos) { + return getRadius() * Math.cos(pos); + } + + default double getY(double pos) { + return getRadius() * Math.sin(pos); + } + + default double getZ(double pos) { + return getDistance() * pos; + } + + default Point toPoint(double pos) { + return new Point(getX(pos), getY(pos), getZ(pos)); + } +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Torus.java b/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Torus.java new file mode 100644 index 0000000..043dd2a --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/api/curve/Torus.java @@ -0,0 +1,11 @@ +package io.github.simplexdev.caravan.api.curve; + +public interface Torus { + double getDistanceFromCenter(); + + double getRadius(); + + default double getX() { + + } +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/base/Caravan.java b/Caravan/src/main/java/io/github/simplexdev/caravan/base/Caravan.java new file mode 100644 index 0000000..b529c2c --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/base/Caravan.java @@ -0,0 +1,11 @@ +package io.github.simplexdev.caravan.base; + +import io.github.simplexdev.caravan.CaravanAPI; + +public final class Caravan implements CaravanAPI { + private static final CaravanAPI api = new Caravan(); + + public static CaravanAPI getAPI() { + return api; + } +} diff --git a/Caravan/src/main/java/io/github/simplexdev/caravan/spatial/Point.java b/Caravan/src/main/java/io/github/simplexdev/caravan/spatial/Point.java new file mode 100644 index 0000000..84af86e --- /dev/null +++ b/Caravan/src/main/java/io/github/simplexdev/caravan/spatial/Point.java @@ -0,0 +1,65 @@ +package io.github.simplexdev.caravan.spatial; + +public class Point { + private final double x; + private final double y; + private final double z; + + private double xOffset; + private double yOffset; + private double zOffset; + + public Point(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + this.xOffset = 0; + this.yOffset = 0; + this.zOffset = 0; + } + + public Point(double x, double y, double z, double xOffset, double yOffset, double zOffset) { + this.x = x; + this.y = y; + this.z = z; + this.xOffset = xOffset; + this.yOffset = yOffset; + this.zOffset = zOffset; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public double getXOffset() { + return xOffset; + } + + public void setXOffset(double xOffset) { + this.xOffset = xOffset; + } + + public double getYOffset() { + return yOffset; + } + + public void setYOffset(double yOffset) { + this.yOffset = yOffset; + } + + public double getZOffset() { + return zOffset; + } + + public void setZOffset(double zOffset) { + this.zOffset = zOffset; + } +} diff --git a/Commons/build.gradle b/Commons/build.gradle deleted file mode 100644 index abdc447..0000000 --- a/Commons/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -plugins { - id 'java' -} - -group = 'io.github.simplexdev' -version = '1.0-SNAPSHOT' - -test { - useJUnitPlatform() -} \ No newline at end of file diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint3D.java b/Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint3D.java deleted file mode 100644 index dcc2ac4..0000000 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint3D.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.simplexdev.polarize.api; - -/** - * Represents a point in 3D space. - * It's important to note that Y is our vertical plane, and XZ is our horizontal plane. - * This is because Minecraft's coordinate system is based on the XZ plane. - * While this library is not Minecraft-specific, it is designed with Minecraft in mind. - */ -public interface IPoint3D { - /** - * Returns the X coordinate of this point. - * - * @return The X coordinate of this point. - */ - double getX(); - - /** - * Returns the Y coordinate of this point. - * - * @return The Y coordinate of this point. - */ - double getY(); - - /** - * Returns the Z coordinate of this point. - * - * @return The Z coordinate of this point. - */ - double getZ(); -} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/math/Point2D.java b/Commons/src/main/java/io/github/simplexdev/polarize/math/Point2D.java deleted file mode 100644 index 0d1a4fe..0000000 --- a/Commons/src/main/java/io/github/simplexdev/polarize/math/Point2D.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.simplexdev.polarize.math; - -import io.github.simplexdev.polarize.api.IPoint2D; - -public class Point2D implements IPoint2D { - - private final double x; - private final double z; - - public Point2D(double x, double z) { - this.x = x; - this.z = z; - } - - @Override - public double getX() { - return this.x; - } - - @Override - public double getZ() { - return this.z; - } -} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/math/Point3D.java b/Commons/src/main/java/io/github/simplexdev/polarize/math/Point3D.java deleted file mode 100644 index cce532f..0000000 --- a/Commons/src/main/java/io/github/simplexdev/polarize/math/Point3D.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.simplexdev.polarize.math; - -import io.github.simplexdev.polarize.api.IPoint3D; - -public class Point3D implements IPoint3D { - private final double x; - private final double y; - private final double z; - - public Point3D(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public double getX() { - return x; - } - - @Override - public double getY() { - return y; - } - - @Override - public double getZ() { - return z; - } -} diff --git a/Converter/.gitignore b/Converter/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/Converter/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Converter/build.gradle b/Converter/build.gradle new file mode 100644 index 0000000..95b5034 --- /dev/null +++ b/Converter/build.gradle @@ -0,0 +1,15 @@ +plugins { + id 'java' +} + +group = 'io.github.simplexdev' +version = '1.0-SNAPSHOT' + +dependencies { + implementation 'org.jetbrains:annotations:24.0.0' + testImplementation 'org.mockito:mockito-core:4.11.0' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IAxisAngle.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IAxisAngle.java new file mode 100644 index 0000000..ebabd81 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IAxisAngle.java @@ -0,0 +1,19 @@ +package io.github.simplexdev.polarize.api.rotation; + +import io.github.simplexdev.polarize.api.units.Theta; + +public interface IAxisAngle { + double getX(); + + double getY(); + + double getZ(); + + Theta getAngle(); + + IAxisAngle negate(); + + IAxisAngle normalize(); + + IAxisAngle inverse(); +} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/IQuaternion.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IQuaternion.java similarity index 97% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/IQuaternion.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IQuaternion.java index c2f2968..f97db19 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/IQuaternion.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/rotation/IQuaternion.java @@ -1,4 +1,6 @@ -package io.github.simplexdev.polarize.api; +package io.github.simplexdev.polarize.api.rotation; + +import io.github.simplexdev.polarize.api.spatial.IVector; /** * Represents the rotation of an object in 3D space. diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint2D.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint2D.java similarity index 69% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint2D.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint2D.java index 040e984..93897a7 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/IPoint2D.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint2D.java @@ -1,4 +1,7 @@ -package io.github.simplexdev.polarize.api; +package io.github.simplexdev.polarize.api.spatial; + +import static io.github.simplexdev.polarize.api.units.Point.X; +import static io.github.simplexdev.polarize.api.units.Point.Z; /** * Represents a point in 2D space along an XZ plane. @@ -11,12 +14,12 @@ public interface IPoint2D { * * @return The X coordinate of the point. */ - double getX(); + X getX(); /** * Returns the Z coordinate of the point. * * @return The Z coordinate of the point. */ - double getZ(); + Z getZ(); } diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint3D.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint3D.java new file mode 100644 index 0000000..58e6996 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IPoint3D.java @@ -0,0 +1,86 @@ +package io.github.simplexdev.polarize.api.spatial; + +import java.util.Set; +import static io.github.simplexdev.polarize.api.units.Point.*; + +/** + * Represents a point in 3D space. + * It's important to note that Y is our vertical plane, and XZ is our horizontal plane. + * This is because Minecraft's coordinate system is based on the XZ plane. + * While this library is not Minecraft-specific, it is designed with Minecraft in mind. + */ +public interface IPoint3D { + /** + * Returns the X coordinate of this point. + * + * @return The X coordinate of this point. + */ + X getX(); + + /** + * Returns the Y coordinate of this point. + * + * @return The Y coordinate of this point. + */ + Y getY(); + + /** + * Returns the Z coordinate of this point. + * + * @return The Z coordinate of this point. + */ + Z getZ(); + + /** + * Returns the distance between this point and another point. + * + * @param point The point to calculate the distance to. + * @return The distance between this point and the other point. + */ + IVector getDistance(IPoint3D point); + + /** + * Returns the difference between this point and another point. + * + * @param point The point to calculate the difference to. + * @return The difference between this point and the other point. + */ + IPoint3D getDifferential(IPoint3D point); + + /** + * Returns the sum of this point and another point. + * + * @param point The point to add to this point. + * @return The sum of this point and the other point. + */ + IPoint3D add(IPoint3D point); + + /** + * Returns the product of this point and another point. + * This will effectively scale the point by the other point. + * For example, if this point is (1, 1, 1) and the other point is (2, 2, 2), + * the resulting point will be (2, 2, 2). + * + * @param point The point to multiply this point by. + * @return The product of this point and the other point. + */ + IPoint3D multiply(IPoint3D point); + + /** + * Translates this point according to the vector provided. + * This will effectively move the point to the desired destination defined by the vector. + * + * @param vector The vector to add to this point. + * @return The sum of this point and the vector. + */ + IPoint3D move(IVector vector); + + /** + * Returns the midpoint between this point and another point. + * + * @param point The point to calculate the midpoint to. + * @param numPoints The number of points to draw between this point and the other point. + * @return The midpoint between this point and the other point. + */ + Set drawLine(IPoint3D point, double numPoints); +} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/IScalar.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IScalar.java similarity index 95% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/IScalar.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IScalar.java index 0f6621f..acc59c1 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/IScalar.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IScalar.java @@ -1,4 +1,6 @@ -package io.github.simplexdev.polarize.api; +package io.github.simplexdev.polarize.api.spatial; + +import io.github.simplexdev.polarize.api.rotation.IQuaternion; /** * Represents a scalar value. diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/IVector.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVector.java similarity index 77% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/IVector.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVector.java index 3870fff..2a6ef3d 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/IVector.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVector.java @@ -1,5 +1,8 @@ -package io.github.simplexdev.polarize.api; +package io.github.simplexdev.polarize.api.spatial; +import io.github.simplexdev.polarize.api.rotation.IQuaternion; +import io.github.simplexdev.polarize.api.units.Point; +import io.github.simplexdev.polarize.cartesian.Point3D; import org.jetbrains.annotations.NotNull; /** @@ -149,4 +152,32 @@ public interface IVector { * @return A new vector with the X Y Z mods rotated by the quaternion passed in. */ IVector rotate(@NotNull IQuaternion quaternion); + + /** + * This method returns the destination point defined by the XYZ mods and the length of the vector. + * The destination point is calculated from the X Y Z mods as + * (x * length, y * length, z * length). + * The destination point is the point that the vector is pointing to. + * + * @return The destination point defined by the XYZ mods and the length of the vector. + */ + default IPoint3D getDestination() { + return Point.fromDouble(getX() * length(), getY() * length(), getZ() * length()); + } + + /** + * This method returns a cross-product of this vector and the vector passed in. + * The cross-product is calculated from the X Y Z mods as + * (y * vector.getZ() - z * vector.getY(), z * vector.getX() - x * vector.getZ(), x * vector.getY() - y * vector.getX()). + * + * @param vector The vector to cross-product with. + * @return A cross-product of this vector and the vector passed in. + */ + default IPoint3D cross(IVector vector) { + return Point.fromDouble( + getY() * vector.getZ() - getZ() * vector.getY(), + getZ() * vector.getX() - getX() * vector.getZ(), + getX() * vector.getY() - getY() * vector.getX() + ); + } } diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVertex.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVertex.java new file mode 100644 index 0000000..0c507b2 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/spatial/IVertex.java @@ -0,0 +1,5 @@ +package io.github.simplexdev.polarize.api.spatial; + +public interface IVertex { + +} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java similarity index 81% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java index 5884c00..bf26ab1 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Phi.java @@ -20,4 +20,12 @@ public interface Phi { * @return the azimuth value as a double */ double getAzimuth(); + + static Phi from(double y, Radius r) { + return () -> Math.cos(y / r.length()); + } + + static Phi of(double azimuth) { + return () -> azimuth; + } } diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Point.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Point.java new file mode 100644 index 0000000..96614fe --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Point.java @@ -0,0 +1,244 @@ +package io.github.simplexdev.polarize.api.units; + + +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.cartesian.Point2D; +import io.github.simplexdev.polarize.cartesian.Point3D; +import io.github.simplexdev.polarize.math.function.Integral; + +import java.io.Serializable; +import java.util.function.DoubleUnaryOperator; + +@FunctionalInterface +public interface Point extends Serializable { + + /** + * Creates a 2d point from a given X and Z value. + * + * @param x The X value. + * @param z The Z value. + * @return The 2d point. + */ + static IPoint2D fromXZ(X x, Z z) { + return new Point2D(x, z); + } + + /** + * Creates a 3d point from a given X, Y, and Z value. + * + * @param x The X value. + * @param y The Y value. + * @param z The Z value. + * @return The 3d point. + */ + static IPoint3D fromXYZ(X x, Y y, Z z) { + return new Point3D(x, y, z); + } + + /** + * Creates a 2d point from the given double values. + * + * @param x The X value. + * @param z The Z value. + * @return The 2d point. + */ + static IPoint2D fromDouble(double x, double z) { + return new Point2D(() -> x, () -> z); + } + + /** + * Creates a 3d point from the given double values. + * + * @param x The X value. + * @param y The Y value. + * @param z The Z value. + * @return The 3d point. + */ + static IPoint3D fromDouble(double x, double y, double z) { + return new Point3D(() -> x, () -> y, () -> z); + } + + @Override + String toString(); + + /** + * Returns the numerical representation of the point. + * + * @return The value of the point. + */ + double get(); + + /** + * Returns the distance between this point and the given point. + * + * @param point The point to compare to. + * @return The distance between the two points. + */ + default double distance(double point) { + return Math.abs(this.get() - point); + } + + /** + * Returns the distance between this point and the given point. + * + * @param point The point to compare to. + * @return The distance between the two points. + */ + default double distance(Point point) { + return this.distance(point.get()); + } + + /** + * Adds the given point to this point. + * + * @param point The point to add. + * @return The sum of the two points. + */ + default double add(double point) { + return this.get() + point; + } + + /** + * Adds the given point to this point. + * + * @param point The point to add. + * @return The sum of the two points. + */ + default double add(Point point) { + return this.add(point.get()); + } + + /** + * Subtracts the given point from this point. + * + * @param point The point to subtract. + * @return The difference of the two points. + */ + default double subtract(double point) { + return this.get() - point; + } + + /** + * Subtracts the given point from this point. + * + * @param point The point to subtract. + * @return The difference of the two points. + */ + default double subtract(Point point) { + return this.subtract(point.get()); + } + + /** + * Multiplies this point by the given point. + * + * @param point The point to multiply by. + * @return The product of the two points. + */ + default double multiply(double point) { + return this.get() * point; + } + + /** + * Multiplies this point by the given point. + * + * @param point The point to multiply by. + * @return The product of the two points. + */ + default double multiply(Point point) { + return this.multiply(point.get()); + } + + /** + * Divides this point by the given point. + * + * @param point The point to divide by. + * @return The quotient of the two points. + */ + default double divide(double point) { + return this.get() / point; + } + + /** + * Divides this point by the given point. + * + * @param point The point to divide by. + * @return The quotient of the two points. + */ + default double divide(Point point) { + return this.divide(point.get()); + } + + /** + * Returns this point raised to the power of the given point. + * + * @param point The point to raise this point to. + * @return The power of the two points. + */ + default double power(double point) { + return Math.pow(this.get(), point); + } + + /** + * Returns this point raised to the power of the given point. + * + * @param point The point to raise this point to. + * @return The power of the two points. + */ + default double power(Point point) { + return this.power(point.get()); + } + + /** + * Returns the integral of the given function from this point to the given point. + * + * @param point The point to integrate to. + * @param subIntervals The number of sub-intervals to use. + * @param function The function to integrate. + * @return The integral of the function. + */ + default double integ(double point, double subIntervals, DoubleUnaryOperator function) { + return Integral.integrate(this.get(), point, subIntervals, function); + } + + /** + * Returns the integral of the given function from this point to the given point. + * + * @param point The point to integrate to. + * @param subIntervals The number of sub-intervals to use. + * @param function The function to integrate. + * @return The integral of the function. + */ + default double integ(Point point, double subIntervals, DoubleUnaryOperator function) { + return this.integ(point.get(), subIntervals, function); + } + + /** + * Represents any value of X along the X coordinate plane. + */ + @FunctionalInterface + interface X extends Point { + @Override + double get(); + } + + /** + * Represents any value of Y along the Y coordinate plane. + */ + @FunctionalInterface + interface Y extends Point { + + @Override + double get(); + } + + /** + * Represents any value of Z along the Z coordinate plane. + */ + @FunctionalInterface + interface Z extends Point { + + @Override + double get(); + } +} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java similarity index 80% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java index a840628..4346153 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Radius.java @@ -19,4 +19,12 @@ public interface Radius { * @return the length of the radius as a double */ double length(); + + static Radius of(double length) { + return () -> length; + } + + static Radius from(double x, double y, double z) { + return () -> Math.sqrt(x * x + y * y + z * z); + } } diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java similarity index 68% rename from Commons/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java rename to Converter/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java index dc3c067..35b69be 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/api/units/Theta.java @@ -11,4 +11,12 @@ public interface Theta { * @return the zenith angle as a double. */ double getZenith(); + + static Theta from(double x, double z) { + return () -> Math.atan2(x, z); + } + + static Theta of(double zenithAngle) { + return () -> zenithAngle; + } } diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java similarity index 77% rename from Commons/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java rename to Converter/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java index c62734b..5396ad7 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianUnit.java @@ -1,9 +1,8 @@ package io.github.simplexdev.polarize.cartesian; -import io.github.simplexdev.polarize.api.IPoint2D; -import io.github.simplexdev.polarize.api.IPoint3D; -import io.github.simplexdev.polarize.math.Point2D; -import io.github.simplexdev.polarize.math.Point3D; +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.units.Point; /** * CartesianUnit is a class that contains a 3D point and a 2D point @@ -21,8 +20,8 @@ public class CartesianUnit { * @param z The z value of the 3D point and the 2D point. */ public CartesianUnit(double x, double y, double z) { - this.point3d = new Point3D(x, y, z); - this.point2d = new Point2D(x, z); + this.point3d = Point.fromDouble(x, y, z); + this.point2d = Point.fromDouble(x, z); } /** diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java similarity index 96% rename from Commons/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java rename to Converter/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java index 9da5a70..c8529b2 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/CartesianVector.java @@ -1,7 +1,7 @@ package io.github.simplexdev.polarize.cartesian; -import io.github.simplexdev.polarize.api.IQuaternion; -import io.github.simplexdev.polarize.api.IVector; +import io.github.simplexdev.polarize.api.rotation.IQuaternion; +import io.github.simplexdev.polarize.api.spatial.IVector; import io.github.simplexdev.polarize.math.Quaternion; import org.jetbrains.annotations.NotNull; diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point2D.java b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point2D.java new file mode 100644 index 0000000..febe0e6 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point2D.java @@ -0,0 +1,25 @@ +package io.github.simplexdev.polarize.cartesian; + +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import static io.github.simplexdev.polarize.api.units.Point.*; + +public class Point2D implements IPoint2D { + + private final X x; + private final Z z; + + public Point2D(X x, Z z) { + this.x = x; + this.z = z; + } + + @Override + public X getX() { + return this.x; + } + + @Override + public Z getZ() { + return this.z; + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point3D.java b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point3D.java new file mode 100644 index 0000000..e914c88 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Point3D.java @@ -0,0 +1,102 @@ +package io.github.simplexdev.polarize.cartesian; + +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.spatial.IVector; +import io.github.simplexdev.polarize.api.units.Point; +import io.github.simplexdev.polarize.log.PolarizeLogger; +import org.jetbrains.annotations.NotNull; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class Point3D implements IPoint3D { + private final Point.X x; + private final Point.Y y; + private final Point.Z z; + + public Point3D(Point.X x, Point.Y y, Point.Z z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public Point.X getX() { + return x; + } + + @Override + public Point.Y getY() { + return y; + } + + @Override + public Point.Z getZ() { + return z; + } + + @Override + public IVector getDistance(@NotNull IPoint3D point) { + return new CartesianVector(point.getX().subtract(x), + point.getY().subtract(y), + point.getZ().subtract(z)); + } + + @Override + public IPoint3D multiply(IPoint3D point) { + return new Point3D(() -> x.multiply(point.getX()), + () -> y.multiply(point.getY()), + () -> z.multiply(point.getZ())); + } + + @Override + public IPoint3D move(IVector vector) { + return add(vector.getDestination()); + } + + @Override + public IPoint3D getDifferential(@NotNull IPoint3D point) { + return new Point3D(() -> point.getX().subtract(x), + () -> point.getY().subtract(y), + () -> point.getZ().subtract(z)); + } + + @Override + public IPoint3D add(IPoint3D point) { + return new Point3D(() -> point.getX().add(x), + () -> point.getY().add(y), + () -> point.getZ().add(z)); + } + + @Override + public Set drawLine(IPoint3D point, double numPoints) { + IPoint3D diff = getDifferential(point); + Set point3DSet = new LinkedHashSet<>(); + for (double i = 0.0; i <= numPoints; i++) { + double multiplier = i / numPoints; + PolarizeLogger.info("i: " + i); + PolarizeLogger.info("multiplier: " + multiplier); + IPoint3D adjusted = Point.fromDouble(diff.getX().multiply(() -> multiplier), + diff.getY().multiply(multiplier), + diff.getZ().multiply(multiplier)); + PolarizeLogger.info("adjusted: " + "X: " + adjusted.getX() + + " Y: " + adjusted.getY() + + " Z: " + adjusted.getZ()); + IPoint3D added = this.add(adjusted); + PolarizeLogger.info("added: " + "X: " + added.getX() + + " Y: " + added.getY() + + " Z: " + added.getZ()); + point3DSet.add(added); + } + return point3DSet; + } + + public void drawLineTestMethod() { + IPoint3D origin = Point.fromDouble(2, 6, 5); + IPoint3D destination = Point.fromDouble(10, 6, -15); + origin.drawLine(destination, 25).forEach(point3D -> + PolarizeLogger.info("X: " + point3D.getX() + + " Y: " + point3D.getY() + + " Z: " + point3D.getZ())); + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Vertex.java b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Vertex.java new file mode 100644 index 0000000..2db05d0 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/cartesian/Vertex.java @@ -0,0 +1,24 @@ +package io.github.simplexdev.polarize.cartesian; + +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.spatial.IVector; + +public class Vertex { + private final IPoint3D vertex; + + public Vertex(IVector vector1, IVector vector2) { + this.vertex = vector1.cross(vector2); + } + + public double getX() { + return vertex.getX().get(); + } + + public double getY() { + return vertex.getY().get(); + } + + public double getZ() { + return vertex.getZ().get(); + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/log/PolarizeLogger.java b/Converter/src/main/java/io/github/simplexdev/polarize/log/PolarizeLogger.java new file mode 100644 index 0000000..faebb2f --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/log/PolarizeLogger.java @@ -0,0 +1,31 @@ +package io.github.simplexdev.polarize.log; + +import java.util.logging.Logger; + +public class PolarizeLogger { + private static final Logger logger = Logger.getLogger("Polarize"); + + private PolarizeLogger() { + throw new AssertionError(); + } + + public static void info(String message) { + logger.info(message); + } + + public static void warning(String message) { + logger.warning(message); + } + + public static void warning(Throwable throwable) { + logger.warning(throwable.getMessage()); + } + + public static void severe(String message) { + logger.severe(message); + } + + public static void severe(Throwable throwable) { + logger.severe(throwable.getMessage()); + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/math/AxisAngle.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/AxisAngle.java new file mode 100644 index 0000000..0e59a14 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/AxisAngle.java @@ -0,0 +1,54 @@ +package io.github.simplexdev.polarize.math; + +import io.github.simplexdev.polarize.api.rotation.IAxisAngle; +import io.github.simplexdev.polarize.api.units.Theta; + +public class AxisAngle implements IAxisAngle { + private final double x; + private final double y; + private final double z; + private final Theta angle; + + public AxisAngle(double x, double y, double z, Theta angle) { + this.x = x; + this.y = y; + this.z = z; + this.angle = angle; + } + + @Override + public double getX() { + return this.x; + } + + @Override + public double getY() { + return this.y; + } + + @Override + public double getZ() { + return this.z; + } + + @Override + public Theta getAngle() { + return this.angle; + } + + @Override + public IAxisAngle negate() { + return new AxisAngle(-this.x, -this.y, -this.z, () -> -(this.angle.getZenith())); + } + + @Override + public IAxisAngle normalize() { + double magnitude = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + return new AxisAngle(this.x / magnitude, this.y / magnitude, this.z / magnitude, this.angle); + } + + @Override + public IAxisAngle inverse() { + return new AxisAngle(-this.x, -this.y, -this.z, this.angle); + } +} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java similarity index 97% rename from Commons/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java rename to Converter/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java index 5b3a36e..29251b4 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/Quaternion.java @@ -1,6 +1,6 @@ package io.github.simplexdev.polarize.math; -import io.github.simplexdev.polarize.api.IQuaternion; +import io.github.simplexdev.polarize.api.rotation.IQuaternion; public class Quaternion implements IQuaternion { private final double w; diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/math/ScalarTriple.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/ScalarTriple.java new file mode 100644 index 0000000..a3d9233 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/ScalarTriple.java @@ -0,0 +1,39 @@ +package io.github.simplexdev.polarize.math; + +import io.github.simplexdev.polarize.api.spatial.IVector; +import io.github.simplexdev.polarize.cartesian.CartesianVector; + +public class ScalarTriple { + private final double productA; + private final double productB; + private final double productC; + + private final IVector scalarTripleProduct; + + public ScalarTriple(IVector productA, IVector productB, IVector productC) { + this.productA = productA.dot(productB.multiply(productC)); + this.productB = productB.dot(productC.multiply(productA)); + this.productC = productC.dot(productA.multiply(productB)); + + this.scalarTripleProduct = new CartesianVector( + this.productA, + this.productB, + this.productC); + } + + public double getProductA() { + return productA; + } + + public double getProductB() { + return productB; + } + + public double getProductC() { + return productC; + } + + public IVector getScalarTripleProduct() { + return scalarTripleProduct; + } +} \ No newline at end of file diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/math/function/ArchimedeanSpiral.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/ArchimedeanSpiral.java new file mode 100644 index 0000000..27fb542 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/ArchimedeanSpiral.java @@ -0,0 +1,36 @@ +package io.github.simplexdev.polarize.math.function; + +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import io.github.simplexdev.polarize.api.units.Point; +import io.github.simplexdev.polarize.api.units.Theta; +import io.github.simplexdev.polarize.cartesian.Point2D; +import org.jetbrains.annotations.NotNull; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class ArchimedeanSpiral { + private final double origin; + private final double step; + private final double radius; + private final Theta theta; + + public ArchimedeanSpiral(double origin, double step, @NotNull Theta theta) { + this.origin = origin; + this.step = step; + this.theta = theta; + + this.radius = origin + (this.step * theta.getZenith()); + } + + public Set getPoints(IPoint2D start) { + Set hashSet = new LinkedHashSet<>(); + hashSet.add(start); + for (double i = origin; i < theta.getZenith(); i += step) { + double x = radius * Math.cos(i); + double z = radius * Math.sin(i); + hashSet.add(Point.fromDouble(x + start.getX().get(), z + start.getZ().get())); + } + return hashSet; + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/math/function/FibonacciLattice.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/FibonacciLattice.java new file mode 100644 index 0000000..c509346 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/FibonacciLattice.java @@ -0,0 +1,28 @@ +package io.github.simplexdev.polarize.math.function; + +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.units.Point; +import io.github.simplexdev.polarize.cartesian.Point3D; + +import java.util.LinkedHashSet; +import java.util.Set; + +public final class FibonacciLattice { + + public static Set populate(IPoint3D origin, int radius, double step) { + Set points = new LinkedHashSet<>(); + final double goldenRatio = (1 + Math.sqrt(5)) / 2; + + for (double i = 0; i <= radius; i += step) { + double theta = 2 * Math.PI * i / goldenRatio; + double phi = Math.acos(1 - 2 * (i + 0.5) / radius); + double x = Math.cos(theta) * Math.sin(phi); + double y = Math.cos(phi); + double z = Math.sin(theta) * Math.sin(phi); + + points.add(origin.add(Point.fromDouble(x, y, z))); + } + + return points; + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/math/function/Integral.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/Integral.java new file mode 100644 index 0000000..ec6a581 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/Integral.java @@ -0,0 +1,51 @@ +package io.github.simplexdev.polarize.math.function; + +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.cartesian.Point3D; + +import java.util.function.DoubleUnaryOperator; +import java.util.function.Function; +import java.util.function.UnaryOperator; + +public interface Integral { + static double integrate(double lower, double upper, double subIntervals, DoubleUnaryOperator function) { + double dx = (upper - lower) / subIntervals; + double sum = 0.5 * (function.applyAsDouble(lower) + function.applyAsDouble(upper)); + for (double i = 1; i < subIntervals; i++) { + double s = lower + i * dx; + sum += function.applyAsDouble(s); + } + return dx * sum; + } + + static double integrate(IPoint3D origin, IPoint3D destination, double subIntervals, TriFunction function) { + double x1 = origin.getX().get(), x2 = destination.getX().get(); + double y1 = origin.getY().get(), y2 = destination.getY().get(); + double z1 = origin.getZ().get(), z2 = destination.getZ().get(); + + double dx = (x2 - x1) / subIntervals; + double dy = (y2 - y1) / subIntervals; + double dz = (z2 - z1) / subIntervals; + + double integral = 0.0; + + for (double i = 0.0; i <= subIntervals; i++) { + double x = x1 + i * dx; + for (double j = 0.0; j <= subIntervals; j++) { + double y = y1 + j * dy; + for (double k = 0.0; k <= subIntervals; k++) { + double z = z1 + k * dz; + double weight = 1.0; + if (i == 0.0 || i == subIntervals) weight *= 0.5; + if (j == 0.0 || j == subIntervals) weight *= 0.5; + if (k == 0.0 || k == subIntervals) weight *= 0.5; + integral += weight * function.apply(x, y, z); + } + } + } + + integral *= dx * dy * dz; + + return integral; + } +} diff --git a/Converter/src/main/java/io/github/simplexdev/polarize/math/function/TriFunction.java b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/TriFunction.java new file mode 100644 index 0000000..7b82459 --- /dev/null +++ b/Converter/src/main/java/io/github/simplexdev/polarize/math/function/TriFunction.java @@ -0,0 +1,6 @@ +package io.github.simplexdev.polarize.math.function; + +@FunctionalInterface +public interface TriFunction { + V apply(T t, S s, U u); +} diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/polar/Delta.java b/Converter/src/main/java/io/github/simplexdev/polarize/polar/Delta.java similarity index 100% rename from Commons/src/main/java/io/github/simplexdev/polarize/polar/Delta.java rename to Converter/src/main/java/io/github/simplexdev/polarize/polar/Delta.java diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/polar/PolarUnit.java b/Converter/src/main/java/io/github/simplexdev/polarize/polar/PolarUnit.java similarity index 100% rename from Commons/src/main/java/io/github/simplexdev/polarize/polar/PolarUnit.java rename to Converter/src/main/java/io/github/simplexdev/polarize/polar/PolarUnit.java diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java b/Converter/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java similarity index 94% rename from Commons/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java rename to Converter/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java index 2d09ac8..f4a39c7 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/polar/Scalar.java @@ -1,7 +1,7 @@ package io.github.simplexdev.polarize.polar; -import io.github.simplexdev.polarize.api.IQuaternion; -import io.github.simplexdev.polarize.api.IScalar; +import io.github.simplexdev.polarize.api.rotation.IQuaternion; +import io.github.simplexdev.polarize.api.spatial.IScalar; public class Scalar implements IScalar { private final double magnitude; diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java b/Converter/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java similarity index 97% rename from Commons/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java rename to Converter/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java index 995cf45..8fbed7e 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/polar/SphericalUnit.java @@ -106,7 +106,7 @@ public class SphericalUnit { */ public double adjacent() { CartesianUnit unit = Polarizer.toCartesianUnit(this); - return unit.getPoint3D().getX(); + return unit.getPoint3D().getX().get(); } /** @@ -119,6 +119,6 @@ public class SphericalUnit { */ public double opposite() { CartesianUnit unit = Polarizer.toCartesianUnit(this); - return unit.getPoint3D().getZ(); + return unit.getPoint3D().getZ().get(); } } diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java b/Converter/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java similarity index 99% rename from Commons/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java rename to Converter/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java index ac3634d..4235ac5 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/util/Interpolator.java @@ -1,7 +1,7 @@ package io.github.simplexdev.polarize.util; -import io.github.simplexdev.polarize.api.IScalar; -import io.github.simplexdev.polarize.api.IVector; +import io.github.simplexdev.polarize.api.spatial.IScalar; +import io.github.simplexdev.polarize.api.spatial.IVector; import io.github.simplexdev.polarize.cartesian.CartesianUnit; import io.github.simplexdev.polarize.polar.PolarUnit; import io.github.simplexdev.polarize.polar.SphericalUnit; diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java b/Converter/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java similarity index 58% rename from Commons/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java rename to Converter/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java index 103abad..eacc7f3 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/util/Polarizer.java @@ -1,12 +1,17 @@ package io.github.simplexdev.polarize.util; -import io.github.simplexdev.polarize.api.IPoint2D; -import io.github.simplexdev.polarize.api.IPoint3D; -import io.github.simplexdev.polarize.api.IScalar; -import io.github.simplexdev.polarize.api.IVector; +import io.github.simplexdev.polarize.api.rotation.IAxisAngle; +import io.github.simplexdev.polarize.api.rotation.IQuaternion; +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.spatial.IScalar; +import io.github.simplexdev.polarize.api.spatial.IVector; import io.github.simplexdev.polarize.api.units.Phi; +import io.github.simplexdev.polarize.api.units.Radius; import io.github.simplexdev.polarize.api.units.Theta; import io.github.simplexdev.polarize.cartesian.CartesianUnit; +import io.github.simplexdev.polarize.math.AxisAngle; +import io.github.simplexdev.polarize.math.Quaternion; import io.github.simplexdev.polarize.polar.PolarUnit; import io.github.simplexdev.polarize.polar.SphericalUnit; @@ -107,6 +112,16 @@ public class Polarizer { /** * Converts a spherical coordinate (radius, theta, phi) to Cartesian coordinates (x, y, z). + *

+ * This method uses the following formula: + *

+     *         {@code radius = sqrt(x^2 + y^2 + z^2)}
+     *         {@code theta = acos(y / radius)}
+     *         {@code phi = atan2(z, x)}
+     *         {@code x = radius * sin(theta) * cos(phi)}
+     *         {@code y = radius * cos(theta)}
+     *         {@code z = radius * sin(theta) * sin(phi)}
+     * 
* * @param radius the radius of the spherical coordinate * @param theta the theta angle in radians of the spherical coordinate @@ -122,21 +137,22 @@ public class Polarizer { /** * Converts a {@link CartesianUnit} to a {@link PolarUnit}. + * This method uses the same formula as {@link #toPolarUnit(double, double)}. * * @param unit the CartesianUnit to be converted * @return a PolarUnit representing the same point as the input CartesianUnit */ public static PolarUnit toPolarUnit(CartesianUnit unit) { - double radius = Math.sqrt( - unit.getPoint2D().getX() * unit.getPoint2D().getX() - + unit.getPoint2D().getZ() * unit.getPoint2D().getZ()); - double theta = Math.atan2(unit.getPoint2D().getX(), unit.getPoint2D().getZ()); + double radius = Math.sqrt(unit.getPoint2D().getX().get() * unit.getPoint2D().getX().get() + unit.getPoint2D().getZ().get() * unit.getPoint2D().getZ().get()); + double theta = Math.atan2(unit.getPoint2D().getX().get(), unit.getPoint2D().getZ().get()); return new PolarUnit(radius, theta); } /** - * Converts the given {@link CartesianUnit} to a {@link PolarUnit} using the magnitude of the given {@link IVector} as - * the radius. The angle theta is calculated from the x and z components of the CartesianUnit using the {@link Math#atan2(double, double)} method. + * Converts the given {@link CartesianUnit} to a {@link PolarUnit}. + * This method uses the same formula as {@link #toPolarUnit(double, double)}, + * with the exception that the radius is computed using the given {@link IVector} + * instead of the {@link IPoint2D}'s x and z coordinates. * * @param unit the {@link CartesianUnit} to convert * @param vector the {@link IVector} representing the radius of the resulting {@link PolarUnit} @@ -144,12 +160,14 @@ public class Polarizer { */ public static PolarUnit toPolarUnit(CartesianUnit unit, IVector vector) { double radius = vector.length(); - double theta = Math.atan2(unit.getPoint2D().getX(), unit.getPoint2D().getZ()); + double theta = Math.atan2(unit.getPoint2D().getX().get(), unit.getPoint2D().getZ().get()); return new PolarUnit(radius, theta); } /** * Returns a {@link PolarUnit} representing the polar coordinates of the given 2D point in relation to the given vector. + *

+ * This method uses the same formula as {@link #toPolarUnit(double, double)}. * * @param point the point to convert to polar coordinates * @param vector the vector used as a reference for the polar coordinates @@ -157,16 +175,25 @@ public class Polarizer { */ public static PolarUnit toPolarUnit(IPoint2D point, IVector vector) { double radius = vector.length(); - double theta = Math.atan2(point.getX(), point.getZ()); + double theta = Math.atan2(point.getX().get(), point.getZ().get()); return new PolarUnit(radius, theta); } /** * Converts a 2D point in Cartesian coordinates to a polar unit. + *

+ * The conversion is based on the following formula: + *

+     *          {@code radius = sqrt(x^2 + z^2)}
+     *          {@code theta = atan2(x, z)}
+     *             where:
+     *         x = {@link IPoint2D#getX()}
+     *         z = {@link IPoint2D#getZ()}
+     * 
* * @param x the x-coordinate of the point * @param z the z-coordinate of the point - * @return a {@code PolarUnit} representing the polar coordinates of the point + * @return a {@link PolarUnit} representing the polar coordinates of the point */ public static PolarUnit toPolarUnit(double x, double z) { double radius = Math.sqrt(x * x + z * z); @@ -175,23 +202,36 @@ public class Polarizer { } /** - * Converts a CartesianUnit to a SphericalUnit. + * Converts a {@link CartesianUnit} to a {@link SphericalUnit}. + *

+ * The radius is calculated by creating a new vector based on the CartesianUnit's + * x, y, and z coordinates, then using {@link IVector#length()} to acquire the {@link IScalar}. + *

+ * The angles are then calculated from {@link IScalar#getMagnitude()}. + *

+ * This method uses the same formula as {@link #toSphericalUnit(double, double, double)}. * * @param unit the CartesianUnit to be converted. * @return the SphericalUnit representing the same point as the input CartesianUnit. */ public static SphericalUnit toSphericalUnit(CartesianUnit unit) { - double radius = Math.sqrt( - unit.getPoint3D().getX() * unit.getPoint3D().getX() - + unit.getPoint3D().getY() * unit.getPoint3D().getY() - + unit.getPoint3D().getZ() * unit.getPoint3D().getZ()); - double theta = Math.acos(unit.getPoint3D().getY() / radius); - double phi = Math.atan2(unit.getPoint3D().getX(), unit.getPoint3D().getZ()); + double radius = Math.sqrt(unit.getPoint3D().getX().get() + * unit.getPoint3D().getX().get() + + unit.getPoint3D().getY().get() + * unit.getPoint3D().getY().get() + + unit.getPoint3D().getZ().get() + * unit.getPoint3D().getZ().get()); + double theta = Math.acos(unit.getPoint3D().getY().get() + / radius); + double phi = Math.atan2(unit.getPoint3D().getX().get(), + unit.getPoint3D().getZ().get()); return new SphericalUnit(radius, theta, phi); } /** * Converts the specified {@link IPoint3D} to a {@link SphericalUnit} using the specified {@link IVector}. + *

+ * This method uses the same formula as {@link #toSphericalUnit(double, double, double)} * * @param point the point to convert to a spherical unit * @param vector the vector to use for the conversion @@ -199,18 +239,33 @@ public class Polarizer { */ public static SphericalUnit toSphericalUnit(IPoint3D point, IVector vector) { double radius = vector.length(); - double theta = Math.acos(point.getY() / radius); - double phi = Math.atan2(point.getX(), point.getZ()); + double theta = Math.acos(point.getY().get() / radius); + double phi = Math.atan2(point.getX().get(), point.getZ().get()); return new SphericalUnit(radius, theta, phi); } /** * Converts the given Cartesian coordinates (x, y, z) to spherical coordinates (radius, theta, phi). + *

+ * The conversion is based on the following formula: + *

+     *         {@code radius = sqrt(x^2 + y^2 + z^2)}
+     *         {@code theta = acos(y / radius)}
+     *         {@code phi = atan2(x, z)}
+     *             where:
+     *         {@code radius} is the {@link Radius} (scalar) of the spherical coordinate
+     *         {@code theta} is the {@link Theta} angle (zenith) in radians of the spherical coordinate
+     *         {@code phi} is the {@link Phi} angle (azimuth) in radians of the spherical coordinate
+     * 
+ *

+ * The resulting spherical coordinates are returned as a new {@link SphericalUnit}. + *

+ * The returned {@link SphericalUnit} is guaranteed to reflect the same coordinates as the input. * * @param x the x-coordinate * @param y the y-coordinate * @param z the z-coordinate - * @return a new {@code SphericalUnit} representing the converted spherical coordinates + * @return a new {@link SphericalUnit} representing the converted spherical coordinates */ public static SphericalUnit toSphericalUnit(double x, double y, double z) { double radius = Math.sqrt(x * x + y * y + z * z); @@ -218,4 +273,70 @@ public class Polarizer { double phi = Math.atan2(x, z); return new SphericalUnit(radius, theta, phi); } + + /** + * Converts the given {@link IQuaternion} to an {@link IAxisAngle}. + *

+ * The conversion is based on the following formula: + *

+     *          {@code r = (x * sin(angle/2), y * sin(angle/2), z * sin(angle/2), cos(angle/2))}
+     *              where:
+     *         sin = {@link Math#sin(double)},
+     *         cos = {@link Math#cos(double)},
+     *         x = {@link IQuaternion#getX()},
+     *         y = {@link IQuaternion#getY()},
+     *         z = {@link IQuaternion#getZ()}
+     *         angle = {@link IQuaternion#getW()}
+     *         r = {@link IAxisAngle}
+     * 
+ * + * @param quaternion the {@link IQuaternion} to convert + * @return a new {@link IAxisAngle} representing the converted {@link IQuaternion} + */ + public static IAxisAngle toAxisAngle(IQuaternion quaternion) { + double angle = 2 * Math.acos(quaternion.getW()); + double s = Math.sqrt(1 - quaternion.getW() * quaternion.getW()); + + double x, y, z; + + if (s < 0.001) { + x = quaternion.getX(); + y = quaternion.getY(); + z = quaternion.getZ(); + } else { + x = quaternion.getX() / s; + y = quaternion.getY() / s; + z = quaternion.getZ() / s; + } + return new AxisAngle(x, y, z, () -> angle); + } + + /** + * Converts the given {@link IAxisAngle} to a {@link IQuaternion}. + *

+ * The conversion is based on the following formula: + *

+     *          {@code q = (x * sin(angle / 2), y * sin(angle / 2), z * sin(angle / 2), cos(angle / 2))}
+     *              where:
+     *         sin = {@link Math#sin(double)}
+     *         cos = {@link Math#cos(double)}
+     *         angle = {@link Theta#getZenith()}
+     *         x = {@link IAxisAngle#getX()}
+     *         y = {@link IAxisAngle#getY()}
+     *         z = {@link IAxisAngle#getZ()}
+     *         q = the resulting quaternion.
+     * 
+ * + * @param axisAngle the {@link IAxisAngle} to convert + * @return a {@link IQuaternion} representing the same rotation as the given {@link IAxisAngle} + */ + public IQuaternion toQuaternion(IAxisAngle axisAngle) { + double angle = axisAngle.getAngle().getZenith(); + double x = axisAngle.getX(); + double y = axisAngle.getY(); + double z = axisAngle.getZ(); + double w = Math.cos(angle / 2); + double s = Math.sin(angle / 2); + return new Quaternion(x * s, y * s, z * s, w); + } } diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/util/Rotator.java b/Converter/src/main/java/io/github/simplexdev/polarize/util/Rotator.java similarity index 60% rename from Commons/src/main/java/io/github/simplexdev/polarize/util/Rotator.java rename to Converter/src/main/java/io/github/simplexdev/polarize/util/Rotator.java index d085d6e..cb81300 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/util/Rotator.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/util/Rotator.java @@ -1,10 +1,11 @@ package io.github.simplexdev.polarize.util; -import io.github.simplexdev.polarize.api.IPoint2D; -import io.github.simplexdev.polarize.api.IPoint3D; -import io.github.simplexdev.polarize.api.IQuaternion; -import io.github.simplexdev.polarize.math.Point2D; -import io.github.simplexdev.polarize.math.Point3D; +import io.github.simplexdev.polarize.api.rotation.IQuaternion; +import io.github.simplexdev.polarize.api.spatial.IPoint2D; +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.api.units.Point; +import io.github.simplexdev.polarize.cartesian.Point2D; +import io.github.simplexdev.polarize.cartesian.Point3D; import io.github.simplexdev.polarize.math.Quaternion; import io.github.simplexdev.polarize.polar.Delta; import io.github.simplexdev.polarize.polar.PolarUnit; @@ -35,11 +36,13 @@ public class Rotator { * @return the rotated point. */ public static IPoint3D rotateX(IPoint3D point, SphericalUnit unit) { - double x = point.getX(); - double y = point.getY() * Math.cos(unit.theta()) - point.getZ() * Math.sin(unit.theta()); - double z = point.getY() * Math.sin(unit.theta()) + point.getZ() * Math.cos(unit.theta()); + double x = point.getX().get(); + double y = point.getY().multiply(Math.cos(unit.theta())) + - point.getZ().multiply(Math.sin(unit.theta())); + double z = point.getY().multiply(Math.sin(unit.theta())) + + point.getZ().multiply(Math.cos(unit.theta())); - return new Point3D(x, y, z); + return Point.fromDouble(x, y, z); } /** @@ -52,11 +55,13 @@ public class Rotator { * @return the rotated point. */ public static IPoint3D rotateY(IPoint3D point, SphericalUnit unit) { - double x = point.getX() * Math.cos(unit.phi()) - point.getZ() * Math.sin(unit.phi()); - double y = point.getY(); - double z = point.getX() * Math.sin(unit.phi()) + point.getZ() * Math.cos(unit.phi()); + double x = point.getX().multiply(Math.cos(unit.phi())) + - point.getZ().multiply(Math.sin(unit.phi())); + double y = point.getY().get(); + double z = point.getX().multiply(Math.sin(unit.phi())) + + point.getZ().multiply(Math.cos(unit.phi())); - return new Point3D(x, y, z); + return Point.fromDouble(x, y, z); } /** @@ -65,15 +70,17 @@ public class Rotator { * This will rotate the point around the z-axis. * * @param point the point to rotate. - * @param unit the spherical unit to rotate the point with. + * @param unit the spherical unit to rotate the point with. * @return the rotated point. */ public static IPoint3D rotateZ(IPoint3D point, SphericalUnit unit) { - double x = point.getX() * Math.cos(unit.theta()) - point.getY() * Math.sin(unit.theta()); - double y = point.getX() * Math.sin(unit.theta()) + point.getY() * Math.cos(unit.theta()); - double z = point.getZ(); + double x = point.getX().multiply(Math.cos(unit.theta())) + - point.getY().multiply(Math.sin(unit.theta())); + double y = point.getX().multiply(Math.sin(unit.theta())) + + point.getY().multiply(Math.cos(unit.theta())); + double z = point.getZ().get(); - return new Point3D(x, y, z); + return Point.fromDouble(x, y, z); } /** @@ -83,19 +90,19 @@ public class Rotator { * * @param point the point to rotate. * @param delta the delta values to rotate the point with. - * @param unit the spherical unit to rotate the point with. + * @param unit the spherical unit to rotate the point with. * @return the rotated point. */ public static IPoint3D fullRotation(IPoint3D point, Delta delta, SphericalUnit unit) { double r = unit.radius() * Math.cos(unit.theta() + delta.theta()) * Math.cos(unit.phi() + delta.phi()); - double theta = Math.atan2(point.getX(), point.getZ()) + delta.theta(); - double phi = Math.atan2(Utilities.magnitudeOf(point.getX(), point.getZ()), point.getY()) + delta.phi(); + double theta = Math.atan2(point.getX().get(), point.getZ().get()) + delta.theta(); + double phi = Math.atan2(Utilities.magnitudeOf(point.getX().get(), point.getZ().get()), point.getY().get()) + delta.phi(); double xRot = r * Math.sin(theta) * Math.cos(phi); double yRot = r * Math.cos(theta); double zRot = r * Math.sin(theta) * Math.sin(phi); - return new Point3D(xRot, yRot, zRot); + return Point.fromDouble(xRot, yRot, zRot); } /** @@ -104,13 +111,15 @@ public class Rotator { * This will rotate the point around the x-axis. * * @param point the point to rotate. - * @param unit the polar unit to rotate the point with. + * @param unit the polar unit to rotate the point with. * @return the rotated point. */ public static IPoint2D rotateX(IPoint2D point, PolarUnit unit) { - double x = point.getZ() * Math.cos(unit.theta()) - point.getX() * Math.sin(unit.theta()); - double z = point.getZ() * Math.sin(unit.theta()) + point.getX() * Math.cos(unit.theta()); - return new Point2D(x, z); + double x = point.getZ().multiply(Math.cos(unit.theta())) + - point.getX().multiply(Math.sin(unit.theta())); + double z = point.getZ().multiply(Math.sin(unit.theta())) + + point.getX().multiply(Math.cos(unit.theta())); + return Point.fromDouble(x, z); } /** @@ -119,13 +128,15 @@ public class Rotator { * This will rotate the point around the y-axis. * * @param point the point to rotate. - * @param unit the polar unit to rotate the point with. + * @param unit the polar unit to rotate the point with. * @return the rotated point. */ public static IPoint2D rotateZ(IPoint2D point, PolarUnit unit) { - double x = point.getX() * Math.cos(unit.theta()) - point.getZ() * Math.sin(unit.theta()); - double z = point.getX() * Math.sin(unit.theta()) + point.getZ() * Math.cos(unit.theta()); - return new Point2D(x, z); + double x = point.getX().multiply(Math.cos(unit.theta())) + - point.getZ().multiply(Math.sin(unit.theta())); + double z = point.getX().multiply(Math.sin(unit.theta())) + + point.getZ().multiply(Math.cos(unit.theta())); + return Point.fromDouble(x, z); } /** @@ -134,48 +145,50 @@ public class Rotator { * This will rotate the point around the x-axis and z-axis. * * @param point the point to rotate. - * @param unit the polar unit to rotate the point with. + * @param unit the polar unit to rotate the point with. * @return the rotated point. */ public static IPoint2D fullRotation(IPoint2D point, SphericalUnit unit) { - double x = point.getX() * Math.cos(unit.theta()) - point.getZ() * Math.sin(unit.theta()); - double z = point.getX() * Math.sin(unit.theta()) + point.getZ() * Math.cos(unit.theta()); - return new Point2D(x, z); + double x = point.getX().multiply(Math.cos(unit.theta())) + - point.getZ().multiply(Math.sin(unit.theta())); + double z = point.getX().multiply(Math.sin(unit.theta())) + + point.getZ().multiply(Math.cos(unit.theta())); + return Point.fromDouble(x, z); } /** * Rotates a point in 3d space using a quaternion. * The returned result is a point in 3d space represented by {@link IPoint3D}. * - * @param point the point to rotate. + * @param point the point to rotate. * @param quaternion the quaternion to rotate the point with. * @return the rotated point. */ public static IPoint3D rotate(IPoint3D point, IQuaternion quaternion) { - IQuaternion pQuat = new Quaternion(0.0, point.getX(), point.getY(), point.getZ()); + IQuaternion pQuat = new Quaternion(0.0, point.getX().get(), point.getY().get(), point.getZ().get()); IQuaternion conjugate = quaternion.conjugate(); IQuaternion w = conjugate.multiply(pQuat).multiply(quaternion); - return new Point3D(w.getX(), w.getY(), w.getZ()); + return Point.fromDouble(w.getX(), w.getY(), w.getZ()); } /** * Rotates a point in 2d space using a quaternion. * The returned result is a point in 2d space represented by {@link IPoint2D}. * - * @param point the point to rotate. + * @param point the point to rotate. * @param quaternion the quaternion to rotate the point with. * @return the rotated point. */ public static IPoint2D rotate(IPoint2D point, IQuaternion quaternion) { - IQuaternion pQuat = new Quaternion(0.0, point.getX(), 0.0, point.getZ()); + IQuaternion pQuat = new Quaternion(0.0, point.getX().get(), 0.0, point.getZ().get()); IQuaternion conjugate = quaternion.conjugate(); IQuaternion w = conjugate.multiply(pQuat).multiply(quaternion); - return new Point2D(w.getX(), w.getZ()); + return Point.fromDouble(w.getX(), w.getZ()); } } diff --git a/Commons/src/main/java/io/github/simplexdev/polarize/util/Utilities.java b/Converter/src/main/java/io/github/simplexdev/polarize/util/Utilities.java similarity index 99% rename from Commons/src/main/java/io/github/simplexdev/polarize/util/Utilities.java rename to Converter/src/main/java/io/github/simplexdev/polarize/util/Utilities.java index 0a33d12..61fd16c 100644 --- a/Commons/src/main/java/io/github/simplexdev/polarize/util/Utilities.java +++ b/Converter/src/main/java/io/github/simplexdev/polarize/util/Utilities.java @@ -26,6 +26,7 @@ public class Utilities { * This represents 360 degrees in radians. */ public static final double RADIAN_360 = Math.PI * 2; + private Utilities() { throw new AssertionError(); } diff --git a/Converter/src/test/java/io/github/simplexdev/polarize/math/FibonacciLatticeTest.java b/Converter/src/test/java/io/github/simplexdev/polarize/math/FibonacciLatticeTest.java new file mode 100644 index 0000000..66e5510 --- /dev/null +++ b/Converter/src/test/java/io/github/simplexdev/polarize/math/FibonacciLatticeTest.java @@ -0,0 +1,23 @@ +package io.github.simplexdev.polarize.math; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.github.simplexdev.polarize.api.spatial.IPoint3D; +import io.github.simplexdev.polarize.cartesian.Point3D; +import io.github.simplexdev.polarize.log.PolarizeLogger; +import io.github.simplexdev.polarize.math.function.FibonacciLattice; +import org.junit.jupiter.api.Test; + +class FibonacciLatticeTest +{ + /** + * Method under test: {@link FibonacciLattice#populate(IPoint3D, int, double)} + */ + @Test + void testDisplayPoints() + { + FibonacciLattice.populate(new Point3D(10,15,5), 10, 0.1) + .forEach(point -> PolarizeLogger.info("X: " + point.getX() + " Y: " + point.getY() + " Z: " + point.getZ())); + } +} + diff --git a/Converter/src/test/java/io/github/simplexdev/polarize/math/Point3DTest.java b/Converter/src/test/java/io/github/simplexdev/polarize/math/Point3DTest.java new file mode 100644 index 0000000..ebb52d6 --- /dev/null +++ b/Converter/src/test/java/io/github/simplexdev/polarize/math/Point3DTest.java @@ -0,0 +1,20 @@ +package io.github.simplexdev.polarize.math; + +import io.github.simplexdev.polarize.cartesian.Point3D; +import org.junit.jupiter.api.Test; + +class Point3DTest +{ + /** + * Method under test: {@link Point3D#drawLineTestMethod()} + */ + @Test + void testDrawLineTestMethod() + { + // TODO: Complete this test. + // Diffblue AI was unable to find a test + + (new Point3D(2.0d, 3.0d, 10.0d)).drawLineTestMethod(); + } +} + diff --git a/build.gradle b/build.gradle index b3e16ef..63ce6cb 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ subprojects { } tasks.build { - dependsOn(":Commons:build", ":Paper:build") + dependsOn(":Converter:build", ":Bukkit:build") } test { diff --git a/settings.gradle b/settings.gradle index 1c3324f..4d3f3c1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'Polarize' -include 'Commons' -include 'Paper' +include 'Converter' +include 'Bukkit' +include 'Caravan' +include 'Caravan'