Update to 1.0.1

This commit is contained in:
bi0qaw 2017-11-25 17:49:24 +01:00
parent 93b170b404
commit e36f3041c2
13 changed files with 207 additions and 38 deletions

View File

@ -6,7 +6,7 @@
<groupId>io.github.bi0qaw</groupId> <groupId>io.github.bi0qaw</groupId>
<artifactId>biosphere2</artifactId> <artifactId>biosphere2</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0.1</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -23,7 +23,7 @@ public class Biosphere extends JavaPlugin {
Skript.registerExpression(ExprDegToRad.class, Number.class, ExpressionType.PROPERTY, "%number% [in] rad[ian]"); Skript.registerExpression(ExprDegToRad.class, Number.class, ExpressionType.PROPERTY, "%number% [in] rad[ian]");
Skript.registerExpression(ExprRadToDeg.class, Number.class, ExpressionType.PROPERTY, "%number% [in] deg[ree]"); Skript.registerExpression(ExprRadToDeg.class, Number.class, ExpressionType.PROPERTY, "%number% [in] deg[ree]");
Skript.registerExpression(ExprFrameFromEntity.class, Frame.class, ExpressionType.SIMPLE, new String[]{"frame of %entity%", "%entity%['s] frame"}); Skript.registerExpression(ExprFrameFromEntity.class, Frame.class, ExpressionType.SIMPLE, "frame of %entity%", "%entity%['s] frame");
Skript.registerExpression(ExprFrameFromYawPitch.class, Frame.class, ExpressionType.SIMPLE, "frame with yaw %number% and pitch %number%"); Skript.registerExpression(ExprFrameFromYawPitch.class, Frame.class, ExpressionType.SIMPLE, "frame with yaw %number% and pitch %number%");
Skript.registerExpression(ExprFrameYawPitch.class, Number.class, ExpressionType.PROPERTY, "frame (0¦yaw|1¦pitch) of %frame%"); Skript.registerExpression(ExprFrameYawPitch.class, Number.class, ExpressionType.PROPERTY, "frame (0¦yaw|1¦pitch) of %frame%");
@ -32,18 +32,19 @@ public class Biosphere extends JavaPlugin {
Skript.registerExpression(ExprLocationCubeOutline.class, Location.class, ExpressionType.SIMPLE, "cube[s] outline[s] at %locations% with radius %number%(,| and) density %number%"); Skript.registerExpression(ExprLocationCubeOutline.class, Location.class, ExpressionType.SIMPLE, "cube[s] outline[s] at %locations% with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationCylinderLoc.class, Location.class, ExpressionType.SIMPLE, "cylinder coordinate[s] at %locations% with radius %number%(,| and) yaw %number%(,| and) height %number%"); Skript.registerExpression(ExprLocationCylinderLoc.class, Location.class, ExpressionType.SIMPLE, "cylinder coordinate[s] at %locations% with radius %number%(,| and) yaw %number%(,| and) height %number%");
Skript.registerExpression(ExprLocationHelix.class, Location.class, ExpressionType.SIMPLE, "heli(x|xes|ces) at %locations% with radius %number%(,| and) height %number%(,| and) step[(height|size)] %number%(,| and) density %number%"); Skript.registerExpression(ExprLocationHelix.class, Location.class, ExpressionType.SIMPLE, "heli(x|xes|ces) at %locations% with radius %number%(,| and) height %number%(,| and) step[(height|size)] %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationLine.class, Location.class, ExpressionType.SIMPLE, "line[s] from %locations% to %location% with density %number%"); Skript.registerExpression(ExprLocationLine.class, Location.class, ExpressionType.SIMPLE, "line[s] (between|from) %locations% (and|to) %location% with density %number%");
Skript.registerExpression(ExprLocationLineLoc.class, Location.class, ExpressionType.SIMPLE, "line[ar] (coordinate[s]|position[s]|location[s]) %number% from %locations% to %location%"); Skript.registerExpression(ExprLocationLineLoc.class, Location.class, ExpressionType.SIMPLE, "line[ar] (coordinate[s]|position[s]|location[s]) %number% from %locations% to %location%");
Skript.registerExpression(ExprLocationLinkAll.class, Location.class, ExpressionType.SIMPLE, "%locations% (linked|connected) with density %number%"); Skript.registerExpression(ExprLocationLinkAll.class, Location.class, ExpressionType.SIMPLE, "%locations% (linked|connected) with density %number%");
Skript.registerExpression(ExprLocationMidpoint.class, Location.class, ExpressionType.SIMPLE, "[location ]midpoint of %locations%"); Skript.registerExpression(ExprLocationMidpoint.class, Location.class, ExpressionType.SIMPLE, "[location ]midpoint of %locations%");
Skript.registerExpression(ExprLocationMove.class, Location.class, ExpressionType.SIMPLE, new String[]{"%locations% with center %location% (moved|shifted) to %location%", "%locations% with center %location% (moved|shifted) to %location%"}); Skript.registerExpression(ExprLocationMove.class, Location.class, ExpressionType.SIMPLE, "%locations% with center %location% (moved|shifted) to %location%", "%locations% with center %location% (moved|shifted) to %location%");
Skript.registerExpression(ExprLocationOffset.class, Location.class, ExpressionType.SIMPLE, "%locations% offset by %vectors%"); Skript.registerExpression(ExprLocationOffset.class, Location.class, ExpressionType.SIMPLE, "[location[s]] %locations% offset by %vectors%");
Skript.registerExpression(ExprLocationPath.class, Location.class, ExpressionType.SIMPLE, "[location ]path between %locations% with density %number%");
Skript.registerExpression(ExprLocationPolygon.class, Location.class, ExpressionType.SIMPLE, "polygon[s] at %locations% with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%"); Skript.registerExpression(ExprLocationPolygon.class, Location.class, ExpressionType.SIMPLE, "polygon[s] at %locations% with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%");
Skript.registerExpression(ExprLocationPolygonOutline.class, Location.class, ExpressionType.SIMPLE, "polygon[s] outline[s] at %locations% with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%(,| and) density %number%"); Skript.registerExpression(ExprLocationPolygonOutline.class, Location.class, ExpressionType.SIMPLE, "polygon[s] outline[s] at %locations% with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationReflection.class, Location.class, ExpressionType.SIMPLE, "%locations% (mirrored|reflected) at %location%[ (in|with) direction [of ]%-vector%]"); Skript.registerExpression(ExprLocationReflection.class, Location.class, ExpressionType.SIMPLE, "%locations% (mirrored|reflected) at %location%[ (in|with) direction [of ]%-vector%]");
Skript.registerExpression(ExprLocationRotate.class, Location.class, ExpressionType.SIMPLE, "%locations% rotated around %vector% at %location% (with angle|by) %number%[ degree[s]]"); Skript.registerExpression(ExprLocationRotate.class, Location.class, ExpressionType.SIMPLE, "%locations% rotated around %vector% at %location% (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprLocationRotXYZ.class, Location.class, ExpressionType.SIMPLE, "%locations% rotated around (1¦x|2¦y|3¦z)(-| )axis at %location% (with angle|by) %number%[ degree[s]]"); Skript.registerExpression(ExprLocationRotXYZ.class, Location.class, ExpressionType.SIMPLE, "%locations% rotated around (1¦x|2¦y|3¦z)(-| )axis at %location% (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprLocationScale.class, Location.class, ExpressionType.SIMPLE, "%locations% scaled at %location% by %number%[ (in|with|and) direction %-vector%]"); Skript.registerExpression(ExprLocationScale.class, Location.class, ExpressionType.SIMPLE, "%locations% scaled at %location% by %number%[ (in|with|and) direction [of ]%-vector%]");
Skript.registerExpression(ExprLocationSphere.class, Location.class, ExpressionType.SIMPLE, "sphere[s] at %locations% with radius %number%(,| and) density %number%"); Skript.registerExpression(ExprLocationSphere.class, Location.class, ExpressionType.SIMPLE, "sphere[s] at %locations% with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationSphereLoc.class, Location.class, ExpressionType.SIMPLE, "spher(e|ic[al]) (coordinate[s]|position[s]|location[s]) at %locations% with radius %number%(,| and) yaw %number%(,| and) pitch %number%"); Skript.registerExpression(ExprLocationSphereLoc.class, Location.class, ExpressionType.SIMPLE, "spher(e|ic[al]) (coordinate[s]|position[s]|location[s]) at %locations% with radius %number%(,| and) yaw %number%(,| and) pitch %number%");
Skript.registerExpression(ExprLocationSphereRand.class, Location.class, ExpressionType.SIMPLE, "random sphere[s] at %locations% with radius %number%(,| and) density %number%"); Skript.registerExpression(ExprLocationSphereRand.class, Location.class, ExpressionType.SIMPLE, "random sphere[s] at %locations% with radius %number%(,| and) density %number%");
@ -54,16 +55,18 @@ public class Biosphere extends JavaPlugin {
Skript.registerExpression(ExprVectorHelix.class, Vector.class, ExpressionType.SIMPLE, "[vector ]helix with radius %number%(,| and) height %number%(,| and) step[(height|size)] %number%(,| and) density %number%"); Skript.registerExpression(ExprVectorHelix.class, Vector.class, ExpressionType.SIMPLE, "[vector ]helix with radius %number%(,| and) height %number%(,| and) step[(height|size)] %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorInFrame.class, Vector.class, ExpressionType.SIMPLE, "[vector ]%vectors% in %frame%"); Skript.registerExpression(ExprVectorInFrame.class, Vector.class, ExpressionType.SIMPLE, "[vector ]%vectors% in %frame%");
Skript.registerExpression(ExprVectorLine.class, Vector.class, ExpressionType.SIMPLE, "[vector ]line with length %number%(,| and) density %number%"); Skript.registerExpression(ExprVectorLine.class, Vector.class, ExpressionType.SIMPLE, "[vector ]line with length %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorLineBetweenVectors.class, Vector.class, ExpressionType.SIMPLE, "vector line between %vector% and %vector% with density %number%"); Skript.registerExpression(ExprVectorLineBetweenVectors.class, Vector.class, ExpressionType.SIMPLE, "vector line (between|from) %vector% (and|to) %vector% with density %number%");
Skript.registerExpression(ExprVectorLinkAll.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% (linked|connected) with density %number%"); Skript.registerExpression(ExprVectorLinkAll.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% (linked|connected) with density %number%");
Skript.registerExpression(ExprVectorMidpoint.class, Vector.class, ExpressionType.SIMPLE, "vector midpoint of %vectors%"); Skript.registerExpression(ExprVectorMidpoint.class, Vector.class, ExpressionType.SIMPLE, "vector midpoint of %vectors%");
Skript.registerExpression(ExprVectorMove.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% moved by %vector%"); Skript.registerExpression(ExprVectorMove.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% moved by %vectors%");
Skript.registerExpression(ExprVectorOffset.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% offset by %vectors%");
Skript.registerExpression(ExprVectorPath.class, Vector.class, ExpressionType.SIMPLE, "vector[s] path between %vectors% with density %number%");
Skript.registerExpression(ExprVectorPolygon.class, Vector.class, ExpressionType.SIMPLE, "[vector ]polygon with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%"); Skript.registerExpression(ExprVectorPolygon.class, Vector.class, ExpressionType.SIMPLE, "[vector ]polygon with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%");
Skript.registerExpression(ExprVectorPolygonOutline.class, Vector.class, ExpressionType.SIMPLE, "[vector ]polygon outline with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%(,|and) density %number%"); Skript.registerExpression(ExprVectorPolygonOutline.class, Vector.class, ExpressionType.SIMPLE, "[vector ]polygon outline with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%(,|and) density %number%");
Skript.registerExpression(ExprVectorReflection.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% (mirrored|reflected) at %vector%[ (in|with) direction [of ]%-vector%]"); Skript.registerExpression(ExprVectorReflection.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% (mirrored|reflected) at %vector%[ (in|with) direction [of ]%-vector%]");
Skript.registerExpression(ExprVectorRotate.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% rotated around %vector% (with angle|by) %number%[ degree[s]]"); Skript.registerExpression(ExprVectorRotate.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% rotated around %vector% (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprVectorRotateXYZ.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% rotated around (1¦x|2¦y|3¦z)(-| )axis (with angle|by) %number%[ degree[s]]"); Skript.registerExpression(ExprVectorRotateXYZ.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% rotated around (1¦x|2¦y|3¦z)(-| )axis (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprVectorScale.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% scaled by %number%[ (in|with|and) direction %-vector%]"); Skript.registerExpression(ExprVectorScale.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% scaled by %number%[ (in|with|and) direction [of ]%-vector%]");
Skript.registerExpression(ExprVectorSphere.class, Vector.class, ExpressionType.SIMPLE, "[vector ]sphere with radius %number%(,| and) density %number%"); Skript.registerExpression(ExprVectorSphere.class, Vector.class, ExpressionType.SIMPLE, "[vector ]sphere with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorSphereRand.class, Vector.class, ExpressionType.SIMPLE, "[vector ]random sphere with radius %number%(,| and) density %number%"); Skript.registerExpression(ExprVectorSphereRand.class, Vector.class, ExpressionType.SIMPLE, "[vector ]random sphere with radius %number%(,| and) density %number%");
} }

View File

@ -0,0 +1,42 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.bi0qaw.biosphere.util.LocationLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
public class ExprLocationPath extends SimpleExpression<Location> {
private Expression<Location> locations;
private Expression<Number> density;
@Override
protected Location[] get(Event event) {
return LocationLib.getPath(locations.getArray(event), density.getSingle(event).doubleValue());
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public String toString(Event event, boolean b) {
return "path between" + locations.toString(event, b) + "with density " + density.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
locations = (Expression<Location>) expressions[0];
density = (Expression<Number>) expressions[1];
return true;
}
}

View File

@ -16,7 +16,7 @@ import javax.annotation.Nullable;
@Name("Vector Offset") @Name("Vector Offset")
@Description("Offset vectors by other vectors.") @Description("Offset vectors by other vectors.")
@Examples({"set {_circle::*} to circle with radius 1 and density 5", @Examples({"set {_circle::*} to circle with radius 1 and density 5",
"set {_offset::*} to {_circle::*} offset by vector 1, 2, 3", "set {_offset::*} to {_circle::*} moved by vector 1, 2, 3",
"#Moves the circle from the origin (vector 0, 0, 0) to the position at 1, 2, 3"}) "#Moves the circle from the origin (vector 0, 0, 0) to the position at 1, 2, 3"})
public class ExprVectorMove extends SimpleExpression<Vector> { public class ExprVectorMove extends SimpleExpression<Vector> {
@ -54,6 +54,6 @@ public class ExprVectorMove extends SimpleExpression<Vector> {
for (Vector v: o) { for (Vector v: o) {
totalOffset.add(v); totalOffset.add(v);
} }
return VectorLib.offset(vectors.getArray(e).clone(), totalOffset); return VectorLib.move(VectorLib.clone(vectors.getArray(e)), totalOffset);
} }
} }

View File

@ -0,0 +1,42 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
public class ExprVectorOffset extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Vector> offsets;
@Override
protected Vector[] get(Event event) {
return VectorLib.offset(vectors.getArray(event), offsets.getArray(event));
}
@Override
public boolean isSingle() {
return vectors.isSingle() && offsets.isSingle();
}
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public String toString(Event event, boolean b) {
return "vector " + vectors.toString(event, b) + " offset by " + offsets.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expressions[0];
offsets = (Expression<Vector>) expressions[1];
return true;
}
}

View File

@ -0,0 +1,42 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
public class ExprVectorPath extends SimpleExpression<Vector>{
private Expression<Vector> vectors;
private Expression<Number> density;
@Override
protected Vector[] get(Event event) {
return VectorLib.getPath(vectors.getArray(event), density.getSingle(event).doubleValue());
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public String toString(Event event, boolean b) {
return "vector path between " + vectors.toString(event, b) + " with density " + density.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expressions[0];
density = (Expression<Number>) expressions[1];
return true;
}
}

View File

@ -50,11 +50,12 @@ public class ExprVectorReflection extends SimpleExpression<Vector> {
@Override @Override
@Nullable @Nullable
protected Vector[] get(Event e) { protected Vector[] get(Event e) {
Vector[] clones = VectorLib.clone(vectors.getArray(e));
if (direction == null) { if (direction == null) {
return VectorLib.pointReflection(vectors.getArray(e).clone(), center.getSingle(e)); return VectorLib.pointReflection(clones, center.getSingle(e));
} }
else { else {
return VectorLib.reflection(vectors.getArray(e).clone(), center.getSingle(e), direction.getSingle(e)); return VectorLib.reflection(clones, center.getSingle(e), direction.getSingle(e));
} }
} }
} }

View File

@ -56,7 +56,7 @@ public class ExprVectorRotate extends SimpleExpression<Vector> {
float a = angle.getSingle(e).floatValue(); float a = angle.getSingle(e).floatValue();
a = -a; //Skript uses clockwise and VectorMath anti-clockwise rotation a = -a; //Skript uses clockwise and VectorMath anti-clockwise rotation
Vector ax = axis.getSingle(e).clone().normalize(); Vector ax = axis.getSingle(e).clone().normalize();
return VectorLib.rotate(vectors.getArray(e).clone(), ax, a); return VectorLib.rotate(VectorLib.clone(vectors.getArray(e)), ax, a);
} }
} }

View File

@ -54,14 +54,15 @@ public class ExprVectorRotateXYZ extends SimpleExpression<Vector> {
protected Vector[] get(Event e) { protected Vector[] get(Event e) {
float a = angle.getSingle(e).floatValue(); float a = angle.getSingle(e).floatValue();
a = -a; //Skript uses clockwise and VectorMath anti-clockwise rotation a = -a; //Skript uses clockwise and VectorMath anti-clockwise rotation
Vector[] clones = VectorLib.clone(vectors.getArray(e));
if (axis == 1) { if (axis == 1) {
return VectorLib.rotateX(vectors.getArray(e).clone(), a); return VectorLib.rotateX(clones, a);
} }
else if (axis == 2) { else if (axis == 2) {
return VectorLib.rotateY(vectors.getArray(e).clone(), a); return VectorLib.rotateY(clones, a);
} }
else { else {
return VectorLib.rotateZ(vectors.getArray(e).clone(), a); return VectorLib.rotateZ(clones, a);
} }
} }

View File

@ -59,10 +59,10 @@ public class ExprVectorScale extends SimpleExpression<Vector> {
protected Vector[] get(Event e) { protected Vector[] get(Event e) {
double f = factor.getSingle(e).doubleValue(); double f = factor.getSingle(e).doubleValue();
if (direction == null) { if (direction == null) {
return VectorLib.scale(vectors.getArray(e).clone(), f); return VectorLib.scale(VectorLib.clone(vectors.getArray(e).clone()), f);
} }
else { else {
return VectorLib.scaleDirectional(vectors.getArray(e).clone(), direction.getSingle(e), f); return VectorLib.scaleDirectional(VectorLib.clone(vectors.getArray(e)), direction.getSingle(e), f);
} }
} }
} }

View File

@ -56,6 +56,17 @@ public class LocationLib {
return locations; return locations;
} }
public static Location[] getPath(Location[] locations, double density) {
if (locations.length > 0) {
Vector[] path = VectorLib.getPath(VectorLib.toVector(locations), density);
World world = locations[0].getWorld();
return toLocation(path, world);
}
else {
return new Location[]{};
}
}
public static Location[] getPolygon(Location[] locations, int points, double radius) { public static Location[] getPolygon(Location[] locations, int points, double radius) {
Vector[] polygon = VectorLib.getPolygon(points, radius); Vector[] polygon = VectorLib.getPolygon(points, radius);
return offset(locations, polygon); return offset(locations, polygon);
@ -85,14 +96,8 @@ public class LocationLib {
if (locations.length > 0) { if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(locations); Vector[] vectors = VectorLib.toVector(locations);
Vector[] linked = VectorLib.linkAll(vectors, density); Vector[] linked = VectorLib.linkAll(vectors, density);
Location[] linkedLocations = new Location[linked.length];
World world = locations[0].getWorld(); World world = locations[0].getWorld();
int i = 0; return toLocation(linked, world);
for (Vector v: linked) {
linkedLocations[i] = v.toLocation(world);
i++;
}
return linkedLocations;
} }
else { else {
return new Location[] {}; return new Location[] {};

View File

@ -50,6 +50,18 @@ public class VectorLib {
return getPolygon(n, radius); return getPolygon(n, radius);
} }
public static Vector[] getPath(Vector[] vectors, double density) {
List<Vector> path = new ArrayList<Vector>();
int length = vectors.length;
if (length < 2) {
return vectors;
}
for (int i = 0; i < length - 1; i++) {
path.addAll(Arrays.asList(linkLine(vectors[i], vectors[i+1], density)));
}
return path.toArray(new Vector[path.size()]);
}
public static Vector[] getPolygon(int points, double radius) { public static Vector[] getPolygon(int points, double radius) {
float deltaAngle = 360 / (float) points; float deltaAngle = 360 / (float) points;
Vector[] vectors = new Vector[points]; Vector[] vectors = new Vector[points];
@ -106,7 +118,7 @@ public class VectorLib {
} }
public static Vector[] getHelix(double radius, double height, double step, double density) { public static Vector[] getHelix(double radius, double height, double step, double density) {
int points = (int) ( height * 2 * Math.PI * radius * density); int points = (int) ( Math.abs(height) * 2 * Math.PI * Math.abs(radius) * density);
double deltaAngle = 360 * height / (step * points); double deltaAngle = 360 * height / (step * points);
double deltaHeight = height / points; double deltaHeight = height / points;
Vector[] vectors = new Vector[points]; Vector[] vectors = new Vector[points];
@ -118,11 +130,10 @@ public class VectorLib {
public static Vector[] linkAll(Vector[] vectors, double density) { public static Vector[] linkAll(Vector[] vectors, double density) {
List<Vector> vecs = new ArrayList<Vector>(); List<Vector> vecs = new ArrayList<Vector>();
for (Vector v1 : vectors) { int length = vectors.length;
for (Vector v2 : vectors) { for (int i = 0; i < length - 1; i++) {
if (!v1.equals(v2)) { for (int j = i + 1; j < length ; j++) {
vecs.addAll(Arrays.asList(linkLine(v1, v2, density))); vecs.addAll(Arrays.asList(linkLine(vectors[i], vectors[j], density)));
}
} }
} }
return vecs.toArray(new Vector[vecs.size()]); return vecs.toArray(new Vector[vecs.size()]);
@ -137,13 +148,25 @@ public class VectorLib {
return midpoint; return midpoint;
} }
public static Vector[] offset(Vector[] vectors, Vector offset) { public static Vector[] move(Vector[] vectors, Vector offset) {
for (Vector v: vectors) { for (Vector v: vectors) {
v.add(offset); v.add(offset);
} }
return vectors; return vectors;
} }
public static Vector[] offset(Vector[] vectors, Vector[] offsets) {
Vector[] offset = new Vector[vectors.length * offsets.length];
int i = 0;
for (Vector v: vectors) {
for (Vector o: offsets) {
offset[i] = v.clone().add(o);
i++;
}
}
return offset;
}
public static Vector[] pointReflection(Vector[] vectors, Vector center) { public static Vector[] pointReflection(Vector[] vectors, Vector center) {
for (Vector v: vectors) { for (Vector v: vectors) {
v.subtract(center).multiply(-1).add(center); v.subtract(center).multiply(-1).add(center);
@ -160,28 +183,28 @@ public class VectorLib {
public static Vector[] rotate(Vector[] vectors, Vector axis, double angle) { public static Vector[] rotate(Vector[] vectors, Vector axis, double angle) {
for (Vector v: vectors) { for (Vector v: vectors) {
v = VectorMath.rot(v, axis, angle); VectorMath.rot(v, axis, angle);
} }
return vectors; return vectors;
} }
public static Vector[] rotateX(Vector[] vectors, double angle) { public static Vector[] rotateX(Vector[] vectors, double angle) {
for (Vector v: vectors) { for (Vector v: vectors) {
v = VectorMath.rotX(v, angle); VectorMath.rotX(v, angle);
} }
return vectors; return vectors;
} }
public static Vector[] rotateY(Vector[] vectors, double angle) { public static Vector[] rotateY(Vector[] vectors, double angle) {
for (Vector v: vectors) { for (Vector v: vectors) {
v = VectorMath.rotY(v, angle); VectorMath.rotY(v, angle);
} }
return vectors; return vectors;
} }
public static Vector[] rotateZ(Vector[] vectors, double angle) { public static Vector[] rotateZ(Vector[] vectors, double angle) {
for (Vector v: vectors) { for (Vector v: vectors) {
v = VectorMath.rotZ(v, angle); VectorMath.rotZ(v, angle);
} }
return vectors; return vectors;
} }
@ -241,4 +264,14 @@ public class VectorLib {
} }
return vectors; return vectors;
} }
public static Vector[] clone(Vector[] vectors) {
Vector[] clones = new Vector[vectors.length];
int i = 0;
for (Vector v: vectors) {
clones[i] = v.clone();
i++;
}
return clones;
}
} }

View File

@ -1,4 +1,4 @@
name: Biosphere2 name: Biosphere2
main: io.github.bi0qaw.biosphere.Biosphere main: io.github.bi0qaw.biosphere.Biosphere
author: bi0qaw author: bi0qaw
version: 1.0.0 version: 1.0.1