Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle/libs.versions.toml
  • Loading branch information
Radu-Voinea committed Nov 25, 2024
2 parents 2c267a4 + a8be837 commit 6daf01c
Show file tree
Hide file tree
Showing 52 changed files with 237 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
version = "1.1.6"
version = "1.1.9"
group = "com.voinearadu"

[plugins]
Expand Down
174 changes: 174 additions & 0 deletions src/main/java/com/voinearadu/generic/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package com.voinearadu.generic;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;

@NoArgsConstructor
@Getter
@Setter
public class Location {

private double x;
private double y;
private double z;
private float pitch;
private float yaw;
private @Nullable String world;

public Location(double x, double y, double z, float pitch, float yaw, @Nullable String world) {
this.x = x;
this.y = y;
this.z = z;
this.pitch = pitch;
this.yaw = yaw;
this.world = world;
}

public Location(double x, double y, double z, @Nullable String world) {
this(x, y, z, 0, 0, world);
}

public Location(double x, double y, double z, float pitch, float yaw) {
this(x, y, z, pitch, yaw, null);
}

public Location(double x, double y, double z) {
this(x, y, z, null);
}


public Location offset(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}

public Location negativeOffset(double x, double y, double z) {
return offset(-x, -y, -z);
}

public Location offsetNew(double x, double y, double z, float pitch, float yaw) {
Location output = clone();

output.x += x;
output.y += y;
output.z += z;
output.pitch += pitch;
output.yaw += yaw;

return output;
}

public Location offsetNew(double x, double y, double z) {
return offsetNew(x, y, z, 0, 0);
}

public Location negativeOffsetNew(double x, double y, double z) {
return offsetNew(-x, -y, -z);
}

public Location negativeOffsetNew(Location offset) {
return negativeOffsetNew(
offset.x,
offset.y,
offset.z
);
}

public Location offset(Location offset) {
return offset(offset.x, offset.y, offset.z);
}

@SuppressWarnings("unused")
public Location negativeOffset(Location offset) {
return negativeOffset(offset.x, offset.y, offset.z);
}

public Location offsetNew(Location offset) {
return offsetNew(
offset.x,
offset.y,
offset.z,
offset.pitch,
offset.yaw
);
}

@SuppressWarnings("UnusedReturnValue")
public Location multiply(double factor) {
this.x *= factor;
this.y *= factor;
this.z *= factor;

return this;
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
public Location clone() {
return new Location(x, y, z, pitch, yaw, world);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Location location)) return false;

if (getX() != location.getX()) return false;
if (getY() != location.getY()) return false;
if (getZ() != location.getZ()) return false;
return getWorld() != null ? getWorld().equals(location.getWorld()) : location.getWorld() == null;
}

public boolean equalsCoords(Object o) {
if (this == o) return true;
if (!(o instanceof Location location)) return false;

return x == location.x && y == location.y && z == location.z;
}

@Override
public int hashCode() {
double result = getX();
result = 31 * result + getY();
result = 31 * result + getZ();
result = 31 * result + getPitch();
result = 31 * result + getYaw();
result = 31 * result + (getWorld() != null ? getWorld().hashCode() : 0);
return (int) result;
}

public static Location min(Location... locations) {
double minX = 1000000000;
double minY = 1000000000;
double minZ = 1000000000;

for (Location location : locations) {
minX = Double.min(minX, location.getX());
minY = Double.min(minY, location.getY());
minZ = Double.min(minZ, location.getZ());
}

return new Location(minX, minY, minZ);
}

public static Location max(Location... locations) {
double maxX = -1000000000;
double maxY = -1000000000;
double maxZ = -1000000000;

for (Location location : locations) {
maxX = Double.max(maxX, location.getX());
maxY = Double.max(maxY, location.getY());
maxZ = Double.max(maxZ, location.getZ());
}

return new Location(maxX, maxY, maxZ);
}

public String toCompactString() {
return "(" + x + ", " + y + ", " + z + ")";
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/voinearadu/generic/Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.voinearadu.generic;

public record Pair<Value1, Value2>(Value1 value1, Value2 value2) {

}
20 changes: 20 additions & 0 deletions src/main/java/com/voinearadu/generic/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.voinearadu.generic;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Getter
public class Range {

private int min;
private int max;

@SuppressWarnings("unused")
public static Range exact(int n) {
return new Range(n, n);
}

}
3 changes: 3 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
exports com.voinearadu.event_manager;
exports com.voinearadu.file_manager;
exports com.voinearadu.lambda;
exports com.voinearadu.lambda.lambda;
exports com.voinearadu.logger;
exports com.voinearadu.logger.dto;
exports com.voinearadu.message_builder;
exports com.voinearadu.redis_manager;
exports com.voinearadu.reflections;
exports com.voinearadu.generic;

requires static lombok;
requires static org.jetbrains.annotations;
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/voinearadu/generic/LocationTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.voinearadu.generic;

import com.voinearadu.file_manager.dto.files.FileObject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class LocationTests {

@Test
public void testOffsets() {
Location location = new Location(1, 2, 3);
assertEquals(new Location(2, 4, 6), location.offsetNew(1, 2, 3));
assertEquals(new Location(0, 0, 0), location.negativeOffsetNew(1, 2, 3));
location.offset(1, 2, 3);
assertEquals(new Location(2, 4, 6), location);
location.negativeOffset(2, 4, 6);
assertEquals(new Location(0, 0, 0), location);
location.offset(1, 2, 3);
location.multiply(2);
assertEquals(new Location(2, 4, 6), location);
assertEquals(new Location(1,1,1), Location.min(
new Location(1,100, 100),
new Location(100,1, 100),
new Location(100,100, 1)
));
assertEquals(new Location(100,100,100), Location.max(
new Location(100,1, 1),
new Location(1,100, 1),
new Location(1,1, 100)
));
}

}

0 comments on commit 6daf01c

Please sign in to comment.