Updating data
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package speiger.src.coreengine;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.lwjgl.opengl.ARBBaseInstance;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL31;
|
||||
import org.lwjgl.opengl.NVMeshShader;
|
||||
|
||||
import speiger.src.coreengine.application.Application;
|
||||
import speiger.src.coreengine.rendering.input.window.Window;
|
||||
import speiger.src.coreengine.rendering.input.window.WindowProvider;
|
||||
|
||||
public class Testing extends Application {
|
||||
public static void main(String... args) {
|
||||
System.out.println((int)1E-6F);
|
||||
new Testing().run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainWindowName() { return "Testing"; }
|
||||
|
||||
@Override
|
||||
public Window createWindow(WindowProvider provider) throws Exception {
|
||||
return provider.createBuilder().setWidth(250).setHeight(250).setName("Testing").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Path file) {
|
||||
System.out.println(GL11.glGetInteger(GL31.GL_MAX_UNIFORM_BUFFER_BINDINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float particalTicks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package speiger.src.coreengine.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.ObjLongConsumer;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
|
||||
import speiger.src.collections.objects.utils.ObjectLists;
|
||||
import speiger.src.coreengine.assets.AssetManager;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.reloader.ResourceReloader;
|
||||
import speiger.src.coreengine.rendering.gui.GuiManager;
|
||||
import speiger.src.coreengine.rendering.gui.base.DebugOverlay;
|
||||
@@ -18,20 +20,21 @@ import speiger.src.coreengine.rendering.input.Mouse;
|
||||
import speiger.src.coreengine.rendering.input.camera.Camera;
|
||||
import speiger.src.coreengine.rendering.input.window.Window;
|
||||
import speiger.src.coreengine.rendering.input.window.WindowProvider;
|
||||
import speiger.src.coreengine.rendering.shader.ProjectionBuffer;
|
||||
import speiger.src.coreengine.rendering.shader.ShaderTracker;
|
||||
import speiger.src.coreengine.rendering.textures.base.NativeMemoryParser;
|
||||
import speiger.src.coreengine.rendering.shaderOld.ProjectionBuffer;
|
||||
import speiger.src.coreengine.rendering.shaderOld.ShaderTracker;
|
||||
import speiger.src.coreengine.rendering.textures.base.TextureManager;
|
||||
import speiger.src.coreengine.rendering.utils.Cursor;
|
||||
import speiger.src.coreengine.utils.counters.timers.FPSTimer;
|
||||
import speiger.src.coreengine.utils.eventbus.EventBus;
|
||||
import speiger.src.coreengine.utils.helpers.FileUtils;
|
||||
import speiger.src.coreengine.utils.helpers.IOUtils;
|
||||
import speiger.src.coreengine.utils.profiler.GPUProfiler;
|
||||
import speiger.src.coreengine.utils.profiler.IProfiler;
|
||||
import speiger.src.coreengine.utils.profiler.Profiler;
|
||||
|
||||
public abstract class Application
|
||||
{
|
||||
private static Application INSTANCE;
|
||||
protected Path applicationFolder;
|
||||
protected FPSTimer timer;
|
||||
protected ApplicationExecutor executor = new ApplicationExecutor(this);
|
||||
protected IProfiler clientProfiler = new Profiler("Client Thread");
|
||||
@@ -47,7 +50,15 @@ public abstract class Application
|
||||
protected FontManager fonts = new FontManager();
|
||||
protected ProjectionBuffer projectionBuffer;
|
||||
protected GuiManager uiManager;
|
||||
|
||||
|
||||
protected Application() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
public static Application getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
GLFWErrorCallback.createPrint(System.err).set();
|
||||
@@ -69,10 +80,10 @@ public abstract class Application
|
||||
return;
|
||||
}
|
||||
Thread.currentThread().setName("Client Thread");
|
||||
File file = FileUtils.getBase();
|
||||
file = file.getName().endsWith(".jar") ? file : new File("bin/main");
|
||||
internalInit(file);
|
||||
init(file);
|
||||
applicationFolder = IOUtils.getBaseLocation();
|
||||
applicationFolder = IOUtils.endsWith(applicationFolder, ".jar") ? applicationFolder : Path.of("bin/main");
|
||||
internalInit();
|
||||
init(applicationFolder);
|
||||
if(!initEarly) mainWindow.finishWindow();
|
||||
executor.start(mainWindow);
|
||||
mainWindow.destroy();
|
||||
@@ -81,10 +92,8 @@ public abstract class Application
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
protected void internalInit(File file)
|
||||
{
|
||||
assetManager = reloader.addReloadableResource(new AssetManager(file), true);
|
||||
assetManager.registerAssetParser(ByteBuffer.class, new NativeMemoryParser());
|
||||
protected void internalInit() {
|
||||
assetManager = new AssetManager(gatherPackages());
|
||||
reloader.addReloadableResource(fonts);
|
||||
fonts.setAssetManager(assetManager);
|
||||
ShaderTracker.INSTANCE.init(assetManager);
|
||||
@@ -101,6 +110,7 @@ public abstract class Application
|
||||
projectionBuffer = new ProjectionBuffer(camera, mainWindow);
|
||||
}
|
||||
|
||||
public List<IAssetPackage> gatherPackages() { return ObjectLists.singleton(IAssetPackage.of(applicationFolder)); }
|
||||
public abstract String getMainWindowName();
|
||||
public void addExtraTickRates(IntConsumer ticks) {};
|
||||
public void addExtraTimers(ObjLongConsumer<String> profiler) {};
|
||||
@@ -109,7 +119,7 @@ public abstract class Application
|
||||
public DebugOverlay createCustomDebug() { return null; }
|
||||
public abstract Window createWindow(WindowProvider provider) throws Exception;
|
||||
public void preinit() {}
|
||||
public abstract void init(File file);
|
||||
public abstract void init(Path path);
|
||||
public void preUpdate() {}
|
||||
public abstract void update();
|
||||
public abstract void render(float particalTicks);
|
||||
@@ -131,8 +141,7 @@ public abstract class Application
|
||||
update();
|
||||
}
|
||||
|
||||
protected final void renderInternal(float particalTicks)
|
||||
{
|
||||
protected final void renderInternal(float particalTicks) {
|
||||
render(particalTicks);
|
||||
if(uiManager != null)
|
||||
{
|
||||
@@ -145,63 +154,16 @@ public abstract class Application
|
||||
gpuProfiler.stop();
|
||||
}
|
||||
|
||||
public AssetManager getAssetManager()
|
||||
{
|
||||
return assetManager;
|
||||
}
|
||||
|
||||
public ResourceReloader getReloader()
|
||||
{
|
||||
return reloader;
|
||||
}
|
||||
|
||||
public Window getMainWindow()
|
||||
{
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
public Camera getCamera()
|
||||
{
|
||||
return camera;
|
||||
}
|
||||
|
||||
public EventBus getEventBus()
|
||||
{
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
public ProjectionBuffer getProjectionBuffer()
|
||||
{
|
||||
return projectionBuffer;
|
||||
}
|
||||
|
||||
public FPSTimer getTimer()
|
||||
{
|
||||
return timer;
|
||||
}
|
||||
|
||||
public FontManager getFonts()
|
||||
{
|
||||
return fonts;
|
||||
}
|
||||
|
||||
public GuiManager getUiManager()
|
||||
{
|
||||
return uiManager;
|
||||
}
|
||||
|
||||
public IProfiler getClientProfiler()
|
||||
{
|
||||
return clientProfiler;
|
||||
}
|
||||
|
||||
public IProfiler getGPUProfiler()
|
||||
{
|
||||
return gpuProfiler;
|
||||
}
|
||||
|
||||
public long getFrame()
|
||||
{
|
||||
return executor.frame;
|
||||
}
|
||||
public AssetManager getAssetManager() { return assetManager; }
|
||||
public ResourceReloader getReloader() { return reloader; }
|
||||
public Window getMainWindow() { return mainWindow; }
|
||||
public Camera getCamera() { return camera; }
|
||||
public EventBus getEventBus() { return eventBus; }
|
||||
public ProjectionBuffer getProjectionBuffer() { return projectionBuffer; }
|
||||
public FPSTimer getTimer() { return timer; }
|
||||
public FontManager getFonts() { return fonts; }
|
||||
public GuiManager getUiManager() { return uiManager; }
|
||||
public IProfiler getClientProfiler() { return clientProfiler; }
|
||||
public IProfiler getGPUProfiler() { return gpuProfiler; }
|
||||
public long getFrame() { return executor.frame; }
|
||||
}
|
||||
@@ -10,12 +10,12 @@ import speiger.src.coreengine.rendering.input.window.Window;
|
||||
import speiger.src.coreengine.rendering.utils.AllocationTracker;
|
||||
import speiger.src.coreengine.rendering.utils.GLStamper;
|
||||
import speiger.src.coreengine.rendering.utils.GLStamper.GLStamp;
|
||||
import speiger.src.coreengine.rendering.utils.GLUtils;
|
||||
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
||||
import speiger.src.coreengine.utils.counters.averager.TimeAverager;
|
||||
import speiger.src.coreengine.utils.counters.timers.FPSTimer;
|
||||
import speiger.src.coreengine.utils.counters.timers.FrameSyncer;
|
||||
import speiger.src.coreengine.utils.counters.timers.TimerTarget;
|
||||
import speiger.src.coreengine.utils.helpers.FileUtils;
|
||||
import speiger.src.coreengine.utils.helpers.IOUtils;
|
||||
import speiger.src.coreengine.utils.helpers.TextUtil;
|
||||
import speiger.src.coreengine.utils.io.GameLog;
|
||||
import speiger.src.coreengine.utils.io.GameLog.LogLevel;
|
||||
@@ -83,7 +83,7 @@ public class ApplicationExecutor
|
||||
boolean end = timer.update();
|
||||
stamp.stop();
|
||||
AllocationTracker.INSTANCE.update();
|
||||
GLUtils.onFrameEnded();
|
||||
GLStateTracker.onFrameEnded();
|
||||
gpu().next("Window").start("V-Sync");
|
||||
window.finishFrame();
|
||||
if(window.isCPULimited()) sync.sync(fps.getTargetTicks());
|
||||
@@ -126,8 +126,8 @@ public class ApplicationExecutor
|
||||
builder.append(fps.getTicks()).append(":").append(ups.getTicks());
|
||||
owner.addExtraTickRates(T -> builder.append(":").append(T));
|
||||
builder.append(",").append(getMemoryUsage());
|
||||
builder.append(",").append("CPU-A: "+FileUtils.convertBytes(AllocationTracker.INSTANCE.getCPUAllocatedBytes()));
|
||||
builder.append(",").append("GPU-A: "+FileUtils.convertBytes(AllocationTracker.INSTANCE.getGPUAllocatedBytes()));
|
||||
builder.append(",").append("CPU-A: "+IOUtils.convertBytes(AllocationTracker.INSTANCE.getCPUAllocatedBytes()));
|
||||
builder.append(",").append("GPU-A: "+IOUtils.convertBytes(AllocationTracker.INSTANCE.getGPUAllocatedBytes()));
|
||||
builder.append(",").append(TextUtil.convertTime(timer.getUsage(), "Client:", FORMATTER));
|
||||
builder.append(",").append(TextUtil.convertTime(gpuTime.getAverage(), "GPU:", FORMATTER));
|
||||
owner.addExtraTimers((N, T) -> builder.append(",").append(TextUtil.convertTime(T, N, FORMATTER)));
|
||||
|
||||
@@ -2,7 +2,7 @@ package speiger.src.coreengine.application;
|
||||
|
||||
import speiger.src.coreengine.rendering.gui.GuiManager;
|
||||
import speiger.src.coreengine.rendering.gui.base.DebugOverlay;
|
||||
import speiger.src.coreengine.rendering.models.UniformBuffer;
|
||||
import speiger.src.coreengine.rendering.models.buffers.UniformBuffer;
|
||||
import speiger.src.coreengine.utils.collections.FlagHolder;
|
||||
import speiger.src.coreengine.utils.profiler.EmptyProfiler;
|
||||
import speiger.src.coreengine.utils.profiler.IProfiler;
|
||||
|
||||
@@ -2,103 +2,71 @@ package speiger.src.coreengine.assets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
|
||||
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
|
||||
import speiger.src.collections.objects.maps.impl.concurrent.Object2ObjectConcurrentOpenHashMap;
|
||||
|
||||
public final class AssetLocation implements Comparable<AssetLocation>
|
||||
{
|
||||
static final Map<String, AssetLocation> LOCATION = Object2ObjectMaps.synchronize(new Object2ObjectOpenHashMap<>());
|
||||
static final Function<String, AssetLocation> BUILDER = AssetLocation::compute;
|
||||
public final class AssetLocation implements Comparable<AssetLocation> {
|
||||
static final Map<String, AssetLocation> LOCATION = new Object2ObjectConcurrentOpenHashMap<>();
|
||||
final String domain;
|
||||
final String location;
|
||||
|
||||
private AssetLocation() {throw new UnsupportedOperationException("use AssetLocation.of instead");}
|
||||
private AssetLocation() {
|
||||
throw new UnsupportedOperationException("use AssetLocation.of instead");
|
||||
}
|
||||
|
||||
private AssetLocation(String domain, String location)
|
||||
{
|
||||
private AssetLocation(String domain, String location) {
|
||||
this.domain = domain;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getDomain()
|
||||
{
|
||||
return domain;
|
||||
public String domain() { return domain; }
|
||||
public String location() { return location; }
|
||||
public String actualLocation() { return "assets/"+domain+"/"+location; }
|
||||
public boolean endsWith(String suffix) { return location.endsWith(suffix); }
|
||||
|
||||
public AssetLocation subAsset(String subPath) {
|
||||
return of(domain+":"+location+"/"+subPath);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getActualLocation()
|
||||
{
|
||||
return "assets/"+domain+"/"+location;
|
||||
}
|
||||
|
||||
public AssetLocation subAsset(String subPath)
|
||||
{
|
||||
return of(domain+":"+location + "/" + subPath);
|
||||
}
|
||||
|
||||
public AssetLocation alternate(String alterversion)
|
||||
{
|
||||
public AssetLocation alternate(String alterversion) {
|
||||
return of(domain+":"+location+"."+alterversion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return domain+":"+location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hash(domain, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(obj instanceof AssetLocation)
|
||||
{
|
||||
AssetLocation location = (AssetLocation)obj;
|
||||
return location.domain.equals(domain) && location.location.equals(this.location);
|
||||
}
|
||||
return false;
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this || (obj instanceof AssetLocation location && matches(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AssetLocation o)
|
||||
{
|
||||
public int compareTo(AssetLocation o) {
|
||||
int result = domain.compareToIgnoreCase(o.domain);
|
||||
return result != 0 ? result : location.compareToIgnoreCase(location);
|
||||
}
|
||||
|
||||
public boolean matches(AssetLocation location)
|
||||
{
|
||||
public boolean matches(AssetLocation location) {
|
||||
return location.domain.equals(domain) && location.location.equals(this.location);
|
||||
}
|
||||
|
||||
public static final AssetLocation of(String domain, String location)
|
||||
{
|
||||
public static final AssetLocation of(String domain, String location) {
|
||||
return of((domain == null || domain.isEmpty() ? "base" : domain)+":"+location);
|
||||
}
|
||||
|
||||
public static final AssetLocation of(String location)
|
||||
{
|
||||
return LOCATION.computeIfAbsent(location.indexOf(":") == -1 ? "base:"+location : location, BUILDER);
|
||||
public static final AssetLocation of(String location) {
|
||||
return LOCATION.computeIfAbsent(location.indexOf(":") == -1 ? "base:"+location : location, AssetLocation::compute);
|
||||
}
|
||||
|
||||
private static final AssetLocation compute(String s)
|
||||
{
|
||||
private static final AssetLocation compute(String s) {
|
||||
int index = s.indexOf(":");
|
||||
return new AssetLocation(s.substring(0, index), s.substring(index+1, s.length()));
|
||||
return new AssetLocation(s.substring(0, index), s.substring(index + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,211 +1,95 @@
|
||||
package speiger.src.coreengine.assets;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
|
||||
import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap.Entry;
|
||||
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
|
||||
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
|
||||
import speiger.src.coreengine.assets.impl.FolderAssetPackage;
|
||||
import speiger.src.coreengine.assets.impl.ZipAssetPackage;
|
||||
import speiger.src.coreengine.assets.reloader.IReloadableResource;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
import speiger.src.collections.objects.utils.ObjectLists;
|
||||
import speiger.src.coreengine.assets.base.IAsset;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.base.IAssetProvider.ICloseableAssetProvider;
|
||||
import speiger.src.coreengine.assets.base.IManagedAsset;
|
||||
import speiger.src.coreengine.assets.base.IReloadableAsset;
|
||||
import speiger.src.coreengine.assets.base.MultiAsset;
|
||||
import speiger.src.coreengine.assets.base.PackReloadingTask;
|
||||
import speiger.src.coreengine.assets.impl.LayeredAssetProvider;
|
||||
|
||||
public class AssetManager implements IReloadableResource
|
||||
public class AssetManager implements ICloseableAssetProvider
|
||||
{
|
||||
Object2ObjectMap<String, DomainAssets> domains = new Object2ObjectLinkedOpenHashMap<>();
|
||||
Object2ObjectMap<Class<?>, IAssetParser<?>> parsers = new Object2ObjectLinkedOpenHashMap<>();
|
||||
Path path;
|
||||
ObjectList<IReloadableAsset> listeners = new ObjectArrayList<>();
|
||||
LayeredAssetProvider provider;
|
||||
|
||||
public AssetManager(File file)
|
||||
{
|
||||
this(file.toPath());
|
||||
public AssetManager(List<IAssetPackage> packages) {
|
||||
provider = new LayeredAssetProvider(packages);
|
||||
}
|
||||
|
||||
public AssetManager(Path path)
|
||||
{
|
||||
this.path = path;
|
||||
public void addListener(IReloadableAsset listener) {
|
||||
listeners.add(listener);
|
||||
if(listener instanceof IManagedAsset managed) {
|
||||
managed.setProvider(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Path getMainAsset()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public <T> void registerAssetParser(Class<T> clz, IAssetParser<T> parser)
|
||||
{
|
||||
if(clz == null || parser == null) return;
|
||||
public ObjectList<IReloadableAsset> listeners() {
|
||||
return ObjectLists.unmodifiable(listeners);
|
||||
}
|
||||
|
||||
public AssetManager reload(Executor offthread, Executor syncer, List<IAssetPackage> packages) {
|
||||
return reloadAssets(packages).reloadSelective(offthread, syncer, listeners);
|
||||
}
|
||||
|
||||
public AssetManager reload(Executor offthread, Executor syncer) {
|
||||
return reloadSelective(offthread, syncer, listeners);
|
||||
}
|
||||
|
||||
public AssetManager reloadSelective(Executor offthread, Executor syncer, List<IReloadableAsset> listeners) {
|
||||
PackReloadingTask.reload(provider, listeners, offthread, syncer).join();
|
||||
return this;
|
||||
}
|
||||
|
||||
public AssetManager reloadAssets(List<IAssetPackage> packages) {
|
||||
provider.close();
|
||||
provider = new LayeredAssetProvider(packages);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void reload()
|
||||
{
|
||||
domains.clear();
|
||||
public void close() {
|
||||
provider.close();
|
||||
listeners.forEach(IReloadableAsset::destroy);
|
||||
}
|
||||
|
||||
|
||||
public void loadAssetPackage(File file)
|
||||
{
|
||||
@Override
|
||||
public FileTime getModifiedTime(AssetLocation location) {
|
||||
return provider.getModifiedTime(location);
|
||||
}
|
||||
|
||||
|
||||
public void loadAssetPackage(Path path)
|
||||
{
|
||||
if(Files.notExists(path)) return;
|
||||
if(Files.isDirectory(path)) loadAssets(new FolderAssetPackage(path));
|
||||
@Override
|
||||
public FileTime getLatestTime(AssetLocation... locations) {
|
||||
return provider.getLatestTime(locations);
|
||||
}
|
||||
|
||||
|
||||
public void loadAssets(IAssetPackage packages)
|
||||
{
|
||||
for(String s : packages.getDomains())
|
||||
{
|
||||
DomainAssets entry = domains.get(s);
|
||||
if(entry == null)
|
||||
{
|
||||
entry = new DomainAssets();
|
||||
domains.put(s, entry);
|
||||
}
|
||||
entry.addAssets(packages);
|
||||
}
|
||||
@Override
|
||||
public IAsset getAsset(AssetLocation location) {
|
||||
return provider.getAsset(location);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getDomains()
|
||||
{
|
||||
|
||||
@Override
|
||||
public MultiAsset getAllAssets(AssetLocation location) {
|
||||
return provider.getAllAssets(location);
|
||||
}
|
||||
}
|
||||
|
||||
public IAsset getAsset(AssetLocation location) throws IOException
|
||||
{
|
||||
DomainAssets asset = domains.get(location.getDomain());
|
||||
if(asset == null)
|
||||
{
|
||||
throw new FileNotFoundException("Domain & File["+location.toString()+"] not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AssetLocation, IAsset> listAssets(String folder, Predicate<AssetLocation> filter) {
|
||||
return provider.listAssets(folder, filter);
|
||||
}
|
||||
}
|
||||
|
||||
public MultiAsset getAssets(AssetLocation...locations)
|
||||
{
|
||||
IAsset[] asset = new IAsset[locations.length];
|
||||
for(int i = 0,m=locations.length;i<m;i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
asset[i] = getAsset(locations[i]);
|
||||
}
|
||||
catch(Exception e) {e.printStackTrace();}
|
||||
}
|
||||
return new MultiAsset(asset);
|
||||
}
|
||||
|
||||
public MultiAsset getMultiAsset(AssetLocation location, AssetLocation...subLocations) throws IOException
|
||||
{
|
||||
DomainAssets asset = domains.get(location.getDomain());
|
||||
if(asset == null)
|
||||
{
|
||||
throw new FileNotFoundException("Domain & File["+location.toString()+"] not found");
|
||||
}
|
||||
return asset.getMultiAsset(location, subLocations);
|
||||
}
|
||||
|
||||
public MultiAsset getAllAsset(AssetLocation location) throws IOException
|
||||
{
|
||||
DomainAssets asset = domains.get(location.getDomain());
|
||||
if(asset == null)
|
||||
{
|
||||
throw new FileNotFoundException("Domain & File["+location.toString()+"] not found");
|
||||
}
|
||||
return asset.getAllAssets(location);
|
||||
}
|
||||
|
||||
public Collection<AssetLocation> gatherAssets(String location, int maxDepth, Predicate<String> filter)
|
||||
{
|
||||
Set<AssetLocation> result = new ObjectLinkedOpenHashSet<>();
|
||||
for(Entry<String, DomainAssets> asset : Object2ObjectMaps.fastIterable(domains))
|
||||
{
|
||||
asset.getValue().gatherAssets(AssetLocation.of(asset.getKey(), location), maxDepth, filter, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean isZipFile(Path file)
|
||||
{
|
||||
try(ZipFile zip = new ZipFile(file.toFile())) { return true; }
|
||||
catch(Exception e) { return false; }
|
||||
}
|
||||
|
||||
static class DomainAssets
|
||||
{
|
||||
List<IAssetPackage> packages = new ObjectArrayList<IAssetPackage>();
|
||||
|
||||
public void addAssets(IAssetPackage assets)
|
||||
{
|
||||
packages.add(assets);
|
||||
}
|
||||
|
||||
public IAsset getAsset(AssetLocation location) throws IOException
|
||||
{
|
||||
for(int i = packages.size() - 1;i>=0;i--)
|
||||
{
|
||||
IAsset asset = packages.get(i).getAsset(location);
|
||||
if(asset != null) return asset;
|
||||
}
|
||||
throw new FileNotFoundException("File["+location.toString()+"] not found");
|
||||
}
|
||||
|
||||
public MultiAsset getMultiAsset(AssetLocation location, AssetLocation... subLocations)
|
||||
{
|
||||
for(int i = packages.size() - 1;i>=0;i--)
|
||||
{
|
||||
IAssetPackage entry = packages.get(i);
|
||||
IAsset asset = entry.getAsset(location);
|
||||
if(asset != null)
|
||||
{
|
||||
IAsset[] result = new IAsset[1 + subLocations.length];
|
||||
result[0] = asset;
|
||||
for(int x = 0;x<subLocations.length;x++)
|
||||
{
|
||||
result[x+1] = entry.getAsset(subLocations[x]);
|
||||
}
|
||||
return new MultiAsset(result);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MultiAsset getAllAssets(AssetLocation location) throws IOException
|
||||
{
|
||||
List<IAsset> assets = new ObjectArrayList<IAsset>();
|
||||
for(IAssetPackage entry : packages)
|
||||
{
|
||||
IAsset asset = entry.getAsset(location);
|
||||
if(asset != null) assets.add(asset);
|
||||
}
|
||||
if(assets.isEmpty())
|
||||
{
|
||||
throw new FileNotFoundException("File["+location.toString()+"] not found");
|
||||
}
|
||||
return new MultiAsset(assets.toArray(new IAsset[assets.size()]));
|
||||
}
|
||||
|
||||
public void gatherAssets(AssetLocation folder, int maxDepth, Predicate<String> filter, Collection<AssetLocation> result)
|
||||
{
|
||||
for(IAssetPackage entry : packages)
|
||||
{
|
||||
entry.getAllAssets(folder, filter, maxDepth, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AssetLocation, MultiAsset> listAllAssets(String folder, Predicate<AssetLocation> filter) {
|
||||
return provider.listAllAssets(folder, filter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package speiger.src.coreengine.assets;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public interface IAsset extends Closeable
|
||||
{
|
||||
public AssetLocation getLocation();
|
||||
|
||||
public IAsset subAsset(String alternative);
|
||||
|
||||
public InputStream getStream() throws IOException;
|
||||
|
||||
public ByteBuffer getBytes() throws IOException;
|
||||
|
||||
public BufferedReader getStringReader() throws IOException;
|
||||
|
||||
public JsonObject getJsonObject() throws IOException;
|
||||
|
||||
public BufferedImage getTexture() throws Exception;
|
||||
|
||||
public <T> T getCustom(Class<T> clz) throws IOException;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package speiger.src.coreengine.assets;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface IAssetPackage
|
||||
{
|
||||
public void setParsers(Function<Class<?>, IAssetParser<?>> parsers);
|
||||
public List<String> getDomains();
|
||||
public IAsset getAsset(AssetLocation location);
|
||||
public void getAllAssets(AssetLocation folder, Predicate<String> fileNames, int maxDepth, Collection<AssetLocation> result);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package speiger.src.coreengine.assets;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MultiAsset implements Closeable
|
||||
{
|
||||
IAsset[] assets;
|
||||
|
||||
public MultiAsset(IAsset[] assets)
|
||||
{
|
||||
this.assets = assets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
if(assets != null)
|
||||
{
|
||||
for(int i = 0,m=assets.length;i<m;i++)
|
||||
{
|
||||
if(assets[i] != null) assets[i].close();
|
||||
}
|
||||
assets = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return assets.length;
|
||||
}
|
||||
|
||||
public IAsset getAsset(int index)
|
||||
{
|
||||
return assets[index];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
|
||||
public interface IAsset extends Closeable
|
||||
{
|
||||
public IAssetPackage owner();
|
||||
public AssetLocation location();
|
||||
@Override
|
||||
public void close();
|
||||
public IAsset subAsset(String alternative);
|
||||
public InputStream stream() throws IOException;
|
||||
public ByteBuffer bytes() throws IOException;
|
||||
public BufferedReader reader() throws IOException;
|
||||
public List<String> lines() throws IOException;
|
||||
public JsonObject json() throws IOException;
|
||||
public BufferedImage texture() throws Exception;
|
||||
public <T> T custom(IAssetParser<T> parser) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.impl.FolderAssetPackage;
|
||||
import speiger.src.coreengine.assets.impl.ZipAssetPackage;
|
||||
import speiger.src.coreengine.utils.helpers.IOUtils;
|
||||
|
||||
public interface IAssetPackage extends Closeable
|
||||
{
|
||||
@Override
|
||||
public void close();
|
||||
public void getModifiedTime(String domain, BiConsumer<AssetLocation, FileTime> accept);
|
||||
public List<String> getDomains();
|
||||
public IAsset getAsset(AssetLocation location);
|
||||
public void gatherAssets(AssetLocation folder, BiConsumer<AssetLocation, IAsset> accept);
|
||||
|
||||
public static IAssetPackage of(Path path) {
|
||||
if(Files.exists(path)) {
|
||||
if(Files.isDirectory(path)) return new FolderAssetPackage(path);
|
||||
if(IOUtils.isZip(path)) return new ZipAssetPackage(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package speiger.src.coreengine.assets;
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -0,0 +1,22 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
|
||||
public interface IAssetProvider {
|
||||
|
||||
public IAsset getAsset(AssetLocation location);
|
||||
public MultiAsset getAllAssets(AssetLocation location);
|
||||
public FileTime getModifiedTime(AssetLocation location);
|
||||
public FileTime getLatestTime(AssetLocation...locations);
|
||||
public Map<AssetLocation, IAsset> listAssets(String folder, Predicate<AssetLocation> filter);
|
||||
public Map<AssetLocation, MultiAsset> listAllAssets(String folder, Predicate<AssetLocation> filter);
|
||||
|
||||
public static interface ICloseableAssetProvider extends IAssetProvider, AutoCloseable {
|
||||
@Override
|
||||
public void close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
public interface IManagedAsset {
|
||||
public void setProvider(IAssetProvider provider);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public interface IReloadableAsset {
|
||||
public String getName();
|
||||
public CompletableFuture<Void> reloadAssets(IAssetProvider provider, IReloadSyncer syncer, Executor offthreadExectutor, Executor syncExecutor);
|
||||
public void destroy();
|
||||
|
||||
public static interface IReloadSyncer {
|
||||
public <T> CompletableFuture<T> sync(T value);
|
||||
}
|
||||
|
||||
public static interface ISimpleRealodableAsset extends IReloadableAsset {
|
||||
@Override
|
||||
default CompletableFuture<Void> reloadAssets(IAssetProvider provider, IReloadSyncer syncer, Executor offthreadExectutor, Executor syncExecutor) {
|
||||
return syncer.sync(null).thenRunAsync(() -> onAssetsReloaded(provider), syncExecutor);
|
||||
}
|
||||
|
||||
public void onAssetsReloaded(IAssetProvider provider);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
|
||||
public class MultiAsset implements Closeable, ObjectIterable<IAsset> {
|
||||
ObjectList<IAsset> assets;
|
||||
|
||||
public MultiAsset(IAsset...assets) {
|
||||
this(ObjectArrayList.wrap(assets));
|
||||
}
|
||||
|
||||
public MultiAsset(ObjectList<IAsset> assets) {
|
||||
this.assets = assets.unmodifiable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if(assets != null) {
|
||||
assets.forEach(IAsset::close);
|
||||
assets = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return assets.size();
|
||||
}
|
||||
|
||||
public IAsset get(int index) {
|
||||
return assets.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super IAsset> action) {
|
||||
assets.forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, ObjectObjectConsumer<E, IAsset> action) {
|
||||
assets.forEach(input, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachIndexed(IntObjectConsumer<IAsset> action) {
|
||||
assets.forEachIndexed(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectIterator<IAsset> iterator() {
|
||||
return assets.iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.sets.ObjectOpenHashSet;
|
||||
import speiger.src.coreengine.assets.base.IReloadableAsset.IReloadSyncer;
|
||||
|
||||
public class PackReloadingTask {
|
||||
public static CompletableFuture<?> reload(IAssetProvider provider, List<IReloadableAsset> assets, Executor offthreadTask, Executor mainThreadTask) {
|
||||
CompletableFuture<Object> syncStep = new CompletableFuture<>();
|
||||
List<CompletableFuture<?>> results = new ObjectArrayList<>();
|
||||
CompletableFuture<?> currentStep = CompletableFuture.completedFuture("");
|
||||
Set<IReloadableAsset> toComplete = new ObjectOpenHashSet<>(assets);
|
||||
for(IReloadableAsset asset : assets) {
|
||||
CompletableFuture<?> next = asset.reloadAssets(provider, new Syncer(mainThreadTask, currentStep, syncStep, asset, toComplete), offthreadTask, mainThreadTask);
|
||||
results.add(next);
|
||||
currentStep = next;
|
||||
}
|
||||
return CompletableFuture.allOf(results.toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
private static class Syncer implements IReloadSyncer {
|
||||
Executor mainExecutor;
|
||||
CompletableFuture<?> currentStep;
|
||||
CompletableFuture<Object> syncStep;
|
||||
IReloadableAsset currentAsset;
|
||||
Set<IReloadableAsset> toComplete;
|
||||
|
||||
public Syncer(Executor mainExecutor, CompletableFuture<?> currentStep, CompletableFuture<Object> syncStep, IReloadableAsset currentAsset, Set<IReloadableAsset> toComplete) {
|
||||
this.mainExecutor = mainExecutor;
|
||||
this.currentStep = currentStep;
|
||||
this.syncStep = syncStep;
|
||||
this.currentAsset = currentAsset;
|
||||
this.toComplete = toComplete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CompletableFuture<T> sync(T value) {
|
||||
mainExecutor.execute(() -> {
|
||||
if(toComplete.remove(currentAsset) && toComplete.isEmpty()) {
|
||||
syncStep.complete(new Object());
|
||||
}
|
||||
});
|
||||
return syncStep.thenCombine(currentStep, (k, v) -> value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package speiger.src.coreengine.assets.base;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public abstract class SteppedReloadableAsset<T> implements IReloadableAsset {
|
||||
@Override
|
||||
public final CompletableFuture<Void> reloadAssets(IAssetProvider provider, IReloadSyncer syncer, Executor offthreadExectutor, Executor syncExecutor) {
|
||||
return CompletableFuture.supplyAsync(() -> prepare(provider), offthreadExectutor).thenCompose(syncer::sync).thenAcceptAsync(T -> apply(T, provider), syncExecutor);
|
||||
}
|
||||
|
||||
protected abstract T prepare(IAssetProvider provider);
|
||||
protected abstract void apply(T value, IAssetProvider provider);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.base.IAsset;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
|
||||
public abstract class BaseAsset implements IAsset {
|
||||
protected AssetLocation location;
|
||||
protected IAssetPackage owner;
|
||||
protected List<Closeable> closeable = new ObjectArrayList<>();
|
||||
|
||||
public BaseAsset(AssetLocation location, IAssetPackage owner) {
|
||||
this.location = location;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
for(Closeable close : closeable) {
|
||||
try { close.close(); }
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
closeable.clear();
|
||||
}
|
||||
|
||||
protected <T extends Closeable> T markClosed(T value) {
|
||||
closeable.add(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetLocation location() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAssetPackage owner() {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.IAsset;
|
||||
import speiger.src.coreengine.assets.IAssetParser;
|
||||
import speiger.src.coreengine.utils.helpers.JsonUtil;
|
||||
|
||||
public class FolderAsset implements IAsset
|
||||
{
|
||||
Function<Class<?>, IAssetParser<?>> parsers;
|
||||
AssetLocation location;
|
||||
Path path;
|
||||
List<Closeable> closeable;
|
||||
|
||||
public FolderAsset(AssetLocation location, Path path, Function<Class<?>, IAssetParser<?>> parsers)
|
||||
{
|
||||
this(location, path, parsers, new ObjectArrayList<>());
|
||||
}
|
||||
|
||||
public FolderAsset(AssetLocation location, Path path, Function<Class<?>, IAssetParser<?>> parsers, List<Closeable> closeable)
|
||||
{
|
||||
this.location = location;
|
||||
this.path = path;
|
||||
this.parsers = parsers;
|
||||
this.closeable = closeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
for(Closeable close : closeable)
|
||||
{
|
||||
try
|
||||
{
|
||||
close.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
closeable.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset subAsset(String alternative)
|
||||
{
|
||||
Path newPath = path.resolveSibling(path.getFileName().toString()+"."+alternative);
|
||||
return Files.exists(newPath) ? new FolderAsset(location.alternate(alternative), newPath, parsers, closeable) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetLocation getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getStream() throws IOException
|
||||
{
|
||||
return markClosed(Files.newInputStream(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer getBytes() throws IOException
|
||||
{
|
||||
return ByteBuffer.wrap(Files.readAllBytes(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getTexture() throws Exception
|
||||
{
|
||||
return ImageIO.read(getStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedReader getStringReader() throws IOException
|
||||
{
|
||||
return markClosed(Files.newBufferedReader(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getJsonObject() throws IOException
|
||||
{
|
||||
return JsonUtil.loadFile(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCustom(Class<T> clz) throws IOException
|
||||
{
|
||||
return clz.cast(parsers.apply(clz).parseAsset(path, closeable::add));
|
||||
}
|
||||
|
||||
protected <T extends Closeable> T markClosed(T value)
|
||||
{
|
||||
closeable.add(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +1,71 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.IAsset;
|
||||
import speiger.src.coreengine.assets.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.IAssetParser;
|
||||
import speiger.src.coreengine.assets.base.IAsset;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.utils.collections.iterators.IterableWrapper;
|
||||
|
||||
public class FolderAssetPackage implements IAssetPackage
|
||||
{
|
||||
public class FolderAssetPackage implements IAssetPackage {
|
||||
Path baseFolder;
|
||||
Function<Class<?>, IAssetParser<?>> parsers;
|
||||
|
||||
public FolderAssetPackage(File baseFolder)
|
||||
{
|
||||
this(baseFolder.toPath());
|
||||
}
|
||||
|
||||
public FolderAssetPackage(Path baseFolder)
|
||||
{
|
||||
public FolderAssetPackage(Path baseFolder) {
|
||||
this.baseFolder = baseFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParsers(Function<Class<?>, IAssetParser<?>> parsers)
|
||||
{
|
||||
this.parsers = parsers;
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public void getModifiedTime(String domain, BiConsumer<AssetLocation, FileTime> accept) {
|
||||
try {
|
||||
Path start = baseFolder.resolve("assets");
|
||||
for(Path path : IterableWrapper.wrap(Files.walk(start.resolve(domain)).filter(Files::isRegularFile).iterator())) {
|
||||
accept.accept(AssetLocation.of(domain, start.relativize(path).toString().replace("\\", "/")), Files.getLastModifiedTime(path));
|
||||
}
|
||||
}
|
||||
catch(IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDomains()
|
||||
{
|
||||
public List<String> getDomains() {
|
||||
List<String> domains = new ObjectArrayList<>();
|
||||
try(DirectoryStream<Path> dirs = Files.newDirectoryStream(baseFolder.resolve("assets")))
|
||||
{
|
||||
for(Path path : dirs)
|
||||
{
|
||||
try(DirectoryStream<Path> dirs = Files.newDirectoryStream(baseFolder.resolve("assets"))) {
|
||||
for(Path path : dirs) {
|
||||
domains.add(path.getFileName().toString());
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(IOException e) { e.printStackTrace(); }
|
||||
return domains;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset getAsset(AssetLocation location)
|
||||
{
|
||||
Path path = baseFolder.resolve(location.getActualLocation());
|
||||
return Files.exists(path) ? new FolderAsset(location, path, parsers) : null;
|
||||
public IAsset getAsset(AssetLocation location) {
|
||||
Path path = baseFolder.resolve(location.actualLocation());
|
||||
return Files.exists(path) ? new SimpleAsset(location, this, path) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllAssets(AssetLocation folder, Predicate<String> fileNames, int maxDepth, Collection<AssetLocation> result)
|
||||
{
|
||||
Path start = baseFolder.resolve(folder.getActualLocation());
|
||||
public void gatherAssets(AssetLocation folder, BiConsumer<AssetLocation, IAsset> result) {
|
||||
Path start = baseFolder.resolve(folder.actualLocation());
|
||||
if(Files.notExists(start)) return;
|
||||
try(Stream<Path> stream = Files.walk(start, maxDepth).filter(Files::isRegularFile).filter(T -> fileNames.test(T.getFileName().toString())))
|
||||
{
|
||||
for(Path path : IterableWrapper.wrap(stream.iterator()))
|
||||
{
|
||||
result.add(folder.subAsset(start.relativize(path).toString().replace("\\", "/")));
|
||||
try(Stream<Path> stream = Files.walk(start).filter(Files::isRegularFile)) {
|
||||
for(Path path : IterableWrapper.wrap(stream.iterator())) {
|
||||
AssetLocation location = folder.subAsset(start.relativize(path).toString().replace("\\", "/"));
|
||||
result.accept(location, new SimpleAsset(location, this, path));
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
|
||||
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.base.IAsset;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.base.IAssetProvider;
|
||||
import speiger.src.coreengine.assets.base.IAssetProvider.ICloseableAssetProvider;
|
||||
import speiger.src.coreengine.assets.base.MultiAsset;
|
||||
import speiger.src.coreengine.math.ArrayUtil;
|
||||
|
||||
public class LayeredAssetProvider implements ICloseableAssetProvider {
|
||||
public static final FileTime DEFAULT_TIME = FileTime.fromMillis(0L);
|
||||
Map<String, DomainAssetProvider> domains = Object2ObjectMap.builder().linkedMap();
|
||||
List<IAssetPackage> packages;
|
||||
|
||||
public LayeredAssetProvider(List<IAssetPackage> packages) {
|
||||
this.packages = packages;
|
||||
for(IAssetPackage pack : packages) {
|
||||
for(String domain : pack.getDomains()) {
|
||||
domains.computeIfAbsent(domain, DomainAssetProvider::new).addPackage(pack);
|
||||
}
|
||||
}
|
||||
domains.values().forEach(DomainAssetProvider::buildCaches);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
packages.forEach(IAssetPackage::close);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTime getModifiedTime(AssetLocation location) {
|
||||
DomainAssetProvider provider = domains.get(location.domain());
|
||||
return provider == null ? DEFAULT_TIME : provider.getModifiedTime(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTime getLatestTime(AssetLocation... locations) {
|
||||
FileTime time = DEFAULT_TIME;
|
||||
for(AssetLocation location : locations) {
|
||||
time = ArrayUtil.higher(time, getModifiedTime(location));
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset getAsset(AssetLocation location) {
|
||||
DomainAssetProvider provider = domains.get(location.domain());
|
||||
return provider == null ? null : provider.getAsset(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiAsset getAllAssets(AssetLocation location) {
|
||||
DomainAssetProvider provider = domains.get(location.domain());
|
||||
return provider == null ? null : provider.getAllAssets(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AssetLocation, IAsset> listAssets(String folder, Predicate<AssetLocation> filter) {
|
||||
Map<AssetLocation, IAsset> result = Object2ObjectMap.builder().linkedMap();
|
||||
for(DomainAssetProvider provider : domains.values()) {
|
||||
result.putAll(provider.listAssets(folder, filter));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AssetLocation, MultiAsset> listAllAssets(String folder, Predicate<AssetLocation> filter) {
|
||||
Map<AssetLocation, MultiAsset> result = Object2ObjectMap.builder().linkedMap();
|
||||
for(DomainAssetProvider provider : domains.values()) {
|
||||
result.putAll(provider.listAllAssets(folder, filter));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class DomainAssetProvider implements IAssetProvider {
|
||||
final String domain;
|
||||
ObjectList<IAssetPackage> packages = new ObjectArrayList<>();
|
||||
Map<AssetLocation, FileTime> lastChanges = Object2ObjectMap.builder().map();
|
||||
|
||||
public DomainAssetProvider(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public void addPackage(IAssetPackage pack) {
|
||||
packages.add(pack);
|
||||
}
|
||||
|
||||
private void buildCaches() {
|
||||
for(int i = packages.size()-1;i>=0;i--) {
|
||||
packages.get(i).getModifiedTime(domain, lastChanges::putIfAbsent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTime getModifiedTime(AssetLocation location) {
|
||||
return lastChanges.getOrDefault(location, DEFAULT_TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTime getLatestTime(AssetLocation... locations) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset getAsset(AssetLocation location) {
|
||||
for(int i = packages.size()-1;i>=0;i--) {
|
||||
IAsset asset = packages.get(i).getAsset(location);
|
||||
if(asset != null) return asset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiAsset getAllAssets(AssetLocation location) {
|
||||
ObjectList<IAsset> result = new ObjectArrayList<>();
|
||||
for(int i = packages.size()-1;i>=0;i--) {
|
||||
IAsset asset = packages.get(i).getAsset(location);
|
||||
if(asset != null) result.add(asset);
|
||||
}
|
||||
return new MultiAsset(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AssetLocation, IAsset> listAssets(String folder, Predicate<AssetLocation> filter) {
|
||||
AssetLocation base = AssetLocation.of(domain, folder);
|
||||
Map<AssetLocation, IAsset> result = Object2ObjectMap.builder().linkedMap();
|
||||
for(int i = packages.size()-1;i>=0;i--) {
|
||||
packages.get(i).gatherAssets(base, (K, V) -> {
|
||||
if(filter.test(K)) result.putIfAbsent(K, V);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AssetLocation, MultiAsset> listAllAssets(String folder, Predicate<AssetLocation> filter) {
|
||||
AssetLocation base = AssetLocation.of(domain, folder);
|
||||
Object2ObjectMap<AssetLocation, ObjectList<IAsset>> assets = Object2ObjectMap.builder().linkedMap();
|
||||
for(int i = packages.size()-1;i>=0;i--) {
|
||||
packages.get(i).gatherAssets(base, (K, V) -> {
|
||||
if(filter.test(K)) assets.supplyIfAbsent(K, ObjectArrayList::new).add(V);
|
||||
});
|
||||
}
|
||||
Map<AssetLocation, MultiAsset> result = Object2ObjectMap.builder().linkedMap();
|
||||
for(Object2ObjectMap.Entry<AssetLocation, ObjectList<IAsset>> entry : Object2ObjectMaps.fastIterable(assets)) {
|
||||
result.put(entry.getKey(), new MultiAsset(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.base.IAsset;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.base.IAssetParser;
|
||||
import speiger.src.coreengine.utils.helpers.JsonUtil;
|
||||
|
||||
public class SimpleAsset extends BaseAsset {
|
||||
Path path;
|
||||
|
||||
public SimpleAsset(AssetLocation location, IAssetPackage owner, Path path) {
|
||||
super(location, owner);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset subAsset(String alternative) {
|
||||
Path newPath = path.resolveSibling(path.getFileName().toString()+"."+alternative);
|
||||
return Files.exists(newPath) ? new SimpleAsset(location.alternate(alternative), owner, newPath) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream stream() throws IOException { return markClosed(Files.newInputStream(path)); }
|
||||
@Override
|
||||
public ByteBuffer bytes() throws IOException { return ByteBuffer.wrap(Files.readAllBytes(path)); }
|
||||
@Override
|
||||
public BufferedImage texture() throws Exception { return ImageIO.read(stream()); }
|
||||
@Override
|
||||
public BufferedReader reader() throws IOException { return markClosed(Files.newBufferedReader(path)); }
|
||||
@Override
|
||||
public List<String> lines() throws IOException { return Files.readAllLines(path); }
|
||||
@Override
|
||||
public JsonObject json() throws IOException { return JsonUtil.loadFile(path); }
|
||||
@Override
|
||||
public <T> T custom(IAssetParser<T> parser) throws IOException { return parser.parseAsset(path, closeable::add); }
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.IAsset;
|
||||
import speiger.src.coreengine.assets.IAssetParser;
|
||||
import speiger.src.coreengine.utils.helpers.JsonUtil;
|
||||
|
||||
public class ZipAsset implements IAsset
|
||||
{
|
||||
Runnable closer;
|
||||
AssetLocation location;
|
||||
Path path;
|
||||
Function<Class<?>, IAssetParser<?>> parsers;
|
||||
|
||||
public ZipAsset(Runnable closer, AssetLocation location, Path path, Function<Class<?>, IAssetParser<?>> parsers)
|
||||
{
|
||||
this.closer = closer;
|
||||
this.location = location;
|
||||
this.path = path;
|
||||
this.parsers = parsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
if(closer != null)
|
||||
{
|
||||
closer.run();
|
||||
closer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void closeInternal()
|
||||
{
|
||||
if(closer != null)
|
||||
{
|
||||
closer.run();
|
||||
closer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset subAsset(String alternative)
|
||||
{
|
||||
if(closer == null) return null;
|
||||
Path newPath = path.resolveSibling(path.getFileName().toString()+"."+alternative);
|
||||
return Files.exists(newPath) ? new ZipAsset(this::closeInternal, location.alternate(alternative), newPath, parsers) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetLocation getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getStream() throws IOException
|
||||
{
|
||||
return Files.newInputStream(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer getBytes() throws IOException
|
||||
{
|
||||
return ByteBuffer.wrap(Files.readAllBytes(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getTexture() throws Exception
|
||||
{
|
||||
return ImageIO.read(getStream());
|
||||
}
|
||||
@Override
|
||||
public BufferedReader getStringReader() throws IOException
|
||||
{
|
||||
return Files.newBufferedReader(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getJsonObject() throws IOException
|
||||
{
|
||||
return JsonUtil.loadFile(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCustom(Class<T> clz) throws IOException
|
||||
{
|
||||
return clz.cast(parsers.apply(clz).parseAsset(path, T -> {}));
|
||||
}
|
||||
}
|
||||
@@ -1,116 +1,107 @@
|
||||
package speiger.src.coreengine.assets.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.IAsset;
|
||||
import speiger.src.coreengine.assets.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.IAssetParser;
|
||||
import speiger.src.coreengine.assets.base.IAsset;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.utils.collections.iterators.IterableWrapper;
|
||||
|
||||
public class ZipAssetPackage implements IAssetPackage
|
||||
{
|
||||
public class ZipAssetPackage implements IAssetPackage {
|
||||
Path baseFolder;
|
||||
Function<Class<?>, IAssetParser<?>> parsers;
|
||||
FileSystem cache;
|
||||
AtomicInteger usedReferences = new AtomicInteger();
|
||||
Runnable referenceCleaner = this::cleanReference;
|
||||
|
||||
public ZipAssetPackage(File file)
|
||||
{
|
||||
this(file.toPath());
|
||||
}
|
||||
|
||||
public ZipAssetPackage(Path baseFolder)
|
||||
{
|
||||
public ZipAssetPackage(Path baseFolder) {
|
||||
this.baseFolder = baseFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParsers(Function<Class<?>, IAssetParser<?>> parsers)
|
||||
{
|
||||
this.parsers = parsers;
|
||||
}
|
||||
|
||||
private void cleanReference()
|
||||
{
|
||||
int left = usedReferences.decrementAndGet();
|
||||
if(left == 0 && cache != null)
|
||||
{
|
||||
public void close() {
|
||||
if(cache != null) {
|
||||
try { cache.close(); }
|
||||
catch(Exception e) {e.printStackTrace();}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
cache = null;
|
||||
}
|
||||
else if(left < 0) usedReferences.set(0);
|
||||
}
|
||||
|
||||
protected FileSystem getReference() throws IOException
|
||||
{
|
||||
usedReferences.getAndIncrement();
|
||||
@Override
|
||||
public void getModifiedTime(String domain, BiConsumer<AssetLocation, FileTime> accept) {
|
||||
try {
|
||||
try(FileSystem system = FileSystems.newFileSystem(baseFolder)) {
|
||||
Path start = system.getPath("assets");
|
||||
for(Path path : IterableWrapper.wrap(Files.walk(start.resolve(domain)).filter(Files::isRegularFile).iterator())) {
|
||||
accept.accept(AssetLocation.of(domain, start.relativize(path).toString().replace("\\", "/")), Files.getLastModifiedTime(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
protected FileSystem getReference() throws IOException {
|
||||
if(cache == null) cache = FileSystems.newFileSystem(baseFolder);
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDomains()
|
||||
{
|
||||
public List<String> getDomains() {
|
||||
List<String> domains = new ObjectArrayList<>();
|
||||
try(FileSystem system = FileSystems.newFileSystem(baseFolder))
|
||||
{
|
||||
try(DirectoryStream<Path> dirs = Files.newDirectoryStream(system.getPath("assets")))
|
||||
{
|
||||
for(Path path : dirs)
|
||||
{
|
||||
try(FileSystem system = FileSystems.newFileSystem(baseFolder)) {
|
||||
try(DirectoryStream<Path> dirs = Files.newDirectoryStream(system.getPath("assets"))) {
|
||||
for(Path path : dirs) {
|
||||
String s = path.getFileName().toString();
|
||||
domains.add(s.substring(0, s.length()-1));
|
||||
domains.add(s.substring(0, s.length() - 1));
|
||||
}
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
return domains;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAsset getAsset(AssetLocation location)
|
||||
{
|
||||
try
|
||||
{
|
||||
Path path = getReference().getPath(location.getActualLocation());
|
||||
return Files.exists(path) ? new ZipAsset(referenceCleaner, location, path, parsers) : null;
|
||||
public IAsset getAsset(AssetLocation location) {
|
||||
try {
|
||||
Path path = getReference().getPath(location.actualLocation());
|
||||
return Files.exists(path) ? new SimpleAsset(location, this, path) : null;
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
catch(Exception e) { return null; }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllAssets(AssetLocation folder, Predicate<String> fileNames, int maxDepth, Collection<AssetLocation> result)
|
||||
{
|
||||
try(FileSystem system = FileSystems.newFileSystem(baseFolder))
|
||||
{
|
||||
Path start = system.getPath(folder.getActualLocation());
|
||||
public void gatherAssets(AssetLocation folder, BiConsumer<AssetLocation, IAsset> result) {
|
||||
try {
|
||||
FileSystem system = getReference();
|
||||
Path start = system.getPath(folder.actualLocation());
|
||||
if(Files.notExists(start)) return;
|
||||
try(Stream<Path> stream = Files.walk(start, maxDepth).filter(Files::isRegularFile).filter(T -> fileNames.test(T.getFileName().toString())))
|
||||
{
|
||||
for(Path path : IterableWrapper.wrap(stream.iterator()))
|
||||
{
|
||||
result.add(folder.subAsset(start.relativize(path).toString().replace("\\", "/")));
|
||||
try(Stream<Path> stream = Files.walk(start).filter(Files::isRegularFile)) {
|
||||
for(Path path : IterableWrapper.wrap(stream.iterator())) {
|
||||
AssetLocation location = folder.subAsset(start.relativize(path).toString().replace("\\", "/"));
|
||||
result.accept(location, new SimpleAsset(location, this, path));
|
||||
}
|
||||
}
|
||||
catch(IOException e) { e.printStackTrace(); }
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,17 @@
|
||||
package speiger.src.coreengine.assets.language;
|
||||
|
||||
public class I18n
|
||||
{
|
||||
public class I18n {
|
||||
static Language CURRENT_LANGUAGE;
|
||||
|
||||
public static boolean has(String key)
|
||||
{
|
||||
public static boolean has(String key) {
|
||||
return CURRENT_LANGUAGE.has(key);
|
||||
}
|
||||
|
||||
public static String translate(String key)
|
||||
{
|
||||
public static String translate(String key) {
|
||||
return CURRENT_LANGUAGE.translate(key);
|
||||
}
|
||||
|
||||
public String translate(String key, Object...args)
|
||||
{
|
||||
public String translate(String key, Object... args) {
|
||||
return CURRENT_LANGUAGE.translate(key, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,50 +4,36 @@ import java.util.Map;
|
||||
|
||||
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
|
||||
|
||||
public class Language
|
||||
{
|
||||
public class Language {
|
||||
String language;
|
||||
String code;
|
||||
Map<String, String> translations = Object2ObjectMaps.empty();
|
||||
|
||||
public Language(String code, String language)
|
||||
{
|
||||
public Language(String code, String language) {
|
||||
this.code = code;
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public void load(Map<String, String> data)
|
||||
{
|
||||
public void load(Map<String, String> data) {
|
||||
translations = data;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
public void clear() {
|
||||
translations = Object2ObjectMaps.empty();
|
||||
}
|
||||
|
||||
public boolean has(String s)
|
||||
{
|
||||
public boolean has(String s) {
|
||||
return translations.containsKey(s);
|
||||
}
|
||||
|
||||
public String translate(String key)
|
||||
{
|
||||
public String translate(String key) {
|
||||
return translations.getOrDefault(key, key);
|
||||
}
|
||||
|
||||
public String translate(String key, Object...args)
|
||||
{
|
||||
public String translate(String key, Object... args) {
|
||||
return String.format(translate(key), args);
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getLanguage()
|
||||
{
|
||||
return language;
|
||||
}
|
||||
public String getCode() { return code; }
|
||||
public String getLanguage() { return language; }
|
||||
}
|
||||
|
||||
@@ -10,108 +10,79 @@ import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
|
||||
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.AssetManager;
|
||||
import speiger.src.coreengine.assets.MultiAsset;
|
||||
import speiger.src.coreengine.assets.base.MultiAsset;
|
||||
import speiger.src.coreengine.assets.reloader.IReloadableResource;
|
||||
|
||||
public class LanguageManager implements IReloadableResource
|
||||
{
|
||||
public class LanguageManager implements IReloadableResource {
|
||||
final AssetLocation location = AssetLocation.of("lang");
|
||||
Map<String, Language> languages = new Object2ObjectOpenHashMap<>();
|
||||
AssetManager assets;
|
||||
String currentLanguage;
|
||||
String currentLanguage;
|
||||
|
||||
@Override
|
||||
public void reload()
|
||||
{
|
||||
public void reload() {
|
||||
languages.clear();
|
||||
try(MultiAsset langs = assets.getAllAsset(location.subAsset("langs.json")))
|
||||
{
|
||||
for(int i = 0,m=langs.size();i<m;i++)
|
||||
{
|
||||
preLoadLanguage(langs.getAsset(i).getJsonObject());
|
||||
try(MultiAsset langs = assets.getAllAssets(location.subAsset("langs.json"))) {
|
||||
for(int i = 0,m = langs.size();i < m;i++) {
|
||||
preLoadLanguage(langs.get(i).json());
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(loadLanguage(currentLanguage))
|
||||
{
|
||||
if(loadLanguage(currentLanguage)) {
|
||||
I18n.CURRENT_LANGUAGE = languages.get(currentLanguage);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
Language dummy = new Language("en_US", "English");
|
||||
dummy.load(Object2ObjectMaps.empty());
|
||||
I18n.CURRENT_LANGUAGE = dummy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setLanguage(String lang)
|
||||
{
|
||||
if(loadLanguage(lang))
|
||||
{
|
||||
public boolean setLanguage(String lang) {
|
||||
if(loadLanguage(lang)) {
|
||||
I18n.CURRENT_LANGUAGE = languages.get(lang);
|
||||
Language currentLang = languages.get(currentLanguage);
|
||||
currentLanguage = lang;
|
||||
if(currentLang != null)
|
||||
{
|
||||
currentLang.clear();
|
||||
}
|
||||
if(currentLang != null) currentLang.clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean loadLanguage(String loadingLang)
|
||||
{
|
||||
protected boolean loadLanguage(String loadingLang) {
|
||||
Language lang = languages.get(loadingLang);
|
||||
if(lang == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(lang == null) return false;
|
||||
Map<String, String> map = new Object2ObjectOpenHashMap<>();
|
||||
loadLanguage(loadingLang, map);
|
||||
if(loadingLang != "en_US")
|
||||
{
|
||||
loadLanguage("en_US", map);
|
||||
}
|
||||
if(loadingLang != "en_US") loadLanguage("en_US", map);
|
||||
lang.load(map);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void loadLanguage(String lang, Map<String, String> data)
|
||||
{
|
||||
try(MultiAsset language = assets.getAllAsset(location.subAsset(lang+".lang")))
|
||||
{
|
||||
for(int i = 0,m=language.size();i<m;i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
for(Map.Entry<String, JsonElement> element : language.getAsset(i).getJsonObject().entrySet())
|
||||
{
|
||||
loadEntry(element.getKey(), element.getValue(), data);
|
||||
protected void loadLanguage(String lang, Map<String, String> data) {
|
||||
try(MultiAsset language = assets.getAllAssets(location.subAsset(lang+".lang"))) {
|
||||
for(int i = 0,m = language.size();i < m;i++) {
|
||||
try {
|
||||
for(Map.Entry<String, JsonElement> element : language.get(i).json().entrySet()) {
|
||||
loadEntry(element.getKey(), element.getValue(), data);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadEntry(String basePath, JsonElement el, Map<String, String> data)
|
||||
{
|
||||
if(el.isJsonPrimitive()) data.put(basePath, el.getAsString());
|
||||
else if(el.isJsonObject())
|
||||
{
|
||||
for(Map.Entry<String, JsonElement> elements : el.getAsJsonObject().entrySet())
|
||||
{
|
||||
protected void loadEntry(String basePath, JsonElement el, Map<String, String> data) {
|
||||
if(el.isJsonPrimitive()) data.putIfAbsent(basePath, el.getAsString());
|
||||
else if(el.isJsonObject()) {
|
||||
for(Map.Entry<String, JsonElement> elements : el.getAsJsonObject().entrySet()) {
|
||||
String key = elements.getKey();
|
||||
if(key.isEmpty()) loadEntry(basePath, elements.getValue(), data);
|
||||
else loadEntry(basePath+"."+key, elements.getValue(), data);
|
||||
@@ -119,31 +90,16 @@ public class LanguageManager implements IReloadableResource
|
||||
}
|
||||
}
|
||||
|
||||
protected void preLoadLanguage(JsonObject object)
|
||||
{
|
||||
protected void preLoadLanguage(JsonObject object) {
|
||||
JsonArray array = object.getAsJsonArray("languages");
|
||||
if(array == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(int i = 0,m=array.size();i<m;i++)
|
||||
{
|
||||
if(array == null) return;
|
||||
for(int i = 0,m = array.size();i < m;i++) {
|
||||
JsonArray subArray = array.get(i).getAsJsonArray();
|
||||
if(subArray.size() != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(subArray.size() != 2) continue;
|
||||
String key = subArray.get(0).getAsString();
|
||||
String value = subArray.get(1).getAsString();
|
||||
if(key.length() != 2 || value.length() > 16)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Language lang = languages.get(key);
|
||||
if(lang == null)
|
||||
{
|
||||
languages.put(key, new Language(key, value));
|
||||
}
|
||||
if(key.length() != 2 || value.length() > 16) continue;
|
||||
languages.computeIfAbsent(key, T -> new Language(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,5 @@ package speiger.src.coreengine.assets.reloader;
|
||||
public interface IReloadableResource
|
||||
{
|
||||
public void reload();
|
||||
|
||||
public default void destroy() {};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package speiger.src.coreengine.assets.reloader;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
|
||||
@@ -10,51 +11,31 @@ public class ResourceReloader
|
||||
boolean globalRemoval = false;
|
||||
boolean reloading = false;
|
||||
|
||||
public <T extends IReloadableResource> T addReloadableResource(T resource)
|
||||
{
|
||||
public <T extends IReloadableResource> T addReloadableResource(T resource) {
|
||||
return addReloadableResource(resource, false);
|
||||
}
|
||||
|
||||
public <T extends IReloadableResource> T addReloadableResource(T resource, boolean init)
|
||||
{
|
||||
if(resources.add(resource) && init)
|
||||
{
|
||||
resource.reload();
|
||||
}
|
||||
public <T extends IReloadableResource> T addReloadableResource(T resource, boolean init) {
|
||||
if(resources.add(resource) && init) resource.reload();
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void removeReloadableResource(IReloadableResource resource)
|
||||
{
|
||||
if(globalRemoval || reloading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void removeReloadableResource(IReloadableResource resource) {
|
||||
if(globalRemoval || reloading) return;
|
||||
resources.remove(resource);
|
||||
}
|
||||
|
||||
public boolean isReloading()
|
||||
{
|
||||
return reloading;
|
||||
}
|
||||
public boolean isReloading() { return reloading; }
|
||||
|
||||
public void reloadResources()
|
||||
{
|
||||
public void reloadResources() {
|
||||
reloading = true;
|
||||
for(IReloadableResource resource : resources)
|
||||
{
|
||||
resource.reload();
|
||||
}
|
||||
resources.forEach(IReloadableResource::reload);
|
||||
reloading = false;
|
||||
}
|
||||
|
||||
public void deleteResources()
|
||||
{
|
||||
public void deleteResources() {
|
||||
globalRemoval = true;
|
||||
for(IReloadableResource resource : resources)
|
||||
{
|
||||
resource.destroy();
|
||||
}
|
||||
resources.forEach(IReloadableResource::destroy);
|
||||
resources.clear();
|
||||
globalRemoval = false;
|
||||
}
|
||||
|
||||
@@ -1,76 +1,91 @@
|
||||
package speiger.src.coreengine.math;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
|
||||
public class ArrayUtil
|
||||
{
|
||||
public static int[] fromTo(int from, int to)
|
||||
{
|
||||
public class ArrayUtil {
|
||||
public static int[] fromTo(int from, int to) {
|
||||
int[] result = new int[to - from];
|
||||
for(int i = 0,m=result.length;i<m;i++)
|
||||
{
|
||||
result[i] = from + i;
|
||||
}
|
||||
for(int i = 0,m = result.length;i < m;i++) result[i] = from + i;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int sum(int...values)
|
||||
{
|
||||
public static int sum(int... values) {
|
||||
int result = 0;
|
||||
for(int index : values)
|
||||
{
|
||||
result += index;
|
||||
}
|
||||
for(int index : values) result += index;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] fill(byte[] array, byte value)
|
||||
{
|
||||
public static byte[] fill(byte[] array, byte value) {
|
||||
Arrays.fill(array, value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static short[] fill(short[] array, short value)
|
||||
{
|
||||
public static short[] fill(short[] array, short value) {
|
||||
Arrays.fill(array, value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static int[] fill(int[] array, int value)
|
||||
{
|
||||
public static int[] fill(int[] array, int value) {
|
||||
Arrays.fill(array, value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static long[] fill(long[] array, long value)
|
||||
{
|
||||
public static long[] fill(long[] array, long value) {
|
||||
Arrays.fill(array, value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static float[] fill(float[] array, float value)
|
||||
{
|
||||
public static float[] fill(float[] array, float value) {
|
||||
Arrays.fill(array, value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static double[] fill(double[] array, double value)
|
||||
{
|
||||
public static double[] fill(double[] array, double value) {
|
||||
Arrays.fill(array, value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static <T> List<T> makeList(IntList indexes, List<T> entries)
|
||||
{
|
||||
List<T> result = new ObjectArrayList<T>(indexes.size());
|
||||
for(int i = 0,m=indexes.size();i<m;i++)
|
||||
{
|
||||
result.add(entries.get(indexes.getInt(i)));
|
||||
public static byte[] toArray(ByteBuffer buffer) {
|
||||
if(buffer.hasArray()) {
|
||||
byte[] data = buffer.array();
|
||||
if(data.length == buffer.remaining()) return data;
|
||||
}
|
||||
byte[] data = new byte[buffer.remaining()];
|
||||
buffer.get(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] toArray(ByteBuffer buffer, Consumer<ByteBuffer> action) {
|
||||
if(buffer.hasArray()) {
|
||||
byte[] data = buffer.array();
|
||||
if(data.length == buffer.remaining()) {
|
||||
action.accept(buffer);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
byte[] data = new byte[buffer.remaining()];
|
||||
buffer.get(data);
|
||||
action.accept(buffer);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> T higher(T key, T value) {
|
||||
return key.compareTo(value) < 0 ? value : key;
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> T lower(T key, T value) {
|
||||
return key.compareTo(value) > 0 ? value : key;
|
||||
}
|
||||
|
||||
public static <T> List<T> makeList(IntList indexes, List<T> entries) {
|
||||
List<T> result = new ObjectArrayList<T>(indexes.size());
|
||||
for(int i = 0,m = indexes.size();i < m;i++) result.add(entries.get(indexes.getInt(i)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,60 +2,48 @@ package speiger.src.coreengine.math;
|
||||
|
||||
import speiger.src.coreengine.math.vector.ints.Vec2i;
|
||||
|
||||
public class BitUtil
|
||||
{
|
||||
public static long toLong(long firstShort, long secondShort)
|
||||
{
|
||||
public class BitUtil {
|
||||
public static long toLong(long firstShort, long secondShort) {
|
||||
return (firstShort << 32) | (secondShort & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
public static int toFirstInt(long value)
|
||||
{
|
||||
public static int toFirstInt(long value) {
|
||||
return (int)((value >> 32) & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
public static int toSecondInt(long value)
|
||||
{
|
||||
public static int toSecondInt(long value) {
|
||||
return (int)(value & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
public static long addToLong(long value, long x, long z)
|
||||
{
|
||||
public static long addToLong(long value, long x, long z) {
|
||||
return ((x + toFirstInt(value)) & 0xFFFFFFFFL) << 32 | (((z + toSecondInt(value)) & 0xFFFFFFFFL));
|
||||
}
|
||||
|
||||
public static int toInt(int firstShort, int secondShort)
|
||||
{
|
||||
public static int toInt(int firstShort, int secondShort) {
|
||||
return (firstShort & 0xFFFF) << 16 | (secondShort & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int toFirstShort(int value)
|
||||
{
|
||||
public static int toFirstShort(int value) {
|
||||
return (short)(value >> 16 & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int toSecondShort(int value)
|
||||
{
|
||||
public static int toSecondShort(int value) {
|
||||
return (short)(value & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int addToInt(int value, int x, int z)
|
||||
{
|
||||
public static int addToInt(int value, int x, int z) {
|
||||
return ((x + toFirstShort(value)) & 0xFFFF) << 16 | ((z + toSecondShort(value)) & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int addToInt(int value, Vec2i offset)
|
||||
{
|
||||
return ((offset.getX() + toFirstShort(value)) & 0xFFFF) << 16 | ((offset.getY() + toSecondShort(value)) & 0xFFFF);
|
||||
public static int addToInt(int value, Vec2i offset) {
|
||||
return ((offset.x() + toFirstShort(value)) & 0xFFFF) << 16 | ((offset.y() + toSecondShort(value)) & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int pack_2_10_10_10_int_rev(float x, float y, float z, float w)
|
||||
{
|
||||
public static int pack_2_10_10_10_int_rev(float x, float y, float z, float w) {
|
||||
return (Math.round(w * 3F) & 3) << 30 | (Math.round(((z * 0.5F) + 0.5F) * 1023F) & 1023) << 20 | (Math.round(((y * 0.5F) + 0.5F) * 1023F) & 1023) << 10 | (Math.round(((x * 0.5F) + 0.5F) * 1023F) & 1023);
|
||||
}
|
||||
|
||||
public static int pack_10_10_10_2_int(float x, float y, float z, float w)
|
||||
{
|
||||
public static int pack_10_10_10_2_int(float x, float y, float z, float w) {
|
||||
return (Math.round(((x * 0.5F) + 0.5F) * 1023F) & 1023) << 22 | (Math.round(((y * 0.5F) + 0.5F) * 1023F) & 1023) << 12 | (Math.round(((z * 0.5F) + 0.5F) * 1023F) & 1023) << 2 | (Math.round(w * 3F) & 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,155 +1,126 @@
|
||||
package speiger.src.coreengine.math;
|
||||
|
||||
public class MathUtils
|
||||
{
|
||||
public class MathUtils {
|
||||
private static final float[] SIN_TABLE;
|
||||
private static final float[] COS_TABLE;
|
||||
private static final float TABLE_MASK;
|
||||
private static final int SIN_MASK;
|
||||
public static final double PI_INVERSION = 180D / Math.PI;
|
||||
|
||||
public static float sin(float a)
|
||||
{
|
||||
public static float sin(float a) {
|
||||
return SIN_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static float sin(double a)
|
||||
{
|
||||
public static float sin(double a) {
|
||||
return SIN_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static float cos(float a)
|
||||
{
|
||||
public static float cos(float a) {
|
||||
return COS_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static float cos(double a)
|
||||
{
|
||||
public static float cos(double a) {
|
||||
return COS_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static byte clamp(byte min, byte max, byte current)
|
||||
{
|
||||
public static byte clamp(byte min, byte max, byte current) {
|
||||
return current < min ? min : (current > max ? max : current);
|
||||
}
|
||||
|
||||
public static short clamp(short min, short max, short current)
|
||||
{
|
||||
public static short clamp(short min, short max, short current) {
|
||||
return current < min ? min : (current > max ? max : current);
|
||||
}
|
||||
|
||||
public static int clamp(int min, int max, int current)
|
||||
{
|
||||
public static int clamp(int min, int max, int current) {
|
||||
return current < min ? min : (current > max ? max : current);
|
||||
}
|
||||
|
||||
public static float clamp(float min, float max, float current)
|
||||
{
|
||||
public static float clamp(float min, float max, float current) {
|
||||
return current < min ? min : (current > max ? max : current);
|
||||
}
|
||||
|
||||
public static double clamp(double min, double max, double current)
|
||||
{
|
||||
public static double clamp(double min, double max, double current) {
|
||||
return current < min ? min : (current > max ? max : current);
|
||||
}
|
||||
|
||||
public static long clamp(long min, long max, long current)
|
||||
{
|
||||
public static long clamp(long min, long max, long current) {
|
||||
return current < min ? min : (current > max ? max : current);
|
||||
}
|
||||
|
||||
public static byte sign(byte value)
|
||||
{
|
||||
public static byte sign(byte value) {
|
||||
return value > 0 ? 1 : (value < 0 ? -1 : (byte)0);
|
||||
}
|
||||
|
||||
public static short sign(short value)
|
||||
{
|
||||
public static short sign(short value) {
|
||||
return value > 0 ? 1 : (value < 0 ? -1 : (short)0);
|
||||
}
|
||||
|
||||
public static int sign(int value)
|
||||
{
|
||||
public static int sign(int value) {
|
||||
return value > 0 ? 1 : (value < 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
public static long sign(long value)
|
||||
{
|
||||
public static long sign(long value) {
|
||||
return value > 0 ? 1 : (value < 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
public static float sign(float value)
|
||||
{
|
||||
public static float sign(float value) {
|
||||
return value > 0 ? 1F : (value < 0 ? -1F : 0F);
|
||||
}
|
||||
|
||||
public static double sign(double value)
|
||||
{
|
||||
public static double sign(double value) {
|
||||
return value > 0 ? 1D : (value < 0 ? -1D : 0D);
|
||||
}
|
||||
|
||||
public static int sub(int key, int value)
|
||||
{
|
||||
public static int sub(int key, int value) {
|
||||
return key - value;
|
||||
}
|
||||
|
||||
public static int ceil(double value)
|
||||
{
|
||||
public static int ceil(double value) {
|
||||
int i = (int)value;
|
||||
return value > i ? i + 1 : i;
|
||||
}
|
||||
|
||||
public static int ceil(float value)
|
||||
{
|
||||
public static int ceil(float value) {
|
||||
int i = (int)value;
|
||||
return value > i ? i + 1 : i;
|
||||
}
|
||||
|
||||
public static int floor(float value)
|
||||
{
|
||||
public static int floor(float value) {
|
||||
int i = (int)value;
|
||||
return value < i ? i - 1 : i;
|
||||
}
|
||||
|
||||
public static int floor(double value)
|
||||
{
|
||||
public static int floor(double value) {
|
||||
int i = (int)value;
|
||||
return value < i ? i - 1 : i;
|
||||
}
|
||||
|
||||
public static int pow(int base, int exp)
|
||||
{
|
||||
public static int pow(int base, int exp) {
|
||||
return (int)Math.pow(base, exp);
|
||||
}
|
||||
|
||||
public static float lerp(float start, float end, float progress)
|
||||
{
|
||||
public static float lerp(float start, float end, float progress) {
|
||||
return start + ((end - start) * progress);
|
||||
}
|
||||
|
||||
public static double lerp(double start, double end, float progress)
|
||||
{
|
||||
public static double lerp(double start, double end, float progress) {
|
||||
return start + ((end - start) * progress);
|
||||
}
|
||||
|
||||
public static float smoothLerp(float start, float end, float progress)
|
||||
{
|
||||
public static float smoothLerp(float start, float end, float progress) {
|
||||
float cosProgress = (1F - MathUtils.cos(progress * Math.PI)) * 0.5F;
|
||||
return start * (1F - cosProgress) + end * cosProgress;
|
||||
}
|
||||
|
||||
public static float quadraticCurve(float start, float median, float end, float progress)
|
||||
{
|
||||
public static float quadraticCurve(float start, float median, float end, float progress) {
|
||||
return lerp(lerp(start, median, progress), lerp(median, end, progress), progress);
|
||||
}
|
||||
|
||||
public static float smoothQuadraticCurve(float start, float median, float end, float progress)
|
||||
{
|
||||
public static float smoothQuadraticCurve(float start, float median, float end, float progress) {
|
||||
return smoothLerp(smoothLerp(start, median, progress), smoothLerp(median, end, progress), progress);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
SIN_MASK = ~(-1 << 12);
|
||||
int SIN_COUNT = SIN_MASK + 1;
|
||||
|
||||
@@ -162,13 +133,11 @@ public class MathUtils
|
||||
SIN_TABLE = new float[SIN_COUNT];
|
||||
COS_TABLE = new float[SIN_COUNT];
|
||||
|
||||
for(int i = 0;i < SIN_COUNT;i++)
|
||||
{
|
||||
for(int i = 0;i < SIN_COUNT;i++) {
|
||||
SIN_TABLE[i] = (float)Math.sin((i + 0.5f) / SIN_COUNT * radFull);
|
||||
COS_TABLE[i] = (float)Math.cos((i + 0.5f) / SIN_COUNT * radFull);
|
||||
}
|
||||
for(int i = 0;i < 360;i += 90)
|
||||
{
|
||||
for(int i = 0;i < 360;i += 90) {
|
||||
SIN_TABLE[(int)(i * degToIndex) & SIN_MASK] = (float)Math.sin(i * Math.PI / 180D);
|
||||
COS_TABLE[(int)(i * degToIndex) & SIN_MASK] = (float)Math.cos(i * Math.PI / 180D);
|
||||
}
|
||||
|
||||
@@ -2,20 +2,16 @@ package speiger.src.coreengine.math;
|
||||
|
||||
import speiger.src.coreengine.math.vector.ints.Vec2i;
|
||||
|
||||
public class ShapeUtil
|
||||
{
|
||||
public static boolean isInCircle(int position, int radius, int testX, int testZ)
|
||||
{
|
||||
public class ShapeUtil {
|
||||
public static boolean isInCircle(int position, int radius, int testX, int testZ) {
|
||||
return isInCircle(BitUtil.toFirstShort(position), BitUtil.toSecondShort(position), radius, testX, testZ);
|
||||
}
|
||||
|
||||
public static boolean isInCircle(Vec2i position, int radius, int testX, int testZ)
|
||||
{
|
||||
return isInCircle(position.getX(), position.getY(), radius, testX, testZ);
|
||||
public static boolean isInCircle(Vec2i position, int radius, int testX, int testZ) {
|
||||
return isInCircle(position.x(), position.y(), radius, testX, testZ);
|
||||
}
|
||||
|
||||
public static boolean isInCircle(int posX, int posZ, int radius, int testX, int testZ)
|
||||
{
|
||||
public static boolean isInCircle(int posX, int posZ, int radius, int testX, int testZ) {
|
||||
posX -= testX;
|
||||
posZ -= testZ;
|
||||
return (posX * posX) + (posZ * posZ) < radius * radius;
|
||||
|
||||
@@ -5,87 +5,62 @@ import java.util.Iterator;
|
||||
import speiger.src.coreengine.math.vector.ints.Vec2i;
|
||||
import speiger.src.coreengine.math.vector.ints.Vec3i;
|
||||
|
||||
public class Circle implements I2DCollision
|
||||
{
|
||||
public class Circle implements I2DCollision {
|
||||
final Vec2i center;
|
||||
final int radius;
|
||||
|
||||
public Circle(int x, int y, int radius)
|
||||
{
|
||||
public Circle(int x, int y, int radius) {
|
||||
center = Vec2i.of(x, y);
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public Circle(Vec2i center, int radius)
|
||||
{
|
||||
public Circle(Vec2i center, int radius) {
|
||||
this.center = center.asImmutable();
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public Circle(Vec3i data)
|
||||
{
|
||||
this(data.getX(), data.getY(), data.getZ());
|
||||
public Circle(Vec3i data) {
|
||||
this(data.x(), data.y(), data.z());
|
||||
}
|
||||
|
||||
public Vec2i getCenter()
|
||||
{
|
||||
return center;
|
||||
}
|
||||
public Vec2i getCenter() { return center; }
|
||||
|
||||
public int getRadius()
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
public int getRadius() { return radius; }
|
||||
|
||||
@Override
|
||||
public boolean isColliding(int x, int y)
|
||||
{
|
||||
int xDiff = center.getX() - x;
|
||||
int yDiff = center.getY() - y;
|
||||
public boolean isColliding(int x, int y) {
|
||||
int xDiff = center.x() - x;
|
||||
int yDiff = center.y() - y;
|
||||
return ((xDiff * xDiff) + (yDiff * yDiff)) < radius * radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Vec2i> iterator()
|
||||
{
|
||||
return new Iterator<Vec2i>(){
|
||||
public Iterator<Vec2i> iterator() {
|
||||
return new Iterator<Vec2i>() {
|
||||
Vec2i iter = step(Vec2i.mutable(center).sub(radius));
|
||||
Vec2i result = Vec2i.mutable();
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
public boolean hasNext() {
|
||||
return iter != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vec2i next()
|
||||
{
|
||||
public Vec2i next() {
|
||||
result.set(iter);
|
||||
iter = step(iter);
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec2i step(Vec2i iter)
|
||||
{
|
||||
while(iter != null)
|
||||
{
|
||||
iter.add(1, 0);
|
||||
if(iter.getX() >= center.getX() + radius)
|
||||
{
|
||||
iter.sub((radius * 2), 0).add(0, 1);
|
||||
if(iter.getY() >= center.getY() + radius)
|
||||
{
|
||||
iter = null;
|
||||
}
|
||||
}
|
||||
if(iter != null && isColliding(iter))
|
||||
{
|
||||
break;
|
||||
Vec2i step(Vec2i iter) {
|
||||
while(iter != null) {
|
||||
if(iter.add(1, 0).x() >= center.x() + radius) {
|
||||
if(iter.sub((radius * 2), 0).add(0, 1).y() >= center.y() + radius) iter = null;
|
||||
}
|
||||
if(iter != null && isColliding(iter)) break;
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ public interface I2DCollision extends Iterable<Vec2i>
|
||||
{
|
||||
public default boolean isMixedCollision() {return false;}
|
||||
public default boolean isColliding(int position){return isColliding(BitUtil.toFirstShort(position), BitUtil.toSecondShort(position));}
|
||||
public default boolean isColliding(Vec2i pos){return isColliding(pos.getX(), pos.getY());}
|
||||
public default boolean isColliding(Vec2i pos){return isColliding(pos.x(), pos.y());}
|
||||
public boolean isColliding(int x, int y);
|
||||
}
|
||||
|
||||
@@ -9,60 +9,45 @@ public class Mixed2DCollision implements I2DCollision
|
||||
I2DCollision mainBox;
|
||||
I2DCollision[] subBoxes;
|
||||
|
||||
public Mixed2DCollision(I2DCollision mainBox, I2DCollision...subBoxes)
|
||||
{
|
||||
public Mixed2DCollision(I2DCollision mainBox, I2DCollision...subBoxes) {
|
||||
this.mainBox = mainBox;
|
||||
this.subBoxes = subBoxes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColliding(int x, int y)
|
||||
{
|
||||
public boolean isColliding(int x, int y) {
|
||||
return mainBox.isColliding(x, y) && isCollidingInSubBox(x, y);
|
||||
}
|
||||
|
||||
public boolean isCollidingInSubBox(int x, int y)
|
||||
{
|
||||
for(int i = 0,m=subBoxes.length;i<m;i++)
|
||||
{
|
||||
if(!subBoxes[i].isColliding(x, y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public boolean isCollidingInSubBox(int x, int y) {
|
||||
for(int i = 0,m=subBoxes.length;i<m;i++) {
|
||||
if(!subBoxes[i].isColliding(x, y)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Vec2i> iterator()
|
||||
{
|
||||
public Iterator<Vec2i> iterator() {
|
||||
return new Iterator<Vec2i>(){
|
||||
Iterator<Vec2i> mainIter = mainBox.iterator();
|
||||
Vec2i cache = findNext(Vec2i.mutable());
|
||||
Vec2i result = Vec2i.mutable();
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
public boolean hasNext() {
|
||||
return cache != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2i next()
|
||||
{
|
||||
public Vec2i next() {
|
||||
result.set(cache);
|
||||
cache = findNext(cache);
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec2i findNext(Vec2i input)
|
||||
{
|
||||
while(mainIter.hasNext())
|
||||
{
|
||||
Vec2i findNext(Vec2i input) {
|
||||
while(mainIter.hasNext()) {
|
||||
Vec2i next = mainIter.next();
|
||||
if(isCollidingInSubBox(next.getX(), next.getY()))
|
||||
{
|
||||
return input.set(next);
|
||||
}
|
||||
if(isCollidingInSubBox(next.x(), next.y())) return input.set(next);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,96 +4,70 @@ import java.util.Iterator;
|
||||
|
||||
import speiger.src.coreengine.math.vector.ints.Vec2i;
|
||||
|
||||
public class Plane implements I2DCollision
|
||||
{
|
||||
public class Plane implements I2DCollision {
|
||||
Vec2i min;
|
||||
Vec2i max;
|
||||
|
||||
public Plane()
|
||||
{
|
||||
public Plane() {
|
||||
this(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public Plane(int minX, int minY, int maxX, int maxY)
|
||||
{
|
||||
public Plane(int minX, int minY, int maxX, int maxY) {
|
||||
this(Vec2i.mutable(minX, minY), Vec2i.mutable(maxX, maxY));
|
||||
}
|
||||
|
||||
public Plane(Vec2i center, int radius)
|
||||
{
|
||||
public Plane(Vec2i center, int radius) {
|
||||
this(center.sub(radius), center.add(radius));
|
||||
}
|
||||
|
||||
public Plane(Vec2i min, Vec2i max)
|
||||
{
|
||||
public Plane(Vec2i min, Vec2i max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Plane set(Plane other)
|
||||
{
|
||||
public Plane set(Plane other) {
|
||||
min.set(other.getMin());
|
||||
max.set(other.getMax());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Plane set(int minX, int minY, int maxX, int maxY)
|
||||
{
|
||||
public Plane set(int minX, int minY, int maxX, int maxY) {
|
||||
min.set(minX, minY);
|
||||
max.set(maxX, maxY);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColliding(int x, int y)
|
||||
{
|
||||
return x >= min.getX() && y >= min.getY() && x < max.getX() && y < max.getY();
|
||||
}
|
||||
|
||||
public boolean isIntersecting(Plane plane)
|
||||
{
|
||||
return isIntersecting(plane.getMinX(), plane.getMinY(), plane.getMaxX(), plane.getMaxY());
|
||||
}
|
||||
|
||||
public boolean isIntersecting(int minX, int minY, int maxX, int maxY)
|
||||
{
|
||||
return min.getX() <= maxX && max.getX() >= minX && min.getY() <= maxY && max.getY() >= minY;
|
||||
}
|
||||
|
||||
public Vec2i getMin(){return min;}
|
||||
public Vec2i getMax(){return max;}
|
||||
public int getWidth(){return max.getX() - min.getX();}
|
||||
public int getHeight(){return max.getY() - min.getY();}
|
||||
public int getMinX(){return min.getX();}
|
||||
public int getMinY(){return min.getY();}
|
||||
public int getMaxX(){return max.getX();}
|
||||
public int getMaxY(){return max.getY();}
|
||||
public boolean isColliding(int x, int y) { return x >= min.x() && y >= min.y() && x < max.x() && y < max.y(); }
|
||||
public boolean isIntersecting(Plane plane) { return isIntersecting(plane.getMinX(), plane.getMinY(), plane.getMaxX(), plane.getMaxY()); }
|
||||
public boolean isIntersecting(int minX, int minY, int maxX, int maxY) { return min.x() <= maxX && max.x() >= minX && min.y() <= maxY && max.y() >= minY; }
|
||||
public Vec2i getMin() { return min; }
|
||||
public Vec2i getMax() { return max; }
|
||||
public int getWidth() { return max.x() - min.x(); }
|
||||
public int getHeight() { return max.y() - min.y(); }
|
||||
public int getMinX() { return min.x(); }
|
||||
public int getMinY() { return min.y(); }
|
||||
public int getMaxX() { return max.x(); }
|
||||
public int getMaxY() { return max.y(); }
|
||||
|
||||
@Override
|
||||
public Iterator<Vec2i> iterator()
|
||||
{
|
||||
return new Iterator<Vec2i>(){
|
||||
public Iterator<Vec2i> iterator() {
|
||||
return new Iterator<Vec2i>() {
|
||||
Vec2i iter = Vec2i.mutable(min);
|
||||
Vec2i result = Vec2i.mutable();
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
public boolean hasNext() {
|
||||
return iter != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vec2i next()
|
||||
{
|
||||
public Vec2i next() {
|
||||
result.set(iter);
|
||||
iter.add(1, 0);
|
||||
if(iter.getX() == max.getX())
|
||||
{
|
||||
iter.set(min.getX(), iter.getY() + 1);
|
||||
if(iter.getY() == max.getY())
|
||||
{
|
||||
iter = null;
|
||||
}
|
||||
if(iter.x() == max.x()) {
|
||||
iter.set(min.x(), iter.y() + 1);
|
||||
if(iter.y() == max.y()) iter = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import java.nio.FloatBuffer;
|
||||
import speiger.src.collections.floats.lists.FloatList;
|
||||
import speiger.src.coreengine.math.MathUtils;
|
||||
|
||||
public class ColorUtils
|
||||
{
|
||||
public class ColorUtils {
|
||||
static final float DEVIDER = 1F / 255F;
|
||||
public static final int R = 0xFF << 16;
|
||||
public static final int G = 0xFF << 8;
|
||||
@@ -15,7 +14,6 @@ public class ColorUtils
|
||||
public static final int A = 0xFF << 24;
|
||||
public static final long SIGN = 0x00000000FFFFFFFFL;
|
||||
static final int ALL = 0xFFFFFFFF;
|
||||
|
||||
public static final int WHITE = rgb(255, 255, 255);
|
||||
public static final int LIGHT_GRAY = rgb(192, 192, 192);
|
||||
public static final int GRAY = rgb(128, 128, 128);
|
||||
@@ -32,16 +30,15 @@ public class ColorUtils
|
||||
public static final int CYAN = rgb(0, 255, 255);
|
||||
public static final int BLUE = rgb(0, 0, 255);
|
||||
public static final int LIGHT_BLUE = rgb(0, 150, 255);
|
||||
|
||||
//Specialized Components that get reused
|
||||
|
||||
// Specialized Components that get reused
|
||||
public static final int INVISIBLE = rgb(0, 0, 0, 0);
|
||||
public static final int TEXT_DEFAULT_BACKGROUND = rgb(80, 80, 80, 144);
|
||||
public static final int WINDOW_DEFAULT_BACKGROUND = rgb(64, 64, 64, 128);
|
||||
public static final int POPUP_DEFAULT_BACKGROUND = rgb(85, 85, 85);
|
||||
public static final int DESTRUCTION = rgb(255, 0, 0, 128);
|
||||
|
||||
public static byte[] toByteArray(int color, boolean alpha)
|
||||
{
|
||||
public static byte[] toByteArray(int color, boolean alpha) {
|
||||
byte[] data = new byte[alpha ? 4 : 3];
|
||||
data[0] = (byte)((color >> 16) & 0xFF);
|
||||
data[1] = (byte)((color >> 8) & 0xFF);
|
||||
@@ -50,325 +47,154 @@ public class ColorUtils
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void write(int color, boolean alpha, ByteBuffer buffer)
|
||||
{
|
||||
public static void write(int color, boolean alpha, ByteBuffer buffer) {
|
||||
buffer.put((byte)((color >> 16) & 0xFF)).put((byte)((color >> 8) & 0xFF)).put((byte)(color & 0xFF));
|
||||
if(alpha)
|
||||
{
|
||||
buffer.put((byte)((color >> 24) & 0xFF));
|
||||
}
|
||||
if(alpha) { buffer.put((byte)((color >> 24) & 0xFF)); }
|
||||
}
|
||||
|
||||
public static void write(int index, int color, boolean alpha, ByteBuffer buffer)
|
||||
{
|
||||
public static void write(int index, int color, boolean alpha, ByteBuffer buffer) {
|
||||
buffer.put(index, (byte)((color >> 16) & 0xFF)).put(index + 1, (byte)((color >> 8) & 0xFF)).put(index + 2, (byte)(color & 0xFF));
|
||||
if(alpha)
|
||||
{
|
||||
buffer.put(index + 3, (byte)((color >> 24) & 0xFF));
|
||||
}
|
||||
if(alpha) buffer.put(index + 3, (byte)((color >> 24) & 0xFF));
|
||||
}
|
||||
|
||||
public static void writeFloat(int color, boolean alpha, ByteBuffer buffer)
|
||||
{
|
||||
public static void writeFloat(int color, boolean alpha, ByteBuffer buffer) {
|
||||
buffer.putFloat(((color >> 16) & 0xFF) * DEVIDER).putFloat(((color >> 8) & 0xFF) * DEVIDER).putFloat((color & 0xFF) * DEVIDER);
|
||||
if(alpha)
|
||||
{
|
||||
buffer.putFloat(((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
if(alpha) buffer.putFloat(((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
|
||||
public static void writeFloat(int index, int color, boolean alpha, ByteBuffer buffer)
|
||||
{
|
||||
public static void writeFloat(int index, int color, boolean alpha, ByteBuffer buffer) {
|
||||
buffer.putFloat(index, ((color >> 16) & 0xFF) * DEVIDER).putFloat(index + 1, ((color >> 8) & 0xFF) * DEVIDER).putFloat(index + 2, (color & 0xFF) * DEVIDER);
|
||||
if(alpha)
|
||||
{
|
||||
buffer.putFloat(index + 3, ((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
if(alpha) buffer.putFloat(index + 3, ((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
|
||||
public static void write(int color, boolean alpha, FloatBuffer buffer)
|
||||
{
|
||||
public static void write(int color, boolean alpha, FloatBuffer buffer) {
|
||||
buffer.put(((color >> 16) & 0xFF) * DEVIDER).put(((color >> 8) & 0xFF) * DEVIDER).put((color & 0xFF) * DEVIDER);
|
||||
if(alpha)
|
||||
{
|
||||
buffer.put(((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
if(alpha) buffer.put(((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
|
||||
public static void write(int index, int color, boolean alpha, FloatBuffer buffer)
|
||||
{
|
||||
public static void write(int index, int color, boolean alpha, FloatBuffer buffer) {
|
||||
buffer.put(index, ((color >> 16) & 0xFF) * DEVIDER).put(index + 1, ((color >> 8) & 0xFF) * DEVIDER).put(index + 2, (color & 0xFF) * DEVIDER);
|
||||
if(alpha)
|
||||
{
|
||||
buffer.put(index + 3, ((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
if(alpha) buffer.put(index + 3, ((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
|
||||
public static void write(int color, boolean alpha, FloatList list)
|
||||
{
|
||||
public static void write(int color, boolean alpha, FloatList list) {
|
||||
list.add(((color >> 16) & 0xFF) * DEVIDER);
|
||||
list.add(((color >> 8) & 0xFF) * DEVIDER);
|
||||
list.add((color & 0xFF) * DEVIDER);
|
||||
if(alpha)
|
||||
{
|
||||
list.add(((color >> 24) & 0xFF) * DEVIDER);
|
||||
}
|
||||
if(alpha) { list.add(((color >> 24) & 0xFF) * DEVIDER); }
|
||||
}
|
||||
|
||||
public static int read(ByteBuffer buffer, boolean alpha)
|
||||
{
|
||||
return alpha ? rgb(buffer.get(), buffer.get(), buffer.get()) : rgb(buffer.get(), buffer.get(), buffer.get(), buffer.get());
|
||||
public static int read(ByteBuffer buffer, boolean alpha) { return alpha ? rgb(buffer.get(), buffer.get(), buffer.get()) : rgb(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
public static int read(ByteBuffer buffer, int index, boolean alpha) { return alpha ? rgb(buffer.get(index), buffer.get(index + 1), buffer.get(index + 2)) : rgb(buffer.get(index), buffer.get(index + 1), buffer.get(index + 2), buffer.get(index + 3)); }
|
||||
public static int readFloat(ByteBuffer buffer, boolean alpha) { return alpha ? rgb(buffer.getFloat(), buffer.getFloat(), buffer.getFloat()) : rgb(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat()); }
|
||||
public static int readFloat(ByteBuffer buffer, int index, boolean alpha) { return alpha ? rgb(buffer.getFloat(index), buffer.getFloat(index + 1), buffer.getFloat(index + 2)) : rgb(buffer.getFloat(index), buffer.getFloat(index + 1), buffer.getFloat(index + 2), buffer.getFloat(index + 3)); }
|
||||
public static int read(FloatBuffer buffer, boolean alpha) { return alpha ? rgb(buffer.get(), buffer.get(), buffer.get()) : rgb(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
public static int read(FloatBuffer buffer, int index, boolean alpha) { return alpha ? rgb(buffer.get(index), buffer.get(index + 1), buffer.get(index + 2)) : rgb(buffer.get(index), buffer.get(index + 1), buffer.get(index + 2), buffer.get(index + 3)); }
|
||||
public static boolean needsDarkColor(int rgba) { return getBrightness(rgba) >= 130; }
|
||||
public static int getBrightness(int rgba) { return getBrightness((rgba >> 16) & 0xFF, (rgba >> 8) & 0xFF, rgba & 0xFF); }
|
||||
public static int getBrightness(int r, int g, int b) { return (int)Math.sqrt((r * r * 0.241F) + (g * g * 0.691F) + (b * b * 0.068F)); }
|
||||
|
||||
public static int mix(int from, int to, float factor) {
|
||||
float weight0 = (1F - factor);
|
||||
float weight1 = factor;
|
||||
int r = (int)((((from >> 16) & 0xFF) * weight0) + (((to >> 16) & 0xFF) * weight1));
|
||||
int g = (int)((((from >> 8) & 0xFF) * weight0) + (((to >> 8) & 0xFF) * weight1));
|
||||
int b = (int)(((from & 0xFF) * weight0) + ((to & 0xFF) * weight1));
|
||||
int a = (int)((((from >> 24) & 0xFF) * weight0) + (((to >> 24) & 0xFF) * weight1));
|
||||
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | b & 0xFF;
|
||||
}
|
||||
|
||||
public static int read(ByteBuffer buffer, int index, boolean alpha)
|
||||
{
|
||||
return alpha ? rgb(buffer.get(index), buffer.get(index+1), buffer.get(index+2)) : rgb(buffer.get(index), buffer.get(index+1), buffer.get(index+2), buffer.get(index+3));
|
||||
}
|
||||
|
||||
public static int readFloat(ByteBuffer buffer, boolean alpha)
|
||||
{
|
||||
return alpha ? rgb(buffer.getFloat(), buffer.getFloat(), buffer.getFloat()) : rgb(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
|
||||
}
|
||||
|
||||
public static int readFloat(ByteBuffer buffer, int index, boolean alpha)
|
||||
{
|
||||
return alpha ? rgb(buffer.getFloat(index), buffer.getFloat(index+1), buffer.getFloat(index+2)) : rgb(buffer.getFloat(index), buffer.getFloat(index+1), buffer.getFloat(index+2), buffer.getFloat(index+3));
|
||||
}
|
||||
|
||||
public static int read(FloatBuffer buffer, boolean alpha)
|
||||
{
|
||||
return alpha ? rgb(buffer.get(), buffer.get(), buffer.get()) : rgb(buffer.get(), buffer.get(), buffer.get(), buffer.get());
|
||||
}
|
||||
|
||||
public static int read(FloatBuffer buffer, int index, boolean alpha)
|
||||
{
|
||||
return alpha ? rgb(buffer.get(index), buffer.get(index+1), buffer.get(index+2)) : rgb(buffer.get(index), buffer.get(index+1), buffer.get(index+2), buffer.get(index+3));
|
||||
}
|
||||
|
||||
public static boolean needsDarkColor(int rgba)
|
||||
{
|
||||
return getBrightness(rgba) >= 130;
|
||||
}
|
||||
|
||||
public static int getBrightness(int rgba)
|
||||
{
|
||||
return getBrightness((rgba >> 16) & 0xFF, (rgba >> 8) & 0xFF, rgba & 0xFF);
|
||||
}
|
||||
|
||||
public static int getBrightness(int r, int g, int b)
|
||||
{
|
||||
return (int)Math.sqrt((r * r * 0.241F) + (g * g * 0.691F) + (b * b * 0.068F));
|
||||
}
|
||||
|
||||
public static int mix(int from, int to, float factor)
|
||||
{
|
||||
float weight0 = (1F - factor);
|
||||
float weight1 = factor;
|
||||
int r = (int)((((from >> 16) & 0xFF) * weight0) + (((to >> 16) & 0xFF) * weight1));
|
||||
int g = (int)((((from >> 8) & 0xFF) * weight0) + (((to >> 8) & 0xFF) * weight1));
|
||||
int b = (int)(((from & 0xFF) * weight0) + ((to & 0xFF) * weight1));
|
||||
int a = (int)((((from >> 24) & 0xFF) * weight0) + (((to >> 24) & 0xFF) * weight1));
|
||||
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | b & 0xFF;
|
||||
}
|
||||
|
||||
public static int darker(int color)
|
||||
{
|
||||
return darker(color, 0.7F);
|
||||
}
|
||||
|
||||
public static int darker(int color, float factor)
|
||||
{
|
||||
public static int darker(int color) { return darker(color, 0.7F); }
|
||||
public static int darker(int color, float factor) {
|
||||
int r = Math.max(0, (int)(((color >> 16) & 0xFF) * factor));
|
||||
int g = Math.max(0, (int)(((color >> 8) & 0xFF) * factor));
|
||||
int b = Math.max(0, (int)((color & 0xFF) * factor));
|
||||
return (color & A) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
|
||||
}
|
||||
|
||||
public static int brighter(int color)
|
||||
{
|
||||
return brighter(color, 0.7F);
|
||||
}
|
||||
|
||||
public static int brighter(int color, float factor)
|
||||
{
|
||||
public static int brighter(int color) { return brighter(color, 0.7F); }
|
||||
public static int brighter(int color, float factor) {
|
||||
int r = (color >> 16) & 0xFF;
|
||||
int g = (color >> 8) & 0xFF;
|
||||
int b = color & 0xFF;
|
||||
int i = (int)(1.0 / (1.0 - factor));
|
||||
if(r == 0 && g == 0 && b == 0)
|
||||
{
|
||||
return (color & A) | ((i & 0xFF) << 16) | ((i & 0xFF) << 8) | (i & 0xFF);
|
||||
}
|
||||
if(r == 0 && g == 0 && b == 0) { return (color & A) | ((i & 0xFF) << 16) | ((i & 0xFF) << 8) | (i & 0xFF); }
|
||||
if(r > 0 && r < i) r = i;
|
||||
if(g > 0 && g < i) g = i;
|
||||
if(b > 0 && b < i) b = i;
|
||||
return (color & A) | Math.min(255, (int)(r / factor)) << 16 | Math.min(255, (int)(g / factor)) << 8 | Math.min(255, (int)(b / factor));
|
||||
}
|
||||
|
||||
public static int toRGB(float hue, float saturation, float brightness)
|
||||
{
|
||||
if (saturation == 0)
|
||||
{
|
||||
public static int toRGB(float hue, float saturation, float brightness) {
|
||||
if(saturation == 0) {
|
||||
int result = (int)(brightness * 255F + 0.5F);
|
||||
return rgb(result, result, result);
|
||||
}
|
||||
}
|
||||
float h = (hue - MathUtils.floor(hue)) * 6F;
|
||||
float f = h - MathUtils.floor(h);
|
||||
float p = brightness * (1F - saturation);
|
||||
float q = brightness * (1F - saturation * f);
|
||||
float t = brightness * (1F - (saturation * (1F - f)));
|
||||
switch ((int)h) {
|
||||
case 0: return rgb(brightness, t, p);
|
||||
case 1: return rgb(q, brightness, p);
|
||||
case 2: return rgb(p, brightness, t);
|
||||
case 3: return rgb(p, q, brightness);
|
||||
case 4: return rgb(t, p, brightness);
|
||||
case 5: return rgb(brightness, p, q);
|
||||
default: return BLACK;
|
||||
}
|
||||
}
|
||||
float q = brightness * (1F - saturation * f);
|
||||
float t = brightness * (1F - (saturation * (1F - f)));
|
||||
switch((int)h) {
|
||||
case 0: return rgb(brightness, t, p);
|
||||
case 1: return rgb(q, brightness, p);
|
||||
case 2: return rgb(p, brightness, t);
|
||||
case 3: return rgb(p, q, brightness);
|
||||
case 4: return rgb(t, p, brightness);
|
||||
case 5: return rgb(brightness, p, q);
|
||||
default: return BLACK;
|
||||
}
|
||||
}
|
||||
|
||||
public static float[] toHue(int rgba)
|
||||
{
|
||||
public static float[] toHue(int rgba) {
|
||||
int r = getR(rgba);
|
||||
int g = getG(rgba);
|
||||
int b = getB(rgba);
|
||||
int cmax = (r > g) ? r : g;
|
||||
if (b > cmax) cmax = b;
|
||||
int cmin = (r < g) ? r : g;
|
||||
if (b < cmin) cmin = b;
|
||||
float length = cmax - cmin;
|
||||
|
||||
int cmax = (r > g) ? r : g;
|
||||
if(b > cmax) cmax = b;
|
||||
int cmin = (r < g) ? r : g;
|
||||
if(b < cmin) cmin = b;
|
||||
float length = cmax - cmin;
|
||||
|
||||
float[] result = new float[3];
|
||||
result[1] = cmax == 0 ? 0F : length / cmax;
|
||||
result[2] = cmax * DEVIDER;
|
||||
float hue = 0F;
|
||||
if(result[1] != 0F) {
|
||||
float redc = (cmax - r) / length;
|
||||
float greenc = (cmax - g) / length;
|
||||
float bluec = (cmax - b) / length;
|
||||
if (r == cmax) hue = bluec - greenc;
|
||||
else if (g == cmax) hue = 2F + redc - bluec;
|
||||
else hue = 4F + greenc - redc;
|
||||
hue /= 6F;
|
||||
if (hue < 0) hue += 1F;
|
||||
}
|
||||
result[0] = hue;
|
||||
return result;
|
||||
float hue = 0F;
|
||||
if(result[1] != 0F) {
|
||||
float redc = (cmax - r) / length;
|
||||
float greenc = (cmax - g) / length;
|
||||
float bluec = (cmax - b) / length;
|
||||
if(r == cmax) hue = bluec - greenc;
|
||||
else if(g == cmax) hue = 2F + redc - bluec;
|
||||
else hue = 4F + greenc - redc;
|
||||
hue /= 6F;
|
||||
if(hue < 0) hue += 1F;
|
||||
}
|
||||
result[0] = hue;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int rgb(int rgb)
|
||||
{
|
||||
return rgb | (255 << 24);
|
||||
}
|
||||
|
||||
public static int rgb(int r, int g, int b)
|
||||
{
|
||||
return A | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
|
||||
}
|
||||
|
||||
public static int rgb(float r, float g, float b)
|
||||
{
|
||||
return rgb((int)(r * 255F + 0.5F), (int)(g * 255F + 0.5F), (int)(b * 255F + 0.5F));
|
||||
}
|
||||
|
||||
public static int rgb(int r, int g, int b, int a)
|
||||
{
|
||||
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
|
||||
}
|
||||
|
||||
public static int rgb(float r, float g, float b, float a)
|
||||
{
|
||||
return rgb((int)(r * 255F + 0.5F), (int)(g * 255F + 0.5F), (int)(b * 255F + 0.5F), (int)(b * 255F + 0.5F));
|
||||
}
|
||||
|
||||
public static int setR(int rgba, int r)
|
||||
{
|
||||
return rgba & ~R | ((r & 0xFF) << 16);
|
||||
}
|
||||
|
||||
public static int setR(int rgba, float r)
|
||||
{
|
||||
return rgba & ~R | (((int)(r * 255F + 0.5F)) << 16);
|
||||
}
|
||||
|
||||
public static int setG(int rgba, int g)
|
||||
{
|
||||
return rgba & ~G | ((g & 0xFF) << 8);
|
||||
}
|
||||
|
||||
public static int setG(int rgba, float g)
|
||||
{
|
||||
return rgba & ~G | (((int)(g * 255F + 0.5F)) << 8);
|
||||
}
|
||||
|
||||
public static int setB(int rgba, int b)
|
||||
{
|
||||
return rgba & ~B | (b & 0xFF);
|
||||
}
|
||||
|
||||
public static int setB(int rgba, float b)
|
||||
{
|
||||
return rgba & ~B | ((int)(b * 255F + 0.5F));
|
||||
}
|
||||
|
||||
public static int setA(int rgba, int a)
|
||||
{
|
||||
return rgba & ~A | ((a & 0xFF) << 24);
|
||||
}
|
||||
|
||||
public static int setA(int rgba, float a)
|
||||
{
|
||||
return rgba & ~A | (((int)(a * 255F + 0.5F)) << 24);
|
||||
}
|
||||
|
||||
public static int getR(int rgba)
|
||||
{
|
||||
return (rgba >> 16) & 0xFF;
|
||||
}
|
||||
|
||||
public static float getRF(int rgba)
|
||||
{
|
||||
return ((rgba >> 16) & 0xFF) * DEVIDER;
|
||||
}
|
||||
|
||||
public static int getG(int rgba)
|
||||
{
|
||||
return (rgba >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
public static float getGF(int rgba)
|
||||
{
|
||||
return ((rgba >> 8) & 0xFF) * DEVIDER;
|
||||
}
|
||||
|
||||
public static int getB(int rgba)
|
||||
{
|
||||
return rgba & 0xFF;
|
||||
}
|
||||
|
||||
public static float getBF(int rgba)
|
||||
{
|
||||
return (rgba & 0xFF) * DEVIDER;
|
||||
}
|
||||
|
||||
public static int getA(int rgba)
|
||||
{
|
||||
return (rgba >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
public static float getAF(int rgba)
|
||||
{
|
||||
return ((rgba >> 24) & 0xFF) * DEVIDER;
|
||||
}
|
||||
|
||||
public static String getHexCode(int rgba, boolean alpha)
|
||||
{
|
||||
return "0x"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1);
|
||||
}
|
||||
|
||||
public static String getHTMLCode(int rgba, boolean alpha)
|
||||
{
|
||||
return "#"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1);
|
||||
}
|
||||
public static int rgb(int rgb) { return rgb | (255 << 24); }
|
||||
public static int rgb(int r, int g, int b) { return A | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF); }
|
||||
public static int rgb(float r, float g, float b) { return rgb((int)(r * 255F + 0.5F), (int)(g * 255F + 0.5F), (int)(b * 255F + 0.5F)); }
|
||||
public static int rgb(int r, int g, int b, int a) { return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF); }
|
||||
public static int rgb(float r, float g, float b, float a) { return rgb((int)(r * 255F + 0.5F), (int)(g * 255F + 0.5F), (int)(b * 255F + 0.5F), (int)(b * 255F + 0.5F)); }
|
||||
public static int setR(int rgba, int r) { return rgba & ~R | ((r & 0xFF) << 16); }
|
||||
public static int setR(int rgba, float r) { return rgba & ~R | (((int)(r * 255F + 0.5F)) << 16); }
|
||||
public static int setG(int rgba, int g) { return rgba & ~G | ((g & 0xFF) << 8); }
|
||||
public static int setG(int rgba, float g) { return rgba & ~G | (((int)(g * 255F + 0.5F)) << 8); }
|
||||
public static int setB(int rgba, int b) { return rgba & ~B | (b & 0xFF); }
|
||||
public static int setB(int rgba, float b) { return rgba & ~B | ((int)(b * 255F + 0.5F)); }
|
||||
public static int setA(int rgba, int a) { return rgba & ~A | ((a & 0xFF) << 24); }
|
||||
public static int setA(int rgba, float a) { return rgba & ~A | (((int)(a * 255F + 0.5F)) << 24); }
|
||||
public static int getR(int rgba) { return (rgba >> 16) & 0xFF; }
|
||||
public static float getRF(int rgba) { return ((rgba >> 16) & 0xFF) * DEVIDER; }
|
||||
public static int getG(int rgba) { return (rgba >> 8) & 0xFF; }
|
||||
public static float getGF(int rgba) { return ((rgba >> 8) & 0xFF) * DEVIDER; }
|
||||
public static int getB(int rgba) { return rgba & 0xFF; }
|
||||
public static float getBF(int rgba) { return (rgba & 0xFF) * DEVIDER; }
|
||||
public static int getA(int rgba) { return (rgba >> 24) & 0xFF; }
|
||||
public static float getAF(int rgba) { return ((rgba >> 24) & 0xFF) * DEVIDER; }
|
||||
public static String toHex(int rgba, boolean alpha) { return "0x"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1); }
|
||||
public static String toHTML(int rgba, boolean alpha) { return "#"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1); }
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import java.util.function.Predicate;
|
||||
|
||||
import speiger.src.coreengine.math.vector.ints.Vec2i;
|
||||
|
||||
public enum Facing
|
||||
{
|
||||
public enum Facing {
|
||||
NORTH(0, 2, "North", Axis.VERTICAL, Vec2i.of(0, 1)),
|
||||
EAST(1, 3, "East", Axis.HORIZONTAL, Vec2i.of(1, 0)),
|
||||
SOUTH(2, 0, "South", Axis.VERTICAL, Vec2i.of(0, -1)),
|
||||
@@ -13,7 +12,6 @@ public enum Facing
|
||||
|
||||
private static final Facing[] VALUES;
|
||||
private static final Facing[] ROTATIONS;
|
||||
|
||||
final int index;
|
||||
final int rotationIndex;
|
||||
final String name;
|
||||
@@ -22,8 +20,7 @@ public enum Facing
|
||||
final boolean positive;
|
||||
final Rotation rotation;
|
||||
|
||||
private Facing(int direction, int rotation, String display, Axis axis, Vec2i offset)
|
||||
{
|
||||
private Facing(int direction, int rotation, String display, Axis axis, Vec2i offset) {
|
||||
index = direction;
|
||||
rotationIndex = rotation;
|
||||
name = display;
|
||||
@@ -33,123 +30,50 @@ public enum Facing
|
||||
this.rotation = Rotation.fromFacing(this);
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
public int getIndex() { return index; }
|
||||
public boolean isPositive() { return positive; }
|
||||
|
||||
public boolean isXAxis()
|
||||
{
|
||||
return axis == Axis.HORIZONTAL;
|
||||
}
|
||||
public boolean isXAxis() { return axis == Axis.HORIZONTAL; }
|
||||
public boolean isZAxis() { return axis == Axis.VERTICAL; }
|
||||
public Axis getAxis() { return axis; }
|
||||
|
||||
public boolean isZAxis()
|
||||
{
|
||||
return axis == Axis.VERTICAL;
|
||||
}
|
||||
|
||||
public Axis getAxis()
|
||||
{
|
||||
return axis;
|
||||
}
|
||||
public Vec2i getOffset() { return offset; }
|
||||
public float getMultiplier() { return positive ? 1F : -1F; }
|
||||
|
||||
public boolean isPositive()
|
||||
{
|
||||
return positive;
|
||||
}
|
||||
|
||||
public Vec2i getOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
public String getName() { return name; }
|
||||
|
||||
public float getMultiplier()
|
||||
{
|
||||
return positive ? 1F : -1F;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getRotationIndex()
|
||||
{
|
||||
return rotationIndex;
|
||||
}
|
||||
|
||||
public int getRotation()
|
||||
{
|
||||
return rotationIndex * 90;
|
||||
}
|
||||
|
||||
public int getRotation(Facing other)
|
||||
{
|
||||
public int getRotationIndex() { return rotationIndex; }
|
||||
public int getRotation() { return rotationIndex * 90; }
|
||||
public int getRotation(Facing other) {
|
||||
if(other == backwards()) return getRotation() - 45;
|
||||
else if(other == forward()) return getRotation() + 45;
|
||||
return getRotation();
|
||||
}
|
||||
|
||||
public Rotation toRotation()
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public Facing rotate(int amount)
|
||||
{
|
||||
return byIndex(index + amount);
|
||||
}
|
||||
|
||||
public Facing forward()
|
||||
{
|
||||
return byIndex(index + 1);
|
||||
}
|
||||
|
||||
public Facing backwards()
|
||||
{
|
||||
return byIndex(index - 1);
|
||||
}
|
||||
|
||||
public Facing opposite()
|
||||
{
|
||||
return byIndex(index + 2);
|
||||
}
|
||||
|
||||
public Rotation toRotation() { return rotation; }
|
||||
public Facing rotate(int amount) { return byIndex(index + amount); }
|
||||
public Facing forward() { return byIndex(index + 1); }
|
||||
public Facing backwards() { return byIndex(index - 1); }
|
||||
public Facing opposite() { return byIndex(index + 2); }
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getName()+": "+offset;
|
||||
}
|
||||
public String toString() { return getName()+": "+offset; }
|
||||
|
||||
public static Facing byIndex(int index)
|
||||
{
|
||||
return VALUES[index & 3];
|
||||
}
|
||||
public static Facing byIndex(int index) { return VALUES[index & 3]; }
|
||||
public static Facing byRotationIndex(int index) { return ROTATIONS[index & 3]; }
|
||||
public static Facing byYaw(float value) { return byRotationIndex((int)(value / 90) & 3); }
|
||||
|
||||
public static Facing byRotationIndex(int index)
|
||||
{
|
||||
return ROTATIONS[index & 3];
|
||||
}
|
||||
|
||||
public static Facing byYaw(float value)
|
||||
{
|
||||
return byRotationIndex((int)(value / 90) & 3);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
Facing[] values = values();
|
||||
VALUES = new Facing[values.length];
|
||||
ROTATIONS = new Facing[values.length];
|
||||
for(Facing entry : values)
|
||||
{
|
||||
for(Facing entry : values) {
|
||||
VALUES[entry.getIndex()] = entry;
|
||||
ROTATIONS[entry.getRotationIndex()] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Rotation
|
||||
{
|
||||
public static enum Rotation {
|
||||
NONE(Facing.NORTH),
|
||||
CLOCKWISE(Facing.EAST),
|
||||
OPPOSITE(Facing.SOUTH),
|
||||
@@ -158,44 +82,27 @@ public enum Facing
|
||||
static final Rotation[] ROTATION = Rotation.values();
|
||||
Facing facing;
|
||||
|
||||
private Rotation(Facing facing)
|
||||
{
|
||||
private Rotation(Facing facing) {
|
||||
this.facing = facing;
|
||||
}
|
||||
|
||||
public static Rotation fromFacing(Facing facing)
|
||||
{
|
||||
return ROTATION[facing.getIndex()];
|
||||
}
|
||||
|
||||
public Facing toFacing()
|
||||
{
|
||||
return facing;
|
||||
}
|
||||
public static Rotation fromFacing(Facing facing) { return ROTATION[facing.getIndex()]; }
|
||||
public Facing toFacing() { return facing; }
|
||||
}
|
||||
|
||||
public static enum Axis implements Predicate<Facing>
|
||||
{
|
||||
public static enum Axis implements Predicate<Facing> {
|
||||
HORIZONTAL(5),
|
||||
VERTICAL(10);
|
||||
|
||||
int code;
|
||||
|
||||
private Axis(int code)
|
||||
{
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
private Axis(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
public int getCode() { return code; }
|
||||
|
||||
@Override
|
||||
public boolean test(Facing t)
|
||||
{
|
||||
return t.getAxis() == this;
|
||||
}
|
||||
public boolean test(Facing t) { return t.getAxis() == this; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,24 +12,20 @@ import speiger.src.coreengine.math.MathUtils;
|
||||
import speiger.src.coreengine.math.misc.Facing.Axis;
|
||||
import speiger.src.coreengine.math.vector.ints.Vec2i;
|
||||
|
||||
public final class FacingList implements Iterable<Facing>, Predicate<Facing>
|
||||
{
|
||||
public final class FacingList implements Iterable<Facing>, Predicate<Facing> {
|
||||
static final FacingList[] FACINGS = createArray();
|
||||
public static final FacingList EMPTY = ofNumber(0);
|
||||
public static final FacingList NORTH = ofFacings(Facing.NORTH);
|
||||
public static final FacingList EAST = ofFacings(Facing.EAST);
|
||||
public static final FacingList SOUTH = ofFacings(Facing.SOUTH);
|
||||
public static final FacingList WEST = ofFacings(Facing.WEST);
|
||||
|
||||
public static final FacingList NORTH_EAST = ofFacings(Facing.NORTH, Facing.EAST);
|
||||
public static final FacingList SOUTH_EAST = ofFacings(Facing.EAST, Facing.SOUTH);
|
||||
public static final FacingList SOUTH_WEST = ofFacings(Facing.SOUTH, Facing.WEST);
|
||||
public static final FacingList NORTH_WEST = ofFacings(Facing.WEST, Facing.NORTH);
|
||||
|
||||
public static final FacingList VERTICAL = ofFacings(Facing.NORTH, Facing.SOUTH);
|
||||
public static final FacingList HORIZONTAL = ofFacings(Facing.EAST, Facing.WEST);
|
||||
public static final FacingList ALL = ofFacings(Facing.NORTH, Facing.SOUTH, Facing.EAST, Facing.WEST);
|
||||
|
||||
final byte code;
|
||||
final byte next;
|
||||
final byte opposite;
|
||||
@@ -38,22 +34,18 @@ public final class FacingList implements Iterable<Facing>, Predicate<Facing>
|
||||
final Vec2i offset;
|
||||
final Facing[] array;
|
||||
|
||||
private FacingList(int initCode)
|
||||
{
|
||||
private FacingList(int initCode) {
|
||||
code = (byte)MathUtils.clamp(0, 15, initCode);
|
||||
Vec2i pos = Vec2i.mutable();
|
||||
ObjectList<Facing> facings = new ObjectArrayList<>();
|
||||
for(int i = 0;i<4;i++)
|
||||
{
|
||||
if((code & 1 << i) != 0)
|
||||
{
|
||||
for(int i = 0;i < 4;i++) {
|
||||
if((code & 1 << i) != 0) {
|
||||
pos.add(Facing.byIndex(i).getOffset());
|
||||
facings.add(Facing.byIndex(i));
|
||||
}
|
||||
}
|
||||
int[] data = new int[3];
|
||||
for(int i = 0,m=facings.size();i<m;i++)
|
||||
{
|
||||
for(int i = 0,m = facings.size();i < m;i++) {
|
||||
Facing face = facings.get(i);
|
||||
data[0] |= 1 << face.forward().getIndex();
|
||||
data[1] |= 1 << face.opposite().getIndex();
|
||||
@@ -67,68 +59,31 @@ public final class FacingList implements Iterable<Facing>, Predicate<Facing>
|
||||
array = facings.toArray(new Facing[facings.size()]);
|
||||
}
|
||||
|
||||
public static FacingList ofFacing(Facing facing)
|
||||
{
|
||||
return FACINGS[1 << facing.getIndex()];
|
||||
}
|
||||
public static FacingList ofFacing(Facing facing) { return FACINGS[1 << facing.getIndex()]; }
|
||||
public static FacingList ofFacings(Facing... facings) { return FACINGS[toNumber(facings)]; }
|
||||
public static FacingList ofFlags(boolean[] facings) { return FACINGS[toNumber(facings)]; }
|
||||
public static FacingList ofNumber(int value) { return FACINGS[value & 15]; }
|
||||
public static FacingList ofAxis(Axis axis) { return FACINGS[axis.getCode()]; }
|
||||
|
||||
public static FacingList ofFacings(Facing... facings)
|
||||
{
|
||||
return FACINGS[toNumber(facings)];
|
||||
}
|
||||
|
||||
public static FacingList ofFlags(boolean[] facings)
|
||||
{
|
||||
return FACINGS[toNumber(facings)];
|
||||
}
|
||||
|
||||
public static FacingList ofNumber(int value)
|
||||
{
|
||||
return FACINGS[value & 15];
|
||||
}
|
||||
|
||||
public static FacingList ofAxis(Axis axis)
|
||||
{
|
||||
return FACINGS[axis.getCode()];
|
||||
}
|
||||
|
||||
public static FacingList fromVec(Vec2i value)
|
||||
{
|
||||
public static FacingList fromVec(Vec2i value) {
|
||||
value = value.clamp(-1, 1);
|
||||
for(int i = 0;i<16;i++)
|
||||
{
|
||||
if(FACINGS[i].getOffset().equals(value))
|
||||
{
|
||||
return FACINGS[i];
|
||||
}
|
||||
}
|
||||
for(int i = 0;i < 16;i++) { if(FACINGS[i].getOffset().equals(value)) { return FACINGS[i]; } }
|
||||
return FACINGS[0];
|
||||
}
|
||||
|
||||
public Set<Facing> toFacings()
|
||||
{
|
||||
return isEmpty() ? EnumSet.noneOf(Facing.class) : EnumSet.copyOf(ObjectArrayList.wrap(array));
|
||||
}
|
||||
public Set<Facing> toFacings() { return isEmpty() ? EnumSet.noneOf(Facing.class) : EnumSet.copyOf(ObjectArrayList.wrap(array)); }
|
||||
public boolean[] toFlags() { return toFlags(array); }
|
||||
|
||||
public boolean[] toFlags()
|
||||
{
|
||||
return toFlags(array);
|
||||
}
|
||||
|
||||
public int getRotation()
|
||||
{
|
||||
switch(count)
|
||||
{
|
||||
public int getRotation() {
|
||||
switch(count) {
|
||||
case 1: return array[0].getRotation();
|
||||
case 2: return array[0].getRotation(array[1]);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public FacingList rotate(int amount)
|
||||
{
|
||||
switch(amount & 3)
|
||||
{
|
||||
public FacingList rotate(int amount) {
|
||||
switch(amount & 3) {
|
||||
case 1: return FACINGS[next];
|
||||
case 2: return FACINGS[opposite];
|
||||
case 3: return FACINGS[prev];
|
||||
@@ -136,177 +91,70 @@ public final class FacingList implements Iterable<Facing>, Predicate<Facing>
|
||||
}
|
||||
}
|
||||
|
||||
public FacingList invert()
|
||||
{
|
||||
return FACINGS[15 - code];
|
||||
}
|
||||
|
||||
public FacingList opposite()
|
||||
{
|
||||
return FACINGS[opposite];
|
||||
}
|
||||
|
||||
public FacingList add(Facing facing)
|
||||
{
|
||||
return FACINGS[code | (1 << facing.getIndex())];
|
||||
}
|
||||
|
||||
public FacingList add(FacingList facings)
|
||||
{
|
||||
return FACINGS[code | facings.code];
|
||||
}
|
||||
|
||||
public FacingList remove(Facing facing)
|
||||
{
|
||||
return FACINGS[code & ~(1 << facing.getIndex())];
|
||||
}
|
||||
|
||||
public FacingList remove(FacingList facings)
|
||||
{
|
||||
return FACINGS[code & ~facings.code];
|
||||
}
|
||||
|
||||
public boolean contains(Facing direction)
|
||||
{
|
||||
return (code & 1 << direction.getIndex()) != 0;
|
||||
}
|
||||
|
||||
public boolean contains(FacingList facings)
|
||||
{
|
||||
return (code & facings.code) == facings.code;
|
||||
}
|
||||
|
||||
public boolean containsAny(FacingList facings)
|
||||
{
|
||||
return (code & facings.code) != 0;
|
||||
}
|
||||
|
||||
public boolean notContains(Facing direction)
|
||||
{
|
||||
return (code & 1 << direction.getIndex()) == 0;
|
||||
}
|
||||
|
||||
public boolean notContains(FacingList facings)
|
||||
{
|
||||
return (code & facings.code) != facings.code;
|
||||
}
|
||||
|
||||
public FacingList flipFacing(Facing facing)
|
||||
{
|
||||
return contains(facing) ? remove(facing).add(facing.opposite()) : this;
|
||||
}
|
||||
|
||||
public FacingList flipAxis(Axis axis)
|
||||
{
|
||||
public FacingList invert() { return FACINGS[15 - code]; }
|
||||
public FacingList opposite() { return FACINGS[opposite]; }
|
||||
public FacingList add(Facing facing) { return FACINGS[code | (1 << facing.getIndex())]; }
|
||||
public FacingList add(FacingList facings) { return FACINGS[code | facings.code]; }
|
||||
public FacingList remove(Facing facing) { return FACINGS[code & ~(1 << facing.getIndex())]; }
|
||||
public FacingList remove(FacingList facings) { return FACINGS[code & ~facings.code]; }
|
||||
public boolean contains(Facing direction) { return (code & 1 << direction.getIndex()) != 0; }
|
||||
public boolean contains(FacingList facings) { return (code & facings.code) == facings.code; }
|
||||
public boolean containsAny(FacingList facings) { return (code & facings.code) != 0; }
|
||||
public boolean notContains(Facing direction) { return (code & 1 << direction.getIndex()) == 0; }
|
||||
public boolean notContains(FacingList facings) { return (code & facings.code) != facings.code; }
|
||||
public FacingList flipFacing(Facing facing) { return contains(facing) ? remove(facing).add(facing.opposite()) : this; }
|
||||
public FacingList flipAxis(Axis axis) {
|
||||
FacingList result = this;
|
||||
for(int i = 0,m=array.length;i<m;i++)
|
||||
{
|
||||
if(array[i].getAxis() == axis)
|
||||
{
|
||||
result = result.remove(array[i]).add(array[i].opposite());
|
||||
}
|
||||
}
|
||||
for(int i = 0,m = array.length;i < m;i++) { if(array[i].getAxis() == axis) { result = result.remove(array[i]).add(array[i].opposite()); } }
|
||||
return result;
|
||||
}
|
||||
|
||||
public Vec2i getOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
public Facing getFacing(int index)
|
||||
{
|
||||
return array[index];
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return code == 0;
|
||||
}
|
||||
|
||||
public boolean isFull()
|
||||
{
|
||||
return code == 15;
|
||||
}
|
||||
public Vec2i getOffset() { return offset; }
|
||||
public Facing getFacing(int index) { return array[index]; }
|
||||
public int getCode() { return code; }
|
||||
public int size() { return count; }
|
||||
public boolean isEmpty() { return code == 0; }
|
||||
public boolean isFull() { return code == 15; }
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
StringJoiner joiner = new StringJoiner(",", "[", "]");
|
||||
for(int i = 0,m=array.length;i<m;i++)
|
||||
{
|
||||
joiner.add(array[i].getName());
|
||||
}
|
||||
for(int i = 0,m = array.length;i < m;i++) { joiner.add(array[i].getName()); }
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Facing t)
|
||||
{
|
||||
return (code & 1 << t.getIndex()) != 0;
|
||||
}
|
||||
public boolean test(Facing t) { return (code & 1 << t.getIndex()) != 0; }
|
||||
|
||||
@Override
|
||||
public Iterator<Facing> iterator()
|
||||
{
|
||||
return new Iterator<Facing>(){
|
||||
public Iterator<Facing> iterator() {
|
||||
return new Iterator<Facing>() {
|
||||
int index = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return index < size();
|
||||
}
|
||||
|
||||
public boolean hasNext() { return index < size(); }
|
||||
@Override
|
||||
public Facing next()
|
||||
{
|
||||
return array[index++];
|
||||
}
|
||||
public Facing next() { return array[index++]; }
|
||||
};
|
||||
}
|
||||
|
||||
public static int toNumber(Facing...facings)
|
||||
{
|
||||
public static int toNumber(Facing... facings) {
|
||||
int value = 0;
|
||||
for(int i = 0,m=facings.length;i<m;i++)
|
||||
{
|
||||
value |= (1 << facings[i].getIndex());
|
||||
}
|
||||
for(int i = 0,m = facings.length;i < m;i++) { value |= (1 << facings[i].getIndex()); }
|
||||
return value & 15;
|
||||
}
|
||||
|
||||
public static int toNumber(boolean[] facings)
|
||||
{
|
||||
return (facings[0] ? 1 : 0) << 0 | (facings[1] ? 1 : 0) << 1 | (facings[2] ? 1 : 0) << 2 | (facings[3] ? 1 : 0) << 3;
|
||||
}
|
||||
public static int toNumber(boolean[] facings) { return (facings[0] ? 1 : 0) << 0 | (facings[1] ? 1 : 0) << 1 | (facings[2] ? 1 : 0) << 2 | (facings[3] ? 1 : 0) << 3; }
|
||||
|
||||
public static boolean[] toFlags(Facing...facings)
|
||||
{
|
||||
public static boolean[] toFlags(Facing... facings) {
|
||||
boolean[] array = new boolean[4];
|
||||
for(int i = 0,m=facings.length;i<m;i++)
|
||||
{
|
||||
array[facings[i].getIndex()] = true;
|
||||
}
|
||||
for(int i = 0,m = facings.length;i < m;i++) { array[facings[i].getIndex()] = true; }
|
||||
return array;
|
||||
}
|
||||
|
||||
private static FacingList[] createArray()
|
||||
{
|
||||
private static FacingList[] createArray() {
|
||||
FacingList[] facings = new FacingList[16];
|
||||
for(int i = 0;i<16;i++)
|
||||
{
|
||||
facings[i] = new FacingList(i);
|
||||
}
|
||||
for(int i = 0;i < 16;i++) { facings[i] = new FacingList(i); }
|
||||
return facings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,25 @@ public class SmoothFloat
|
||||
protected float target;
|
||||
protected float agility;
|
||||
|
||||
public SmoothFloat(float agility)
|
||||
{
|
||||
public SmoothFloat(float agility) {
|
||||
this.agility = agility;
|
||||
}
|
||||
|
||||
public SmoothFloat(float value, float agility)
|
||||
{
|
||||
public SmoothFloat(float value, float agility) {
|
||||
this.value = value;
|
||||
target = value;
|
||||
this.agility = agility;
|
||||
}
|
||||
|
||||
public boolean isDone(){return Math.abs(target - value) <= 0.5F;}
|
||||
public void update(float delta){value += (target - value) * agility * delta;}
|
||||
public boolean isDone() { return isDone(0.0005F); }
|
||||
public boolean isDone(float limit) { return Math.abs(target - value) <= limit; }
|
||||
public void update(float delta) { value += (target - value) * agility * delta; }
|
||||
|
||||
public void setTarget(float value){target = value;}
|
||||
public void addTarget(float value){target += value;}
|
||||
public void setTarget(float value) { target = value; }
|
||||
public void addTarget(float value) { target += value; }
|
||||
|
||||
public void forceFinish(){value = target;}
|
||||
public void forceFinish() { value = target; }
|
||||
|
||||
public float getValue(){return value;}
|
||||
public float getTarget(){return target;}
|
||||
public float getValue() { return value; }
|
||||
public float getTarget() { return target; }
|
||||
}
|
||||
|
||||
@@ -9,36 +9,28 @@ public class SmoothVec3f
|
||||
Vec3f helper = Vec3f.mutable();
|
||||
float agility = 0F;
|
||||
|
||||
public SmoothVec3f(float agility)
|
||||
{
|
||||
public SmoothVec3f(float agility) {
|
||||
this.agility = agility;
|
||||
}
|
||||
|
||||
public SmoothVec3f(Vec3f vec, float agility)
|
||||
{
|
||||
public SmoothVec3f(Vec3f vec, float agility) {
|
||||
value.set(vec);
|
||||
target.set(vec);
|
||||
this.agility = agility;
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return target.distanceToSquared(value) <= 0.005F;
|
||||
}
|
||||
public boolean isDone() { return isDone(0.0005F); }
|
||||
public boolean isDone(float limit) { return target.distanceToSquared(value) <= limit; }
|
||||
public void update(float delta) { value.add(target.difference(value, helper).multiply(agility * delta)); }
|
||||
|
||||
public void update(float delta)
|
||||
{
|
||||
value.add(target.difference(value, helper).multiply(agility * delta));
|
||||
}
|
||||
public void setTarget(Vec3f value) { target.set(value); }
|
||||
public void setTarget(float x, float y, float z) { target.set(x, y, z); }
|
||||
|
||||
public void setTarget(Vec3f value){setTarget(value.getX(), value.getY(), value.getZ());}
|
||||
public void setTarget(float x, float y, float z) {target.set(x, y, z);}
|
||||
public void addTarget(Vec3f value) { target.add(value); }
|
||||
public void addTarget(float x, float y, float z) { target.add(x, y, z); }
|
||||
|
||||
public void addTarget(Vec3f value){addTarget(value.getX(), value.getY(), value.getZ());}
|
||||
public void addTarget(float x, float y, float z) {target.add(x, y, z);}
|
||||
public Vec3f getTarget() { return target.copy(); }
|
||||
public Vec3f getValue() { return value.copy();}
|
||||
|
||||
public Vec3f getTarget(){return target.copy();}
|
||||
public Vec3f getValue(){return value.copy();}
|
||||
|
||||
public void forceFinish(){value.set(target);}
|
||||
public void forceFinish() { value.set(target); }
|
||||
}
|
||||
|
||||
@@ -1,29 +1,19 @@
|
||||
package speiger.src.coreengine.math.value;
|
||||
|
||||
public class ConstantValue extends Value
|
||||
{
|
||||
public class ConstantValue extends Value {
|
||||
public static final IValue MINUS_ONE = new ConstantValue(-1F);
|
||||
public static final IValue ZERO = new ConstantValue(0F);
|
||||
public static final IValue ONE = new ConstantValue(1F);
|
||||
|
||||
final float value;
|
||||
|
||||
public ConstantValue(float value)
|
||||
{
|
||||
public ConstantValue(float value) {
|
||||
super(0F, 0F);
|
||||
this.value = value;
|
||||
update(-1F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateProgress(float time)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
protected float calculateProgress(float time) { return value; }
|
||||
@Override
|
||||
protected void onInitialValueSet()
|
||||
{
|
||||
finishProgress();
|
||||
}
|
||||
protected void onInitialValueSet() { finishProgress(); }
|
||||
}
|
||||
|
||||
@@ -2,21 +2,18 @@ package speiger.src.coreengine.math.value;
|
||||
|
||||
import speiger.src.coreengine.math.MathUtils;
|
||||
|
||||
public class CubicValue extends Value
|
||||
{
|
||||
public class CubicValue extends Value {
|
||||
final float startValue;
|
||||
final float startHelperValue;
|
||||
final float endHelperValue;
|
||||
final float endValue;
|
||||
boolean smooth = false;
|
||||
|
||||
public CubicValue(float duration, float startValue, float startHelper, float endHelper, float endValue)
|
||||
{
|
||||
this(0F, duration, startValue, startHelper, endHelper, endValue);
|
||||
public CubicValue(float duration, float startValue, float startHelper, float endHelper, float endValue) {
|
||||
this(0F, duration, startValue, startHelper, endHelper, endValue);
|
||||
}
|
||||
|
||||
public CubicValue(float start, float duration, float startValue, float startHelper, float endHelper, float endValue)
|
||||
{
|
||||
public CubicValue(float start, float duration, float startValue, float startHelper, float endHelper, float endValue) {
|
||||
super(start, duration);
|
||||
this.startValue = startValue;
|
||||
startHelperValue = startHelper;
|
||||
@@ -24,23 +21,19 @@ public class CubicValue extends Value
|
||||
this.endValue = endValue;
|
||||
}
|
||||
|
||||
public CubicValue setSmooth()
|
||||
{
|
||||
public CubicValue setSmooth() {
|
||||
smooth = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CubicValue setSmooth(boolean smooth)
|
||||
{
|
||||
public CubicValue setSmooth(boolean smooth) {
|
||||
this.smooth = smooth;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateProgress(float time)
|
||||
{
|
||||
if(smooth)
|
||||
{
|
||||
protected float calculateProgress(float time) {
|
||||
if(smooth) {
|
||||
float first = MathUtils.smoothQuadraticCurve(startValue, startHelperValue, endHelperValue, time);
|
||||
float second = MathUtils.smoothQuadraticCurve(startHelperValue, endHelperValue, endValue, time);
|
||||
return MathUtils.smoothLerp(first, second, time);
|
||||
@@ -51,9 +44,5 @@ public class CubicValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinished()
|
||||
{
|
||||
finishProgress();
|
||||
}
|
||||
|
||||
protected void onFinished() { finishProgress(); }
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package speiger.src.coreengine.math.value;
|
||||
|
||||
public interface IValue
|
||||
{
|
||||
public interface IValue {
|
||||
public float get();
|
||||
|
||||
public default float get(float min, float max)
|
||||
{
|
||||
return min + ((max - min) * get());
|
||||
}
|
||||
|
||||
public default float get(float min, float max) { return min + ((max - min) * get()); }
|
||||
public float update(float particalTicks);
|
||||
|
||||
public boolean isDone();
|
||||
}
|
||||
|
||||
@@ -2,45 +2,33 @@ package speiger.src.coreengine.math.value;
|
||||
|
||||
import speiger.src.coreengine.math.MathUtils;
|
||||
|
||||
public class LiniarValue extends Value
|
||||
{
|
||||
public class LiniarValue extends Value {
|
||||
final float startValue;
|
||||
final float endValue;
|
||||
boolean smooth = false;
|
||||
|
||||
public LiniarValue(float duration, float startValue, float endValue)
|
||||
{
|
||||
this(0F, duration, startValue, endValue);
|
||||
public LiniarValue(float duration, float startValue, float endValue) {
|
||||
this(0F, duration, startValue, endValue);
|
||||
}
|
||||
|
||||
public LiniarValue(float start, float duration, float startValue, float endValue)
|
||||
{
|
||||
public LiniarValue(float start, float duration, float startValue, float endValue) {
|
||||
super(start, duration);
|
||||
this.startValue = startValue;
|
||||
this.endValue = endValue;
|
||||
}
|
||||
|
||||
public LiniarValue setSmooth()
|
||||
{
|
||||
public LiniarValue setSmooth() {
|
||||
smooth = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiniarValue setSmooth(boolean smooth)
|
||||
{
|
||||
public LiniarValue setSmooth(boolean smooth) {
|
||||
this.smooth = smooth;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateProgress(float time)
|
||||
{
|
||||
return smooth ? MathUtils.smoothLerp(startValue, endValue, time) : MathUtils.lerp(startValue, endValue, time);
|
||||
}
|
||||
|
||||
protected float calculateProgress(float time) { return smooth ? MathUtils.smoothLerp(startValue, endValue, time) : MathUtils.lerp(startValue, endValue, time); }
|
||||
@Override
|
||||
protected void onFinished()
|
||||
{
|
||||
finishProgress();
|
||||
}
|
||||
protected void onFinished() { finishProgress(); }
|
||||
}
|
||||
|
||||
@@ -2,47 +2,36 @@ package speiger.src.coreengine.math.value;
|
||||
|
||||
import speiger.src.coreengine.math.MathUtils;
|
||||
|
||||
public class QuadraticValue extends Value
|
||||
{
|
||||
public class QuadraticValue extends Value {
|
||||
final float startValue;
|
||||
final float medianValue;
|
||||
final float endValue;
|
||||
boolean smooth;
|
||||
|
||||
public QuadraticValue(float duration, float startValue, float medianValue, float endValue)
|
||||
{
|
||||
public QuadraticValue(float duration, float startValue, float medianValue, float endValue) {
|
||||
this(0F, duration, startValue, medianValue, endValue);
|
||||
}
|
||||
|
||||
public QuadraticValue(float start, float duration, float startValue, float medianValue, float endValue)
|
||||
{
|
||||
public QuadraticValue(float start, float duration, float startValue, float medianValue, float endValue) {
|
||||
super(start, duration);
|
||||
this.startValue = startValue;
|
||||
this.medianValue = medianValue;
|
||||
this.endValue = endValue;
|
||||
}
|
||||
|
||||
public QuadraticValue setSmooth()
|
||||
{
|
||||
public QuadraticValue setSmooth() {
|
||||
smooth = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QuadraticValue setSmooth(boolean smooth)
|
||||
{
|
||||
public QuadraticValue setSmooth(boolean smooth) {
|
||||
this.smooth = smooth;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateProgress(float time)
|
||||
{
|
||||
return smooth ? MathUtils.smoothQuadraticCurve(startValue, medianValue, endValue, time) : MathUtils.quadraticCurve(startValue, medianValue, endValue, time);
|
||||
}
|
||||
protected float calculateProgress(float time) { return smooth ? MathUtils.smoothQuadraticCurve(startValue, medianValue, endValue, time) : MathUtils.quadraticCurve(startValue, medianValue, endValue, time); }
|
||||
|
||||
@Override
|
||||
protected void onFinished()
|
||||
{
|
||||
finishProgress();
|
||||
}
|
||||
protected void onFinished() { finishProgress(); }
|
||||
}
|
||||
|
||||
@@ -1,78 +1,52 @@
|
||||
package speiger.src.coreengine.math.value;
|
||||
|
||||
public abstract class Value implements IValue
|
||||
{
|
||||
public abstract class Value implements IValue {
|
||||
final float start;
|
||||
final float duration;
|
||||
byte flags = 0;
|
||||
int done = 0;
|
||||
|
||||
float progress = 0F;
|
||||
float value;
|
||||
|
||||
public Value(float duration)
|
||||
{
|
||||
public Value(float duration) {
|
||||
this(0F, duration);
|
||||
}
|
||||
|
||||
public Value(float start, float duration)
|
||||
{
|
||||
public Value(float start, float duration) {
|
||||
this.duration = duration;
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float update(float particleTime)
|
||||
{
|
||||
if((flags & 2) != 0)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
public float update(float particleTime) {
|
||||
if((flags & 2) != 0) { return value; }
|
||||
progress += particleTime;
|
||||
if(progress < start)
|
||||
{
|
||||
if((flags & 1) == 0)
|
||||
{
|
||||
if(progress < start) {
|
||||
if((flags & 1) == 0) {
|
||||
value = calculateProgress(0F);
|
||||
onInitialValueSet();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
value = calculateProgress((progress - start) / duration);
|
||||
if(progress >= start + duration)
|
||||
{
|
||||
onFinished();
|
||||
}
|
||||
if(progress >= start + duration) { onFinished(); }
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float get()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public float get() { return value; }
|
||||
@Override
|
||||
public boolean isDone()
|
||||
{
|
||||
return done > 0;
|
||||
}
|
||||
|
||||
public boolean isDone() { return done > 0; }
|
||||
protected abstract float calculateProgress(float time);
|
||||
|
||||
protected void onFinished()
|
||||
{
|
||||
protected void onFinished() {
|
||||
progress = start;
|
||||
done++;
|
||||
}
|
||||
|
||||
protected void onInitialValueSet()
|
||||
{
|
||||
flags |= 1;
|
||||
}
|
||||
protected void onInitialValueSet() { flags |= 1; }
|
||||
|
||||
protected void finishProgress()
|
||||
{
|
||||
protected void finishProgress() {
|
||||
flags |= 2;
|
||||
done++;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ public class VectorUtil
|
||||
{
|
||||
public static float barryCentric(Vec3f p1, Vec3f p2, Vec3f p3, Vec2f pos)
|
||||
{
|
||||
float det = (p2.getZ() - p3.getZ()) * (p1.getX() - p3.getX()) + (p3.getX() - p2.getX()) * (p1.getZ() - p3.getZ());
|
||||
float l1 = ((p2.getZ() - p3.getZ()) * (pos.getX() - p3.getX()) + (p3.getX() - p2.getX()) * (pos.getY() - p3.getZ())) / det;
|
||||
float l2 = ((p3.getZ() - p1.getZ()) * (pos.getX() - p3.getX()) + (p1.getX() - p3.getX()) * (pos.getY() - p3.getZ())) / det;
|
||||
float det = (p2.z() - p3.z()) * (p1.x() - p3.x()) + (p3.x() - p2.x()) * (p1.z() - p3.z());
|
||||
float l1 = ((p2.z() - p3.z()) * (pos.x() - p3.x()) + (p3.x() - p2.x()) * (pos.y() - p3.z())) / det;
|
||||
float l2 = ((p3.z() - p1.z()) * (pos.x() - p3.x()) + (p1.x() - p3.x()) * (pos.y() - p3.z())) / det;
|
||||
float l3 = 1.0f - l1 - l2;
|
||||
return l1 * p1.getY() + l2 * p2.getY() + l3 * p3.getY();
|
||||
return l1 * p1.y() + l2 * p2.y() + l3 * p3.y();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,106 +17,106 @@ public interface Vec2b extends Vecb {
|
||||
public static Vec2b mutable() { return new Vec2bMutable(); }
|
||||
public static Vec2b mutable(byte value) { return new Vec2bMutable(value); }
|
||||
public static Vec2b mutable(byte x, byte y) { return new Vec2bMutable(x, y); }
|
||||
public static Vec2b mutable(Vec2b value) { return mutable(value.getX(), value.getY()); }
|
||||
public static Vec2b mutable(Vec2b value) { return mutable(value.x(), value.y()); }
|
||||
|
||||
public static Vec2b of() { return new Vec2bImmutable(); }
|
||||
public static Vec2b of(byte value) { return new Vec2bImmutable(value); }
|
||||
public static Vec2b of(byte x, byte y) { return new Vec2bImmutable(x, y); }
|
||||
public static Vec2b of(Vec2b value) { return of(value.getX(), value.getY()); }
|
||||
public static Vec2b of(Vec2b value) { return of(value.x(), value.y()); }
|
||||
|
||||
public byte getX();
|
||||
public byte getY();
|
||||
public Vec2b setX(byte x);
|
||||
public Vec2b setY(byte y);
|
||||
public byte x();
|
||||
public byte y();
|
||||
public Vec2b x(byte x);
|
||||
public Vec2b y(byte y);
|
||||
|
||||
@Override
|
||||
public default byte[] asArray() { return new byte[] {getX(), getY()}; }
|
||||
public default byte[] asArray() { return new byte[] {x(), y()}; }
|
||||
@Override
|
||||
public Vec2b copy();
|
||||
@Override
|
||||
public default Vec2b abs() { return set((byte)Math.abs(getX()), (byte)Math.abs(getY())); }
|
||||
public default Vec2b abs() { return set((byte)Math.abs(x()), (byte)Math.abs(y())); }
|
||||
@Override
|
||||
public default Vec2b negate() { return set((byte)0, (byte)0); }
|
||||
@Override
|
||||
public default Vec2b invert() { return set((byte)(-getX()), (byte)(-getY())); };
|
||||
public default Vec2b invert() { return set((byte)(-x()), (byte)(-y())); };
|
||||
@Override
|
||||
public default Vec2b add(byte value) { return add(value, value); }
|
||||
public default Vec2b add(Vec2b value) { return add(value.getX(), value.getY()); }
|
||||
public default Vec2b add(byte x, byte y) { return set((byte)(x + getX()), (byte)(y + getY())); }
|
||||
public default Vec2b add(Vec2b value) { return add(value.x(), value.y()); }
|
||||
public default Vec2b add(byte x, byte y) { return set((byte)(x + x()), (byte)(y + y())); }
|
||||
@Override
|
||||
public default Vec2b sub(byte value) { return sub(value, value); }
|
||||
public default Vec2b sub(Vec2b value) { return sub(value.getX(), value.getY()); }
|
||||
public default Vec2b sub(byte x, byte y) { return set((byte)(getX() - x), (byte)(getY() - y)); }
|
||||
public default Vec2b sub(Vec2b value) { return sub(value.x(), value.y()); }
|
||||
public default Vec2b sub(byte x, byte y) { return set((byte)(x() - x), (byte)(y() - y)); }
|
||||
@Override
|
||||
public default Vec2b multiply(byte value) { return multiply(value, value); }
|
||||
public default Vec2b multiply(Vec2b value) { return multiply(value.getX(), value.getY()); }
|
||||
public default Vec2b multiply(byte x, byte y) { return set((byte)(x * getX()), (byte)(y * getY())); }
|
||||
public default Vec2b multiply(Vec2b value) { return multiply(value.x(), value.y()); }
|
||||
public default Vec2b multiply(byte x, byte y) { return set((byte)(x * x()), (byte)(y * y())); }
|
||||
@Override
|
||||
public default Vec2b devide(byte value) { return devide(value, value); }
|
||||
public default Vec2b devide(Vec2b value) { return devide(value.getX(), value.getY()); }
|
||||
public default Vec2b devide(byte x, byte y) { return set((byte)(getX() / x), (byte)(getY() / y)); }
|
||||
public default Vec2b devide(Vec2b value) { return devide(value.x(), value.y()); }
|
||||
public default Vec2b devide(byte x, byte y) { return set((byte)(x() / x), (byte)(y() / y)); }
|
||||
@Override
|
||||
public default Vec2b set(byte value) { return set(value, value); };
|
||||
public default Vec2b set(Vec2b value) { return set(value.getX(), value.getY()); }
|
||||
public default Vec2b set(Vec2b value) { return set(value.x(), value.y()); }
|
||||
public Vec2b set(byte x, byte y);
|
||||
public default double distanceTo(Vec2b value) { return distanceTo(value.getX(), value.getY()); }
|
||||
public default double distanceTo(Vec2b value) { return distanceTo(value.x(), value.y()); }
|
||||
public default double distanceTo(byte x, byte y) { return Math.sqrt(distanceToSquared(x, y)); }
|
||||
public default long distanceToSquared(Vec2b value) { return distanceToSquared(value.getX(), value.getY()); }
|
||||
public default long distanceToSquared(Vec2b value) { return distanceToSquared(value.x(), value.y()); }
|
||||
public default long distanceToSquared(byte x, byte y) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
return (xPos * xPos) + (yPos * yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
|
||||
public default long dotProduct(Vec2b value) { return dotProduct(value.getX(), value.getY()); }
|
||||
public default long dotProduct(byte x, byte y) { return (getX() * x) + (getY() * y); }
|
||||
public default Vec2b rotate(byte angle, Vec2b center) { return rotate(angle, center.getX(), center.getY()); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()); }
|
||||
public default long dotProduct(Vec2b value) { return dotProduct(value.x(), value.y()); }
|
||||
public default long dotProduct(byte x, byte y) { return (x() * x) + (y() * y); }
|
||||
public default Vec2b rotate(byte angle, Vec2b center) { return rotate(angle, center.x(), center.y()); }
|
||||
public default Vec2b rotate(byte angle, byte x, byte y) {
|
||||
byte xPos = (byte)(getX() - x);
|
||||
byte yPos = (byte)(getY() - y);
|
||||
byte xPos = (byte)(x() - x);
|
||||
byte yPos = (byte)(y() - y);
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
return set((byte)((xPos * cos) + (yPos * sin) + x), (byte)(-(xPos * sin) + (yPos * cos) + y));
|
||||
}
|
||||
|
||||
public default Vec2b min(Vec2b other) { return min(other, this); }
|
||||
public default Vec2b min(Vec2b other, Vec2b result) { return min(other.getX(), other.getY(), result); }
|
||||
public default Vec2b min(Vec2b other, Vec2b result) { return min(other.x(), other.y(), result); }
|
||||
public default Vec2b min(byte x, byte y) { return min(x, y, this); }
|
||||
public default Vec2b min(byte x, byte y, Vec2b result) { return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y)); }
|
||||
public default Vec2b min(byte x, byte y, Vec2b result) { return result.set((byte)Math.min(x(), x), (byte)Math.min(y(), y)); }
|
||||
public default Vec2b max(Vec2b other) { return max(other, this); }
|
||||
public default Vec2b max(Vec2b other, Vec2b result) { return max(other.getX(), other.getY(), result); }
|
||||
public default Vec2b max(Vec2b other, Vec2b result) { return max(other.x(), other.y(), result); }
|
||||
public default Vec2b max(byte x, byte y) { return max(x, y, this); }
|
||||
public default Vec2b max(byte x, byte y, Vec2b result) { return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y)); }
|
||||
public default Vec2b max(byte x, byte y, Vec2b result) { return result.set((byte)Math.max(x(), x), (byte)Math.max(y(), y)); }
|
||||
public default Vec2b difference(Vec2b other) { return difference(other, this); }
|
||||
public default Vec2b difference(Vec2b other, Vec2b result) { return difference(other.getX(), other.getY(), result); }
|
||||
public default Vec2b difference(Vec2b other, Vec2b result) { return difference(other.x(), other.y(), result); }
|
||||
public default Vec2b difference(byte x, byte y) { return difference(x, y, this); }
|
||||
public default Vec2b difference(byte x, byte y, Vec2b result) { return result.set((byte)(getX() - x), (byte)(getY() - y)); }
|
||||
public default Vec2b difference(byte x, byte y, Vec2b result) { return result.set((byte)(x() - x), (byte)(y() - y)); }
|
||||
@Override
|
||||
public default Vec2b clamp(byte min, byte max) { return clamp(min, max, ALL); }
|
||||
public default Vec2b clamp(byte min, byte max, Vec2b result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec2b clamp(byte min, byte max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec2b clamp(byte min, byte max, Vec2b result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
|
||||
public default Vec2b clamp(byte min, byte max, Vec2b result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
|
||||
@Override
|
||||
public default Vec2b store(ByteBuffer buffer) {
|
||||
buffer.put(getX()).put(getY());
|
||||
buffer.put(x()).put(y());
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public default Vec2b load(ByteBuffer buffer) { return set(buffer.get(), buffer.get()); }
|
||||
|
||||
@Override
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable(getX(), getY()) : Vec2s.of(getX(), getY()); }
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable(x(), y()) : Vec2s.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(getX(), getY()) : Vec2i.of(getX(), getY()); }
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(x(), y()) : Vec2i.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY()); }
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(x(), y()) : Vec2l.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(x(), y()) : Vec2f.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(x(), y()) : Vec2d.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2b asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Vec2bImmutable implements Vec2b {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public byte getX() { return x; }
|
||||
public byte x() { return x; }
|
||||
@Override
|
||||
public byte getY() { return y; }
|
||||
public byte y() { return y; }
|
||||
@Override
|
||||
public Vec2b setX(byte x) { return this.x == x ? this : Vec2b.of(x, y); }
|
||||
public Vec2b x(byte x) { return this.x == x ? this : Vec2b.of(x, y); }
|
||||
@Override
|
||||
public Vec2b setY(byte y) { return this.y == y ? this : Vec2b.of(x, y); }
|
||||
public Vec2b y(byte y) { return this.y == y ? this : Vec2b.of(x, y); }
|
||||
@Override
|
||||
public Vec2b copy() { return Vec2b.of(this); }
|
||||
@Override
|
||||
@@ -41,7 +41,7 @@ public class Vec2bImmutable implements Vec2b {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2b) {
|
||||
Vec2b vec = (Vec2b)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ public class Vec2bMutable implements Vec2b {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public byte getX() { return x; }
|
||||
public byte x() { return x; }
|
||||
@Override
|
||||
public byte getY() { return y; }
|
||||
public byte y() { return y; }
|
||||
|
||||
@Override
|
||||
public Vec2b setX(byte x) {
|
||||
public Vec2b x(byte x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2b setY(byte y) {
|
||||
public Vec2b y(byte y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class Vec2bMutable implements Vec2b {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2b) {
|
||||
Vec2b vec = (Vec2b)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,101 +17,101 @@ public interface Vec3b extends Vecb {
|
||||
public static Vec3b mutable() { return new Vec3bMutable(); }
|
||||
public static Vec3b mutable(byte value) { return new Vec3bMutable(value); }
|
||||
public static Vec3b mutable(byte x, byte y, byte z) { return new Vec3bMutable(x, y, z); }
|
||||
public static Vec3b mutable(Vec3b vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3b mutable(Vec3b vec) { return mutable(vec.x(), vec.y(), vec.z()); }
|
||||
public static Vec3b of() { return new Vec3bImmutable(); }
|
||||
public static Vec3b of(byte value) { return new Vec3bImmutable(value); }
|
||||
public static Vec3b of(byte x, byte y, byte z) { return new Vec3bImmutable(x, y, z); }
|
||||
public static Vec3b of(Vec3b vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3b of(Vec3b vec) { return of(vec.x(), vec.y(), vec.z()); }
|
||||
|
||||
public byte getX();
|
||||
public byte getY();
|
||||
public byte getZ();
|
||||
public Vec3b setX(byte x);
|
||||
public Vec3b setY(byte y);
|
||||
public Vec3b setZ(byte z);
|
||||
public byte x();
|
||||
public byte y();
|
||||
public byte z();
|
||||
public Vec3b x(byte x);
|
||||
public Vec3b y(byte y);
|
||||
public Vec3b z(byte z);
|
||||
|
||||
@Override
|
||||
public default byte[] asArray() { return new byte[] {getX(), getY(), getZ()}; }
|
||||
public default byte[] asArray() { return new byte[] {x(), y(), z()}; }
|
||||
@Override
|
||||
public Vec3b copy();
|
||||
@Override
|
||||
public default Vec3b abs() { return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ())); }
|
||||
public default Vec3b abs() { return set((byte)Math.abs(x()), (byte)Math.abs(y()), (byte)Math.abs(z())); }
|
||||
@Override
|
||||
public default Vec3b negate() { return set((byte)0, (byte)0, (byte)0); }
|
||||
@Override
|
||||
public default Vec3b invert() { return set((byte)-getX(), (byte)-getY(), (byte)-getZ()); }
|
||||
public default Vec3b invert() { return set((byte)-x(), (byte)-y(), (byte)-z()); }
|
||||
@Override
|
||||
public default Vec3b add(byte value) { return add(value, value, value); }
|
||||
public default Vec3b add(Vec3b value) { return add(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3b add(byte x, byte y, byte z) { return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z)); }
|
||||
public default Vec3b add(Vec3b value) { return add(value.x(), value.y(), value.z()); }
|
||||
public default Vec3b add(byte x, byte y, byte z) { return set((byte)(x() + x), (byte)(y() + y), (byte)(z() + z)); }
|
||||
@Override
|
||||
public default Vec3b sub(byte value) { return sub(value, value, value); }
|
||||
public default Vec3b sub(Vec3b value) { return sub(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3b sub(byte x, byte y, byte z) { return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z)); }
|
||||
public default Vec3b sub(Vec3b value) { return sub(value.x(), value.y(), value.z()); }
|
||||
public default Vec3b sub(byte x, byte y, byte z) { return set((byte)(x() - x), (byte)(y() - y), (byte)(z() - z)); }
|
||||
@Override
|
||||
public default Vec3b multiply(byte value) { return multiply(value, value, value); }
|
||||
public default Vec3b multiply(Vec3b value) { return multiply(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3b multiply(byte x, byte y, byte z) { return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z)); }
|
||||
public default Vec3b multiply(Vec3b value) { return multiply(value.x(), value.y(), value.z()); }
|
||||
public default Vec3b multiply(byte x, byte y, byte z) { return set((byte)(x() * x), (byte)(y() * y), (byte)(z() * z)); }
|
||||
@Override
|
||||
public default Vec3b devide(byte value) { return devide(value, value, value); }
|
||||
public default Vec3b devide(Vec3b value) { return devide(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3b devide(byte x, byte y, byte z) { return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z)); }
|
||||
public default Vec3b devide(Vec3b value) { return devide(value.x(), value.y(), value.z()); }
|
||||
public default Vec3b devide(byte x, byte y, byte z) { return set((byte)(x() / x), (byte)(y() / y), (byte)(z() / z)); }
|
||||
@Override
|
||||
public default Vec3b set(byte value) { return set(value, value, value); }
|
||||
public default Vec3b set(Vec3b value) { return set(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3b set(Vec3b value) { return set(value.x(), value.y(), value.z()); }
|
||||
public Vec3b set(byte x, byte y, byte z);
|
||||
public default double distanceTo(Vec3b value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
|
||||
public default double distanceTo(Vec3b value) { return distanceTo(value.x(), value.y(), value.z()); }
|
||||
public default double distanceTo(byte x, byte y, byte z) { return Math.sqrt(distanceToSquared(x, y, z)); }
|
||||
public default long distanceToSquared(Vec3b value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
|
||||
public default long distanceToSquared(Vec3b value) { return distanceToSquared(value.x(), value.y(), value.z()); }
|
||||
|
||||
public default long distanceToSquared(byte x, byte y, byte z) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long zPos = getZ() - z;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
long zPos = z() - z;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
|
||||
public default long dotProduct(Vec3b value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
|
||||
public default long dotProduct(byte x, byte y, byte z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
|
||||
public default long dotProduct(Vec3b value) { return dotProduct(value.x(), value.y(), value.z()); }
|
||||
public default long dotProduct(byte x, byte y, byte z) { return (x() * x) + (y() * y) + (z() * z); }
|
||||
public default Vec3b min(Vec3b other) { return min(other, this); }
|
||||
public default Vec3b min(Vec3b other, Vec3b result) { return min(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3b min(Vec3b other, Vec3b result) { return min(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3b min(byte x, byte y, byte z) { return min(x, y, z, this); }
|
||||
public default Vec3b min(byte x, byte y, byte z, Vec3b result) { return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z)); }
|
||||
public default Vec3b min(byte x, byte y, byte z, Vec3b result) { return result.set((byte)Math.min(x(), x), (byte)Math.min(y(), y), (byte)Math.min(z(), z)); }
|
||||
public default Vec3b max(Vec3b other) { return max(other, this); }
|
||||
public default Vec3b max(Vec3b other, Vec3b result) { return max(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3b max(Vec3b other, Vec3b result) { return max(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3b max(byte x, byte y, byte z) { return max(x, y, z, this); }
|
||||
public default Vec3b max(byte x, byte y, byte z, Vec3b result) { return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z)); }
|
||||
public default Vec3b max(byte x, byte y, byte z, Vec3b result) { return result.set((byte)Math.max(x(), x), (byte)Math.max(y(), y), (byte)Math.max(z(), z)); }
|
||||
public default Vec3b difference(Vec3b other) { return difference(other, this); }
|
||||
public default Vec3b difference(Vec3b other, Vec3b result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3b difference(Vec3b other, Vec3b result) { return difference(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3b difference(byte x, byte y, byte z) { return difference(x, y, z, this); }
|
||||
public default Vec3b difference(byte x, byte y, byte z, Vec3b result) { return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z)); }
|
||||
public default Vec3b difference(byte x, byte y, byte z, Vec3b result) { return result.set((byte)(x() - x), (byte)(y() - y), (byte)(z() - z)); }
|
||||
@Override
|
||||
public default Vec3b clamp(byte min, byte max) { return clamp(min, max, ALL); }
|
||||
public default Vec3b clamp(byte min, byte max, Vec3b result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec3b clamp(byte min, byte max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec3b clamp(byte min, byte max, Vec3b result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
|
||||
public default Vec3b clamp(byte min, byte max, Vec3b result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
|
||||
|
||||
@Override
|
||||
public default Vec3b store(ByteBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ());
|
||||
buffer.put(x()).put(y()).put(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec3b load(ByteBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable(getX(), getY(), getZ()) : Vec3s.of(getX(), getY(), getZ()); }
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable(x(), y(), z()) : Vec3s.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(getX(), getY(), getZ()) : Vec3i.of(getX(), getY(), getZ()); }
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(x(), y(), z()) : Vec3i.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ()); }
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(x(), y(), z()) : Vec3l.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(x(), y(), z()) : Vec3f.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(x(), y(), z()) : Vec3d.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3b asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -28,17 +28,17 @@ public class Vec3bImmutable implements Vec3b {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public byte getX() { return x; }
|
||||
public byte x() { return x; }
|
||||
@Override
|
||||
public byte getY() { return y; }
|
||||
public byte y() { return y; }
|
||||
@Override
|
||||
public byte getZ() { return z; }
|
||||
public byte z() { return z; }
|
||||
@Override
|
||||
public Vec3b setX(byte x) { return this.x == x ? this : Vec3b.of(x, y, z); }
|
||||
public Vec3b x(byte x) { return this.x == x ? this : Vec3b.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3b setY(byte y) { return this.y == y ? this : Vec3b.of(x, y, z); }
|
||||
public Vec3b y(byte y) { return this.y == y ? this : Vec3b.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3b setZ(byte z) { return this.z == z ? this : Vec3b.of(x, y, z); }
|
||||
public Vec3b z(byte z) { return this.z == z ? this : Vec3b.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3b copy() { return Vec3b.of(this); }
|
||||
@Override
|
||||
@@ -49,7 +49,7 @@ public class Vec3bImmutable implements Vec3b {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3b) {
|
||||
Vec3b vec = (Vec3b)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,26 +24,26 @@ public class Vec3bMutable implements Vec3b {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public byte getX() { return x; }
|
||||
public byte x() { return x; }
|
||||
@Override
|
||||
public byte getY() { return y; }
|
||||
public byte y() { return y; }
|
||||
@Override
|
||||
public byte getZ() { return z; }
|
||||
public byte z() { return z; }
|
||||
|
||||
@Override
|
||||
public Vec3b setX(byte x) {
|
||||
public Vec3b x(byte x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3b setY(byte y) {
|
||||
public Vec3b y(byte y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3b setZ(byte z) {
|
||||
public Vec3b z(byte z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class Vec3bMutable implements Vec3b {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3b) {
|
||||
Vec3b vec = (Vec3b)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,101 +17,101 @@ public interface Vec4b extends Vecb {
|
||||
public static Vec4b mutable() { return new Vec4bMutable(); }
|
||||
public static Vec4b mutable(byte value) { return new Vec4bMutable(value); }
|
||||
public static Vec4b mutable(byte x, byte y, byte z, byte w) { return new Vec4bMutable(x, y, z, w); }
|
||||
public static Vec4b mutable(Vec4b vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4b mutable(Vec4b vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
public static Vec4b of() { return new Vec4bImmutable(); }
|
||||
public static Vec4b of(byte value) { return new Vec4bImmutable(value); }
|
||||
public static Vec4b of(byte x, byte y, byte z, byte w) { return new Vec4bImmutable(x, y, z, w); }
|
||||
public static Vec4b of(Vec4b vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4b of(Vec4b vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
|
||||
public byte getX();
|
||||
public byte getY();
|
||||
public byte getZ();
|
||||
public byte getW();
|
||||
public Vec4b setX(byte x);
|
||||
public Vec4b setY(byte y);
|
||||
public Vec4b setZ(byte z);
|
||||
public Vec4b setW(byte w);
|
||||
public byte x();
|
||||
public byte y();
|
||||
public byte z();
|
||||
public byte w();
|
||||
public Vec4b x(byte x);
|
||||
public Vec4b y(byte y);
|
||||
public Vec4b z(byte z);
|
||||
public Vec4b w(byte w);
|
||||
|
||||
@Override
|
||||
public default byte[] asArray() { return new byte[] {getX(), getY(), getZ(), getW()}; }
|
||||
public default byte[] asArray() { return new byte[] {x(), y(), z(), w()}; }
|
||||
@Override
|
||||
public Vec4b copy();
|
||||
@Override
|
||||
public default Vec4b abs() { return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ()), (byte)Math.abs(getW())); }
|
||||
public default Vec4b abs() { return set((byte)Math.abs(x()), (byte)Math.abs(y()), (byte)Math.abs(z()), (byte)Math.abs(w())); }
|
||||
@Override
|
||||
public default Vec4b negate() { return set((byte)0, (byte)0, (byte)0, (byte)0); }
|
||||
@Override
|
||||
public default Vec4b invert() { return set((byte)-getX(), (byte)-getY(), (byte)-getZ(), (byte)-getW()); }
|
||||
public default Vec4b invert() { return set((byte)-x(), (byte)-y(), (byte)-z(), (byte)-w()); }
|
||||
@Override
|
||||
public default Vec4b add(byte value) { return add(value, value, value, value); }
|
||||
public default Vec4b add(Vec4b value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4b add(byte x, byte y, byte z, byte w) { return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z), (byte)(getW() + w)); }
|
||||
public default Vec4b add(Vec4b value) { return add(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4b add(byte x, byte y, byte z, byte w) { return set((byte)(x() + x), (byte)(y() + y), (byte)(z() + z), (byte)(w() + w)); }
|
||||
@Override
|
||||
public default Vec4b sub(byte value) { return sub(value, value, value, value); }
|
||||
public default Vec4b sub(Vec4b value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4b sub(byte x, byte y, byte z, byte w) { return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w)); }
|
||||
public default Vec4b sub(Vec4b value) { return sub(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4b sub(byte x, byte y, byte z, byte w) { return set((byte)(x() - x), (byte)(y() - y), (byte)(z() - z), (byte)(w() - w)); }
|
||||
@Override
|
||||
public default Vec4b multiply(byte value) { return multiply(value, value, value, value); }
|
||||
public default Vec4b multiply(Vec4b value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4b multiply(byte x, byte y, byte z, byte w) { return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z), (byte)(getW() * w)); }
|
||||
public default Vec4b multiply(Vec4b value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4b multiply(byte x, byte y, byte z, byte w) { return set((byte)(x() * x), (byte)(y() * y), (byte)(z() * z), (byte)(w() * w)); }
|
||||
@Override
|
||||
public default Vec4b devide(byte value) { return devide(value, value, value, value); }
|
||||
public default Vec4b devide(Vec4b value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4b devide(byte x, byte y, byte z, byte w) { return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z), (byte)(getW() / w)); }
|
||||
public default Vec4b devide(Vec4b value) { return devide(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4b devide(byte x, byte y, byte z, byte w) { return set((byte)(x() / x), (byte)(y() / y), (byte)(z() / z), (byte)(w() / w)); }
|
||||
@Override
|
||||
public default Vec4b set(byte value) { return set(value, value, value, value); }
|
||||
public default Vec4b set(Vec4b value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4b set(Vec4b value) { return set(value.x(), value.y(), value.z(), value.w()); }
|
||||
public Vec4b set(byte x, byte y, byte z, byte w);
|
||||
public default double distanceTo(Vec4b value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceTo(Vec4b value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceTo(byte x, byte y, byte z, byte w) { return Math.sqrt(distanceTo(x, y, z, w)); }
|
||||
public default long distanceToSquared(Vec4b value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default long distanceToSquared(Vec4b value) { return distanceToSquared(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default long distanceToSquared(byte x, byte y, byte z, byte w) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long zPos = getZ() - z;
|
||||
long wPos = getW() - w;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
long zPos = z() - z;
|
||||
long wPos = w() - w;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
|
||||
public default long dotProduct(Vec4b value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default long dotProduct(byte x, byte y, byte z, byte w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
|
||||
public default long dotProduct(Vec4b value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default long dotProduct(byte x, byte y, byte z, byte w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
|
||||
public default Vec4b min(Vec4b other) { return min(other, this); }
|
||||
public default Vec4b min(Vec4b other, Vec4b result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4b min(Vec4b other, Vec4b result) { return min(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4b min(byte x, byte y, byte z, byte w) { return min(x, y, z, w, this); }
|
||||
public default Vec4b min(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z), (byte)Math.min(getW(), w)); }
|
||||
public default Vec4b min(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)Math.min(x(), x), (byte)Math.min(y(), y), (byte)Math.min(z(), z), (byte)Math.min(w(), w)); }
|
||||
public default Vec4b max(Vec4b other) { return max(other, this); }
|
||||
public default Vec4b max(Vec4b other, Vec4b result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4b max(Vec4b other, Vec4b result) { return max(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4b max(byte x, byte y, byte z, byte w) { return max(x, y, z, w, this); }
|
||||
public default Vec4b max(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z), (byte)Math.max(getZ(), z)); }
|
||||
public default Vec4b max(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)Math.max(x(), x), (byte)Math.max(y(), y), (byte)Math.max(z(), z), (byte)Math.max(z(), z)); }
|
||||
public default Vec4b difference(Vec4b other) { return difference(other, this); }
|
||||
public default Vec4b difference(Vec4b other, Vec4b result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4b difference(Vec4b other, Vec4b result) { return difference(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4b difference(byte x, byte y, byte z, byte w) { return difference(x, y, z, w, this); }
|
||||
public default Vec4b difference(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w)); }
|
||||
public default Vec4b difference(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)(x() - x), (byte)(y() - y), (byte)(z() - z), (byte)(w() - w)); }
|
||||
@Override
|
||||
public default Vec4b clamp(byte min, byte max) { return clamp(min, max, ALL); }
|
||||
public default Vec4b clamp(byte min, byte max, Vec4b result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec4b clamp(byte min, byte max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec4b clamp(byte min, byte max, Vec4b result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
|
||||
public default Vec4b clamp(byte min, byte max, Vec4b result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
|
||||
@Override
|
||||
public default Vec4b store(ByteBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
|
||||
buffer.put(x()).put(y()).put(z()).put(w());
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public default Vec4b load(ByteBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable(getX(), getY(), getZ(), getW()) : Vec4s.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable(x(), y(), z(), w()) : Vec4s.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(getX(), getY(), getZ(), getW()) : Vec4i.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(x(), y(), z(), w()) : Vec4i.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(x(), y(), z(), w()) : Vec4l.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(x(), y(), z(), w()) : Vec4f.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4d asDouble() {return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4d asDouble() {return isMutable() ? Vec4d.mutable(x(), y(), z(), w()) : Vec4d.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4b asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -32,21 +32,21 @@ public class Vec4bImmutable implements Vec4b {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public byte getX() { return x; }
|
||||
public byte x() { return x; }
|
||||
@Override
|
||||
public byte getY() { return y; }
|
||||
public byte y() { return y; }
|
||||
@Override
|
||||
public byte getZ() { return z; }
|
||||
public byte z() { return z; }
|
||||
@Override
|
||||
public byte getW() { return w; }
|
||||
public byte w() { return w; }
|
||||
@Override
|
||||
public Vec4b setX(byte x) { return this.x == x ? this : Vec4b.of(x, y, z, w); }
|
||||
public Vec4b x(byte x) { return this.x == x ? this : Vec4b.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4b setY(byte y) { return this.y == y ? this : Vec4b.of(x, y, z, w); }
|
||||
public Vec4b y(byte y) { return this.y == y ? this : Vec4b.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4b setZ(byte z) { return this.z == z ? this : Vec4b.of(x, y, z, w); }
|
||||
public Vec4b z(byte z) { return this.z == z ? this : Vec4b.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4b setW(byte w) { return this.w == w ? this : Vec4b.of(x, y, z, w); }
|
||||
public Vec4b w(byte w) { return this.w == w ? this : Vec4b.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4b copy() { return Vec4b.of(this); }
|
||||
@Override
|
||||
@@ -58,7 +58,7 @@ public class Vec4bImmutable implements Vec4b {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4b) {
|
||||
Vec4b vec = (Vec4b)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,34 +27,34 @@ public class Vec4bMutable implements Vec4b {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public byte getX() { return x; }
|
||||
public byte x() { return x; }
|
||||
@Override
|
||||
public byte getY() { return y; }
|
||||
public byte y() { return y; }
|
||||
@Override
|
||||
public byte getZ() { return z; }
|
||||
public byte z() { return z; }
|
||||
@Override
|
||||
public byte getW() { return w; }
|
||||
public byte w() { return w; }
|
||||
|
||||
@Override
|
||||
public Vec4b setX(byte x) {
|
||||
public Vec4b x(byte x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4b setY(byte y) {
|
||||
public Vec4b y(byte y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4b setZ(byte z) {
|
||||
public Vec4b z(byte z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4b setW(byte w) {
|
||||
public Vec4b w(byte w) {
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class Vec4bMutable implements Vec4b {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4b) {
|
||||
Vec4b vec = (Vec4b)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,26 +18,26 @@ public interface Vec2d extends Vecd {
|
||||
public static Vec2d mutable() { return new Vec2dMutable(); }
|
||||
public static Vec2d mutable(double value) { return new Vec2dMutable(value); }
|
||||
public static Vec2d mutable(double x, double y) { return new Vec2dMutable(x, y); }
|
||||
public static Vec2d mutable(Vec2d value) { return mutable(value.getX(), value.getY()); }
|
||||
public static Vec2d mutable(Vec2d value) { return mutable(value.x(), value.y()); }
|
||||
public static Vec2d of() { return new Vec2dImmutable(); }
|
||||
public static Vec2d of(double value) { return new Vec2dImmutable(value); }
|
||||
public static Vec2d of(double x, double y) { return new Vec2dImmutable(x, y); }
|
||||
public static Vec2d of(Vec2d value) { return of(value.getX(), value.getY()); }
|
||||
public static Vec2d of(Vec2d value) { return of(value.x(), value.y()); }
|
||||
|
||||
public double getX();
|
||||
public double getY();
|
||||
public Vec2d setX(double x);
|
||||
public Vec2d setY(double y);
|
||||
public double x();
|
||||
public double y();
|
||||
public Vec2d x(double x);
|
||||
public Vec2d y(double y);
|
||||
@Override
|
||||
public default double[] asArray() { return new double[] {getX(), getY()}; }
|
||||
public default double[] asArray() { return new double[] {x(), y()}; }
|
||||
@Override
|
||||
public Vec2d copy();
|
||||
@Override
|
||||
public default Vec2d abs() { return set(Math.abs(getX()), Math.abs(getY())); }
|
||||
public default Vec2d abs() { return set(Math.abs(x()), Math.abs(y())); }
|
||||
@Override
|
||||
public default Vec2d negate() { return set(0D, 0D); }
|
||||
@Override
|
||||
public default Vec2d invert() { return set(-getX(), -getY()); };
|
||||
public default Vec2d invert() { return set(-x(), -y()); };
|
||||
public default Vec2d normalize() {
|
||||
double l = length();
|
||||
return l == 0D ? this : multiply(1D / l);
|
||||
@@ -45,106 +45,106 @@ public interface Vec2d extends Vecd {
|
||||
|
||||
@Override
|
||||
public default Vec2d add(double value) { return add(value, value); }
|
||||
public default Vec2d add(Vec2d value) { return add(value.getX(), value.getY()); }
|
||||
public default Vec2d add(double x, double y) { return set(x + getX(), y + getY()); }
|
||||
public default Vec2d add(Vec2d value) { return add(value.x(), value.y()); }
|
||||
public default Vec2d add(double x, double y) { return set(x + x(), y + y()); }
|
||||
@Override
|
||||
public default Vec2d sub(double value) { return sub(value, value); }
|
||||
public default Vec2d sub(Vec2d value) { return sub(value.getX(), value.getY()); }
|
||||
public default Vec2d sub(double x, double y) { return set(getX() - x, getY() - y); }
|
||||
public default Vec2d sub(Vec2d value) { return sub(value.x(), value.y()); }
|
||||
public default Vec2d sub(double x, double y) { return set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2d multiply(double value) { return multiply(value, value); }
|
||||
public default Vec2d multiply(Vec2d value) { return multiply(value.getX(), value.getY()); }
|
||||
public default Vec2d multiply(double x, double y) { return set(x * getX(), y * getY()); }
|
||||
public default Vec2d multiply(Vec2d value) { return multiply(value.x(), value.y()); }
|
||||
public default Vec2d multiply(double x, double y) { return set(x * x(), y * y()); }
|
||||
@Override
|
||||
public default Vec2d devide(double value) { return devide(value, value); }
|
||||
public default Vec2d devide(Vec2d value) { return devide(value.getX(), value.getY()); }
|
||||
public default Vec2d devide(double x, double y) { return set(getX() / x, getY() / y); }
|
||||
public default Vec2d devide(Vec2d value) { return devide(value.x(), value.y()); }
|
||||
public default Vec2d devide(double x, double y) { return set(x() / x, y() / y); }
|
||||
@Override
|
||||
public default Vec2d set(double value) { return set(value, value); };
|
||||
public default Vec2d set(Vec2d value) { return set(value.getX(), value.getY()); }
|
||||
public default Vec2d set(Vec2d value) { return set(value.x(), value.y()); }
|
||||
public Vec2d set(double x, double y);
|
||||
|
||||
public default double distanceTo(Vec2d value) { return distanceTo(value.getX(), value.getY()); }
|
||||
public default double distanceTo(Vec2d value) { return distanceTo(value.x(), value.y()); }
|
||||
public default double distanceTo(double x, double y) { return Math.sqrt(distanceToSquared(x, y)); }
|
||||
public default double distanceToSquared(Vec2d value) { return distanceToSquared(value.getX(), value.getY()); }
|
||||
public default double distanceToSquared(Vec2d value) { return distanceToSquared(value.x(), value.y()); }
|
||||
public default double distanceToSquared(double x, double y) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
return (xPos * xPos) + (yPos * yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default double lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
|
||||
public default double dotProduct(Vec2d value) { return dotProduct(value.getX(), value.getY()); }
|
||||
public default double dotProduct(double x, double y) { return (getX() * x) + (getY() * y); }
|
||||
public default Vec2d lerp(Vec2d value, float progress, Vec2d result) { return lerp(value.getX(), value.getY(), progress, result); }
|
||||
public default Vec2d lerp(double x, double y, float progress, Vec2d result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress)); };
|
||||
public default double angle(Vec2d value) { return angle(value.getX(), value.getY()); }
|
||||
public default double angle(double x, double y) { return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y)); }
|
||||
public default double directionAngle(Vec2d value) { return directionAngle(value.getX(), value.getY()); }
|
||||
public default double directionAngle(double x, double y) { return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D); }
|
||||
public default Vec2d reflect(Vec2d value) { return reflect(value.getX(), value.getY(), this); }
|
||||
public default double lengthSquared() { return (x() * x()) + (y() * y()); }
|
||||
public default double dotProduct(Vec2d value) { return dotProduct(value.x(), value.y()); }
|
||||
public default double dotProduct(double x, double y) { return (x() * x) + (y() * y); }
|
||||
public default Vec2d lerp(Vec2d value, float progress, Vec2d result) { return lerp(value.x(), value.y(), progress, result); }
|
||||
public default Vec2d lerp(double x, double y, float progress, Vec2d result) { return result.set(MathUtils.lerp(x(), x, progress), MathUtils.lerp(y(), y, progress)); };
|
||||
public default double angle(Vec2d value) { return angle(value.x(), value.y()); }
|
||||
public default double angle(double x, double y) { return (float)Math.atan2((x() * y) - (y() * x), (x() * x) + (y() * y)); }
|
||||
public default double directionAngle(Vec2d value) { return directionAngle(value.x(), value.y()); }
|
||||
public default double directionAngle(double x, double y) { return (float)(-Math.toDegrees(Math.atan2(x() - x, y() - y)) % 360D); }
|
||||
public default Vec2d reflect(Vec2d value) { return reflect(value.x(), value.y(), this); }
|
||||
public default Vec2d reflect(double x, double y) { return reflect(x, y, this); };
|
||||
public default Vec2d reflect(Vec2d value, Vec2d result) { return reflect(value.getX(), value.getY(), result); }
|
||||
public default Vec2d reflect(Vec2d value, Vec2d result) { return reflect(value.x(), value.y(), result); }
|
||||
public default Vec2d reflect(double x, double y, Vec2d result) {
|
||||
double dot = dotProduct(x, y);
|
||||
double x2 = (float)((dot + dot) * x);
|
||||
double y2 = (float)((dot + dot) * y);
|
||||
return result.set(getX() - x2, getY() - y2);
|
||||
return result.set(x() - x2, y() - y2);
|
||||
}
|
||||
|
||||
public default Vec2d rotate(double angle, Vec2d center) { return rotate(angle, center.getX(), center.getY()); }
|
||||
public default Vec2d rotate(double angle, Vec2d center) { return rotate(angle, center.x(), center.y()); }
|
||||
public default Vec2d rotate(double angle, double x, double y) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y));
|
||||
}
|
||||
|
||||
public default Vec2d min(Vec2d other) { return min(other, this); }
|
||||
public default Vec2d min(Vec2d other, Vec2d result) { return min(other.getX(), other.getY(), result); }
|
||||
public default Vec2d min(Vec2d other, Vec2d result) { return min(other.x(), other.y(), result); }
|
||||
public default Vec2d min(double x, double y) { return min(x, y, this); }
|
||||
public default Vec2d min(double x, double y, Vec2d result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
|
||||
public default Vec2d min(double x, double y, Vec2d result) { return result.set(Math.min(x(), x), Math.min(y(), y)); }
|
||||
public default Vec2d max(Vec2d other) { return max(other, this); }
|
||||
public default Vec2d max(Vec2d other, Vec2d result) { return max(other.getX(), other.getY(), result); }
|
||||
public default Vec2d max(Vec2d other, Vec2d result) { return max(other.x(), other.y(), result); }
|
||||
public default Vec2d max(double x, double y) { return max(x, y, this); }
|
||||
public default Vec2d max(double x, double y, Vec2d result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
|
||||
public default Vec2d max(double x, double y, Vec2d result) { return result.set(Math.max(x(), x), Math.max(y(), y)); }
|
||||
public default Vec2d difference(Vec2d other) { return difference(other, this); }
|
||||
public default Vec2d difference(Vec2d other, Vec2d result) { return difference(other.getX(), other.getY(), result); }
|
||||
public default Vec2d difference(Vec2d other, Vec2d result) { return difference(other.x(), other.y(), result); }
|
||||
public default Vec2d difference(double x, double y) { return difference(x, y, this); }
|
||||
public default Vec2d difference(double x, double y, Vec2d result) { return result.set(getX() - x, getY() - y); }
|
||||
public default Vec2d difference(double x, double y, Vec2d result) { return result.set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2d clamp(double min, double max) { return clamp(min, max, ALL); }
|
||||
public default Vec2d clamp(double min, double max, Vec2d result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec2d clamp(double min, double max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec2d clamp(double min, double max, Vec2d result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
|
||||
public default Vec2d clamp(double min, double max, Vec2d result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
|
||||
|
||||
@Override
|
||||
public default Vec2d store(ByteBuffer buffer) {
|
||||
buffer.putDouble(getX()).putDouble(getY());
|
||||
buffer.putDouble(x()).putDouble(y());
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public default Vec2d load(ByteBuffer buffer) { return set(buffer.getDouble(), buffer.getDouble()); }
|
||||
@Override
|
||||
public default Vec2d store(DoubleBuffer buffer) {
|
||||
buffer.put(getX()).put(getY());
|
||||
buffer.put(x()).put(y());
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public default Vec2d load(DoubleBuffer buffer) { return set(buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())); }
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y())) : Vec2b.of((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())); }
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)MathUtils.floor(x()), (short)MathUtils.floor(y())) : Vec2s.of((short)MathUtils.floor(x()), (short)MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(MathUtils.floor(x()), MathUtils.floor(y())) : Vec2i.of(MathUtils.floor(x()), MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(MathUtils.floor(x()), MathUtils.floor(y())) : Vec2l.of(MathUtils.floor(x()), MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable((float)getX(), (float)getY()) : Vec2f.of((float)getX(), (float)getY()); }
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable((float)x(), (float)y()) : Vec2f.of((float)x(), (float)y()); }
|
||||
@Override
|
||||
public default Vec2d asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Vec2dImmutable implements Vec2d {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public double getX() { return x; }
|
||||
public double x() { return x; }
|
||||
@Override
|
||||
public double getY() { return y; }
|
||||
public double y() { return y; }
|
||||
@Override
|
||||
public Vec2d setX(double x) { return this.x == x ? this : Vec2d.of(x, y); }
|
||||
public Vec2d x(double x) { return this.x == x ? this : Vec2d.of(x, y); }
|
||||
@Override
|
||||
public Vec2d setY(double y) { return this.y == y ? this : Vec2d.of(x, y); }
|
||||
public Vec2d y(double y) { return this.y == y ? this : Vec2d.of(x, y); }
|
||||
@Override
|
||||
public Vec2d copy() { return Vec2d.of(this); }
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class Vec2dImmutable implements Vec2d {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2d) {
|
||||
Vec2d vec = (Vec2d)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,18 +24,18 @@ public class Vec2dMutable implements Vec2d {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public double getX() { return x; }
|
||||
public double x() { return x; }
|
||||
@Override
|
||||
public double getY() { return y; }
|
||||
public double y() { return y; }
|
||||
|
||||
@Override
|
||||
public Vec2d setX(double x) {
|
||||
public Vec2d x(double x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2d setY(double y) {
|
||||
public Vec2d y(double y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class Vec2dMutable implements Vec2d {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2d) {
|
||||
Vec2d vec = (Vec2d)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface Vec3d extends Vecd {
|
||||
|
||||
public static Vec3d mutable(double x, double y, double z) { return new Vec3dMutable(x, y, z); }
|
||||
|
||||
public static Vec3d mutable(Vec3d vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3d mutable(Vec3d vec) { return mutable(vec.x(), vec.y(), vec.z()); }
|
||||
|
||||
public static Vec3d of() { return new Vec3dImmutable(); }
|
||||
|
||||
@@ -29,30 +29,26 @@ public interface Vec3d extends Vecd {
|
||||
|
||||
public static Vec3d of(double x, double y, double z) { return new Vec3dImmutable(x, y, z); }
|
||||
|
||||
public static Vec3d of(Vec3d vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3d of(Vec3d vec) { return of(vec.x(), vec.y(), vec.z()); }
|
||||
|
||||
public double getX();
|
||||
public double getY();
|
||||
public double getZ();
|
||||
public Vec3d setX(double x);
|
||||
public Vec3d setY(double y);
|
||||
public Vec3d setZ(double z);
|
||||
public double x();
|
||||
public double y();
|
||||
public double z();
|
||||
public Vec3d x(double x);
|
||||
public Vec3d y(double y);
|
||||
public Vec3d z(double z);
|
||||
|
||||
@Override
|
||||
public default double[] asArray() { return new double[] {getX(), getY(), getZ()}; }
|
||||
public default double[] asArray() { return new double[] {x(), y(), z()}; }
|
||||
|
||||
@Override
|
||||
public Vec3d copy();
|
||||
|
||||
@Override
|
||||
public default Vec3d abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
|
||||
|
||||
public default Vec3d abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z())); }
|
||||
@Override
|
||||
public default Vec3d negate() { return set(0D, 0D, 0D); }
|
||||
|
||||
@Override
|
||||
public default Vec3d invert() { return set(-getX(), -getY(), -getZ()); }
|
||||
|
||||
public default Vec3d invert() { return set(-x(), -y(), -z()); }
|
||||
public default Vec3d normalize() {
|
||||
double l = length();
|
||||
return l == 0D ? this : multiply(1.0D / l);
|
||||
@@ -60,316 +56,165 @@ public interface Vec3d extends Vecd {
|
||||
|
||||
@Override
|
||||
public default Vec3d add(double value) { return add(value, value, value); }
|
||||
|
||||
public default Vec3d add(Vec3d value) { return add(value.getX(), value.getY(), value.getZ()); }
|
||||
|
||||
public default Vec3d add(double x, double y, double z) {
|
||||
return set(getX() + x, getY() + y, getZ() + z);
|
||||
}
|
||||
|
||||
public default Vec3d add(Vec3d value) { return add(value.x(), value.y(), value.z()); }
|
||||
public default Vec3d add(double x, double y, double z) { return set(x() + x, y() + y, z() + z); }
|
||||
@Override
|
||||
public default Vec3d sub(double value) { return sub(value, value, value); }
|
||||
|
||||
public default Vec3d sub(Vec3d value) { return sub(value.getX(), value.getY(), value.getZ()); }
|
||||
|
||||
public default Vec3d sub(double x, double y, double z) {
|
||||
return set(getX() - x, getY() - y, getZ() - z);
|
||||
}
|
||||
|
||||
public default Vec3d sub(Vec3d value) { return sub(value.x(), value.y(), value.z()); }
|
||||
public default Vec3d sub(double x, double y, double z) { return set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3d multiply(double value) { return multiply(value, value, value); }
|
||||
|
||||
public default Vec3d multiply(Vec3d value) {
|
||||
return multiply(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default Vec3d multiply(double x, double y, double z) {
|
||||
return set(getX() * x, getY() * y, getZ() * z);
|
||||
}
|
||||
|
||||
public default Vec3d multiply(Vec3d value) { return multiply(value.x(), value.y(), value.z()); }
|
||||
public default Vec3d multiply(double x, double y, double z) { return set(x() * x, y() * y, z() * z); }
|
||||
@Override
|
||||
public default Vec3d devide(double value) { return devide(value, value, value); }
|
||||
|
||||
public default Vec3d devide(Vec3d value) {
|
||||
return devide(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default Vec3d devide(double x, double y, double z) {
|
||||
return set(getX() / x, getY() / y, getZ() / z);
|
||||
}
|
||||
|
||||
public default Vec3d devide(Vec3d value) { return devide(value.x(), value.y(), value.z()); }
|
||||
public default Vec3d devide(double x, double y, double z) { return set(x() / x, y() / y, z() / z); }
|
||||
@Override
|
||||
public default Vec3d set(double value) { return set(value, value, value); }
|
||||
|
||||
public default Vec3d set(Vec3d value) { return set(value.getX(), value.getY(), value.getZ()); }
|
||||
|
||||
public default Vec3d set(Vec3d value) { return set(value.x(), value.y(), value.z()); }
|
||||
public Vec3d set(double x, double y, double z);
|
||||
|
||||
public default double distanceTo(Vec3d value) {
|
||||
return distanceTo(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default double distanceTo(double x, double y, double z) {
|
||||
return Math.sqrt(distanceToSquared(x, y, z));
|
||||
}
|
||||
|
||||
public default double distanceToSquared(Vec3d value) {
|
||||
return distanceToSquared(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default double distanceTo(Vec3d value) { return distanceTo(value.x(), value.y(), value.z()); }
|
||||
public default double distanceTo(double x, double y, double z) { return Math.sqrt(distanceToSquared(x, y, z)); }
|
||||
public default double distanceToSquared(Vec3d value) { return distanceToSquared(value.x(), value.y(), value.z()); }
|
||||
public default double distanceToSquared(double x, double y, double z) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double zPos = getZ() - z;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
double zPos = z() - z;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default double lengthSquared() {
|
||||
return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
|
||||
}
|
||||
|
||||
public default double dotProduct(Vec3d value) {
|
||||
return dotProduct(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default double dotProduct(double x, double y, double z) {
|
||||
return (getX() * x) + (getY() * y) + (getZ() * z);
|
||||
}
|
||||
|
||||
public default Vec3d lerp(Vec3d value, float progress, Vec3d result) {
|
||||
return lerp(value.getX(), value.getY(), value.getZ(), progress, result);
|
||||
}
|
||||
|
||||
public default Vec3d lerp(double x, double y, double z, float progress, Vec3d result) {
|
||||
return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress));
|
||||
}
|
||||
|
||||
public default double angle(Vec3d value) {
|
||||
return angle(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default double angle(double x, double y, double z) {
|
||||
return Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z)));
|
||||
}
|
||||
|
||||
public default double angleCos(Vec3d value) {
|
||||
return angleCos(value.getX(), value.getY(), value.getZ());
|
||||
}
|
||||
|
||||
public default double lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
|
||||
public default double dotProduct(Vec3d value) { return dotProduct(value.x(), value.y(), value.z()); }
|
||||
public default double dotProduct(double x, double y, double z) { return (x() * x) + (y() * y) + (z() * z); }
|
||||
public default Vec3d lerp(Vec3d value, float progress, Vec3d result) { return lerp(value.x(), value.y(), value.z(), progress, result); }
|
||||
public default Vec3d lerp(double x, double y, double z, float progress, Vec3d result) { return result.set(MathUtils.lerp(x(), x, progress), MathUtils.lerp(y(), y, progress), MathUtils.lerp(z(), z, progress)); }
|
||||
public default double angle(Vec3d value) { return angle(value.x(), value.y(), value.z()); }
|
||||
public default double angle(double x, double y, double z) { return Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z))); }
|
||||
public default double angleCos(Vec3d value) { return angleCos(value.x(), value.y(), value.z()); }
|
||||
public default double angleCos(double x, double y, double z) {
|
||||
double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
|
||||
double myLength = (x() * x()) + (y() * y()) + (z() * z());
|
||||
double otherLength = (x * x) + (y * y) + (z * z);
|
||||
double dot = (getX() * x) + (getY() * y) + (getZ() * z);
|
||||
double dot = (x() * x) + (y() * y) + (z() * z);
|
||||
return dot / (Math.sqrt(myLength * otherLength));
|
||||
}
|
||||
|
||||
public default Vec3d crossProduct(Vec3d value) {
|
||||
return crossProduct(value.getX(), value.getY(), value.getZ(), this);
|
||||
}
|
||||
|
||||
public default Vec3d crossProduct(Vec3d value, Vec3d result) {
|
||||
return crossProduct(value.getX(), value.getY(), value.getZ(), result);
|
||||
}
|
||||
|
||||
public default Vec3d crossProduct(double x, double y, double z) {
|
||||
return crossProduct(x, y, z, this);
|
||||
}
|
||||
|
||||
public default Vec3d crossProduct(double x, double y, double z, Vec3d result) {
|
||||
return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x));
|
||||
}
|
||||
|
||||
public default Vec3d reflect(Vec3d value) {
|
||||
return reflect(value.getX(), value.getY(), value.getZ(), this);
|
||||
}
|
||||
|
||||
public default Vec3d reflect(Vec3d value, Vec3d result) {
|
||||
return reflect(value.getX(), value.getY(), value.getZ(), result);
|
||||
}
|
||||
|
||||
public default Vec3d crossProduct(Vec3d value) { return crossProduct(value.x(), value.y(), value.z(), this); }
|
||||
public default Vec3d crossProduct(Vec3d value, Vec3d result) { return crossProduct(value.x(), value.y(), value.z(), result); }
|
||||
public default Vec3d crossProduct(double x, double y, double z) { return crossProduct(x, y, z, this); }
|
||||
public default Vec3d crossProduct(double x, double y, double z, Vec3d result) { return result.set((y() * z) - (z() * y), (z() * x) - (x() * z), (x() * y) - (y() * x)); }
|
||||
public default Vec3d reflect(Vec3d value) { return reflect(value.x(), value.y(), value.z(), this); }
|
||||
public default Vec3d reflect(Vec3d value, Vec3d result) { return reflect(value.x(), value.y(), value.z(), result); }
|
||||
public default Vec3d reflect(double x, double y, double z) { return reflect(x, y, z, this); }
|
||||
|
||||
public default Vec3d reflect(double x, double y, double z, Vec3d result) {
|
||||
public default Vec3d reflect(double x, double y, double z, Vec3d result) {
|
||||
double dot = dotProduct(x, y, z) * 2D;
|
||||
return result.set(getX() - dot * x, getY() - dot * y, getZ() - dot * z);
|
||||
}
|
||||
|
||||
public default Vec3d rotate(double angle, Vec3d axis) {
|
||||
return rotate(angle, axis.getX(), axis.getY(), axis.getZ());
|
||||
}
|
||||
|
||||
public default Vec3d rotate(double angle, Vec3d axis, Vec3d result) {
|
||||
return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result);
|
||||
}
|
||||
|
||||
public default Vec3d rotate(double angle, double x, double y, double z) {
|
||||
return rotate(angle, x, y, z, this);
|
||||
return result.set(x() - dot * x, y() - dot * y, z() - dot * z);
|
||||
}
|
||||
|
||||
public default Vec3d rotate(double angle, Vec3d axis) { return rotate(angle, axis.x(), axis.y(), axis.z()); }
|
||||
public default Vec3d rotate(double angle, Vec3d axis, Vec3d result) { return rotate(angle, axis.x(), axis.y(), axis.z(), result); }
|
||||
public default Vec3d rotate(double angle, double x, double y, double z) { return rotate(angle, x, y, z, this); }
|
||||
public default Vec3d rotate(double angle, double x, double y, double z, Vec3d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double dot = dotProduct(x, y, z);
|
||||
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
|
||||
double xPos = x * dot * (1D - cos) + (x() * cos) + (-z * y() + y * z()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (y() * cos) + (z * x() - x * z()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (z() * cos) + (-y * x() + x * y()) * sin;
|
||||
return result.set(xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
public default Vec3d rotateX(double angle) { return rotateX(angle, this); }
|
||||
|
||||
public default Vec3d rotateX(double angle, Vec3d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double y = getY() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getY() * sin;
|
||||
return result.set(getX(), y, z);
|
||||
double y = y() * cos + z() * sin;
|
||||
double z = z() * cos - y() * sin;
|
||||
return result.set(x(), y, z);
|
||||
}
|
||||
|
||||
public default Vec3d rotateY(double angle) { return rotateY(angle, this); }
|
||||
|
||||
public default Vec3d rotateY(double angle, Vec3d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = getX() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getX() * sin;
|
||||
return result.set(x, getY(), z);
|
||||
double x = x() * cos + z() * sin;
|
||||
double z = z() * cos - x() * sin;
|
||||
return result.set(x, y(), z);
|
||||
}
|
||||
|
||||
public default Vec3d rotateZ(double angle) { return rotateZ(angle, this); }
|
||||
|
||||
public default Vec3d rotateZ(double angle, Vec3d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = cos * getX() - sin * getY();
|
||||
double y = sin * getX() + cos * getY();
|
||||
return result.set(x, y, getZ());
|
||||
}
|
||||
|
||||
public default Vec3d smoothStep(Vec3d value, float progress, Vec3d result) {
|
||||
return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result);
|
||||
double x = cos * x() - sin * y();
|
||||
double y = sin * x() + cos * y();
|
||||
return result.set(x, y, z());
|
||||
}
|
||||
|
||||
public default Vec3d smoothStep(Vec3d value, float progress, Vec3d result) { return smoothStep(value.x(), value.y(), value.z(), progress, result); }
|
||||
public default Vec3d smoothStep(double x, double y, double z, float progress, Vec3d result) {
|
||||
double t2 = progress * progress;
|
||||
double t3 = t2 * progress;
|
||||
double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX());
|
||||
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY());
|
||||
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ());
|
||||
double xPos = ((x() + x() - x - x) * t3 + (3.0D * x - 3.0D * x()) * t2 + x() * progress + x());
|
||||
double yPos = ((y() + y() - y - y) * t3 + (3.0D * y - 3.0D * y()) * t2 + y() * progress + y());
|
||||
double zPos = ((z() + z() - z - z) * t3 + (3.0D * z - 3.0D * z()) * t2 + z() * progress + z());
|
||||
return result.set(xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
public default Vec3d min(Vec3d other) { return min(other, this); }
|
||||
|
||||
public default Vec3d min(Vec3d other, Vec3d result) {
|
||||
return min(other.getX(), other.getY(), other.getZ(), result);
|
||||
}
|
||||
|
||||
public default Vec3d min(Vec3d other, Vec3d result) { return min(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3d min(double x, double y, double z) { return min(x, y, z, this); }
|
||||
|
||||
public default Vec3d min(double x, double y, double z, Vec3d result) {
|
||||
return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));
|
||||
}
|
||||
|
||||
public default Vec3d min(double x, double y, double z, Vec3d result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z)); }
|
||||
public default Vec3d max(Vec3d other) { return max(other, this); }
|
||||
|
||||
public default Vec3d max(Vec3d other, Vec3d result) {
|
||||
return max(other.getX(), other.getY(), other.getZ(), result);
|
||||
}
|
||||
|
||||
public default Vec3d max(Vec3d other, Vec3d result) { return max(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3d max(double x, double y, double z) { return max(x, y, z, this); }
|
||||
|
||||
public default Vec3d max(double x, double y, double z, Vec3d result) {
|
||||
return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));
|
||||
}
|
||||
|
||||
public default Vec3d max(double x, double y, double z, Vec3d result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z)); }
|
||||
public default Vec3d difference(Vec3d other) { return difference(other, this); }
|
||||
|
||||
public default Vec3d difference(Vec3d other, Vec3d result) {
|
||||
return difference(other.getX(), other.getY(), other.getZ(), result);
|
||||
}
|
||||
|
||||
public default Vec3d difference(double x, double y, double z) {
|
||||
return difference(x, y, z, this);
|
||||
}
|
||||
|
||||
public default Vec3d difference(double x, double y, double z, Vec3d result) {
|
||||
return result.set(getX() - x, getY() - y, getZ() - z);
|
||||
}
|
||||
|
||||
public default Vec3d difference(Vec3d other, Vec3d result) { return difference(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3d difference(double x, double y, double z) { return difference(x, y, z, this); }
|
||||
public default Vec3d difference(double x, double y, double z, Vec3d result) { return result.set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3d clamp(double min, double max) { return clamp(min, max, ALL); }
|
||||
|
||||
public default Vec3d clamp(double min, double max, Vec3d result) {
|
||||
return clamp(min, max, result, ALL);
|
||||
}
|
||||
|
||||
public default Vec3d clamp(double min, double max, Vec3d result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec3d clamp(double min, double max, int filter) {
|
||||
return clamp(min, max, this, filter);
|
||||
}
|
||||
|
||||
public default Vec3d clamp(double min, double max, Vec3d result, int filter) {
|
||||
return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));
|
||||
}
|
||||
public default Vec3d clamp(double min, double max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec3d clamp(double min, double max, Vec3d result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
|
||||
|
||||
@Override
|
||||
public default Vec3d store(ByteBuffer buffer) {
|
||||
buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ());
|
||||
buffer.putDouble(x()).putDouble(y()).putDouble(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec3d load(ByteBuffer buffer) {
|
||||
return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble());
|
||||
}
|
||||
public default Vec3d load(ByteBuffer buffer) { return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble()); }
|
||||
|
||||
@Override
|
||||
public default Vec3d store(DoubleBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ());
|
||||
buffer.put(x()).put(y()).put(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec3d load(DoubleBuffer buffer) {
|
||||
return set(buffer.get(), buffer.get(), buffer.get());
|
||||
}
|
||||
|
||||
public default Vec3d load(DoubleBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec3b asByte() {
|
||||
return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()));
|
||||
}
|
||||
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z())) : Vec3b.of((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3s asShort() {
|
||||
return isMutable() ? Vec3s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()));
|
||||
}
|
||||
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z())) : Vec3s.of((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3i asInt() {
|
||||
return isMutable() ? Vec3i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));
|
||||
}
|
||||
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())) : Vec3i.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3l asLong() {
|
||||
return isMutable() ? Vec3l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));
|
||||
}
|
||||
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())) : Vec3l.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3f asFloat() {
|
||||
return isMutable() ? Vec3f.mutable((float)getX(), (float)getY(), (float)getZ()) : Vec3f.of((float)getX(), (float)getY(), (float)getZ());
|
||||
}
|
||||
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable((float)x(), (float)y(), (float)z()) : Vec3f.of((float)x(), (float)y(), (float)z()); }
|
||||
@Override
|
||||
public default Vec3d asMutable() { return isMutable() ? this : mutable(this); }
|
||||
|
||||
@Override
|
||||
public default Vec3d asImmutable() { return isMutable() ? of(this) : this; }
|
||||
|
||||
@Override
|
||||
public default Vec3d copyAsMutable() { return mutable(this); }
|
||||
|
||||
@Override
|
||||
public default Vec3d copyAsImmutable() { return of(this); }
|
||||
}
|
||||
|
||||
@@ -28,17 +28,17 @@ public class Vec3dImmutable implements Vec3d {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public double getX() { return x; }
|
||||
public double x() { return x; }
|
||||
@Override
|
||||
public double getY() { return y; }
|
||||
public double y() { return y; }
|
||||
@Override
|
||||
public double getZ() { return z; }
|
||||
public double z() { return z; }
|
||||
@Override
|
||||
public Vec3d setX(double x) { return this.x == x ? this : Vec3d.of(x, y, z); }
|
||||
public Vec3d x(double x) { return this.x == x ? this : Vec3d.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3d setY(double y) { return this.y == y ? this : Vec3d.of(x, y, z); }
|
||||
public Vec3d y(double y) { return this.y == y ? this : Vec3d.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3d setZ(double z) { return this.z == z ? this : Vec3d.of(x, y, z); }
|
||||
public Vec3d z(double z) { return this.z == z ? this : Vec3d.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3d copy() { return Vec3d.of(this); }
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public class Vec3dImmutable implements Vec3d {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3d) {
|
||||
Vec3d vec = (Vec3d)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,26 +28,26 @@ public class Vec3dMutable implements Vec3d {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public double getX() { return x; }
|
||||
public double x() { return x; }
|
||||
@Override
|
||||
public double getY() { return y; }
|
||||
public double y() { return y; }
|
||||
@Override
|
||||
public double getZ() { return z; }
|
||||
public double z() { return z; }
|
||||
|
||||
@Override
|
||||
public Vec3d setX(double x) {
|
||||
public Vec3d x(double x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d setY(double y) {
|
||||
public Vec3d y(double y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d setZ(double z) {
|
||||
public Vec3d z(double z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class Vec3dMutable implements Vec3d {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3d) {
|
||||
Vec3d vec = (Vec3d)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,154 +18,154 @@ public interface Vec4d extends Vecd {
|
||||
public static Vec4d mutable() { return new Vec4dMutable(); }
|
||||
public static Vec4d mutable(double value) { return new Vec4dMutable(value); }
|
||||
public static Vec4d mutable(double x, double y, double z, double w) { return new Vec4dMutable(x, y, z, w); }
|
||||
public static Vec4d mutable(Vec4d vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4d mutable(Vec4d vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
public static Vec4d of() { return new Vec4dImmutable(); }
|
||||
public static Vec4d of(double value) { return new Vec4dImmutable(value); }
|
||||
public static Vec4d of(double x, double y, double z, double w) { return new Vec4dImmutable(x, y, z, w); }
|
||||
public static Vec4d of(Vec4d vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4d of(Vec4d vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
|
||||
public double getX();
|
||||
public double getY();
|
||||
public double getZ();
|
||||
public double getW();
|
||||
public Vec4d setX(double x);
|
||||
public Vec4d setY(double y);
|
||||
public Vec4d setZ(double z);
|
||||
public Vec4d setW(double w);
|
||||
public double x();
|
||||
public double y();
|
||||
public double z();
|
||||
public double w();
|
||||
public Vec4d x(double x);
|
||||
public Vec4d y(double y);
|
||||
public Vec4d z(double z);
|
||||
public Vec4d w(double w);
|
||||
|
||||
@Override
|
||||
public default double[] asArray() { return new double[] {getX(), getY(), getZ(), getW()}; }
|
||||
public default double[] asArray() { return new double[] {x(), y(), z(), w()}; }
|
||||
@Override
|
||||
public Vec4d copy();
|
||||
@Override
|
||||
public default Vec4d abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
|
||||
public default Vec4d abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z()), Math.abs(w())); }
|
||||
@Override
|
||||
public default Vec4d negate() { return set(0D, 0D, 0D, 0D); }
|
||||
@Override
|
||||
public default Vec4d invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
|
||||
public default Vec4d invert() { return set(-x(), -y(), -z(), -w()); }
|
||||
public default Vec4d normalize() {
|
||||
double l = length();
|
||||
return l == 0D ? this : multiply(1.0D / l);
|
||||
}
|
||||
public default Vec4d normalize3D() {
|
||||
double value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
|
||||
double value = (x() * x()) + (y() * y()) + (z() * z());
|
||||
return value == 0D ? this : multiply(1D / value);
|
||||
}
|
||||
@Override
|
||||
public default Vec4d add(double value) { return add(value, value, value, value); }
|
||||
public default Vec4d add(Vec4d value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4d add(double x, double y, double z, double w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
|
||||
public default Vec4d add(Vec4d value) { return add(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4d add(double x, double y, double z, double w) { return set(x() + x, y() + y, z() + z, w() + w); }
|
||||
@Override
|
||||
public default Vec4d sub(double value) { return sub(value, value, value, value); }
|
||||
public default Vec4d sub(Vec4d value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4d sub(double x, double y, double z, double w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4d sub(Vec4d value) { return sub(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4d sub(double x, double y, double z, double w) { return set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4d multiply(double value) { return multiply(value, value, value, value); }
|
||||
public default Vec4d multiply(Vec4d value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4d multiply(double x, double y, double z, double w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
|
||||
public default Vec4d multiply(Vec4d value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4d multiply(double x, double y, double z, double w) { return set(x() * x, y() * y, z() * z, w() * w); }
|
||||
@Override
|
||||
public default Vec4d devide(double value) { return devide(value, value, value, value); }
|
||||
public default Vec4d devide(Vec4d value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4d devide(double x, double y, double z, double w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
|
||||
public default Vec4d devide(Vec4d value) { return devide(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4d devide(double x, double y, double z, double w) { return set(x() / x, y() / y, z() / z, w() / w); }
|
||||
@Override
|
||||
public default Vec4d set(double value) { return set(value, value, value, value); }
|
||||
public default Vec4d set(Vec4d value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4d set(Vec4d value) { return set(value.x(), value.y(), value.z(), value.w()); }
|
||||
public Vec4d set(double x, double y, double z, double w);
|
||||
|
||||
public default double distanceTo(Vec4d value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceTo(Vec4d value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceTo(double x, double y, double z, double w) { return Math.sqrt(distanceTo(x, y, z, w)); }
|
||||
public default double distanceToSquared(Vec4d value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceToSquared(Vec4d value) { return distanceToSquared(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceToSquared(double x, double y, double z, double w) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double zPos = getZ() - z;
|
||||
double wPos = getW() - w;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
double zPos = z() - z;
|
||||
double wPos = w() - w;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default double lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
|
||||
public default double dotProduct(Vec4d value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double dotProduct(double x, double y, double z, double w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
|
||||
public default Vec4d lerp(Vec4d value, float progress, Vec4d result) { return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
|
||||
public default Vec4d lerp(double x, double y, double z, double w, float progress, Vec4d result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress)); }
|
||||
public default double angle(Vec4d value) { return angle(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
|
||||
public default double dotProduct(Vec4d value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double dotProduct(double x, double y, double z, double w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
|
||||
public default Vec4d lerp(Vec4d value, float progress, Vec4d result) { return lerp(value.x(), value.y(), value.z(), value.w(), progress, result); }
|
||||
public default Vec4d lerp(double x, double y, double z, double w, float progress, Vec4d result) { return result.set(MathUtils.lerp(x(), x, progress), MathUtils.lerp(y(), y, progress), MathUtils.lerp(z(), z, progress), MathUtils.lerp(w(), w, progress)); }
|
||||
public default double angle(Vec4d value) { return angle(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double angle(double x, double y, double z, double w) { return Math.acos(MathUtils.clamp(-1D, 1D, angleCos(x, y, z, w))); }
|
||||
public default double angleCos(Vec4d value) { return angleCos(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double angleCos(Vec4d value) { return angleCos(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double angleCos(double x, double y, double z, double w) { return dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w)); }
|
||||
public default Vec4d rotate(double angle, Vec4d axis) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW()); }
|
||||
public default Vec4d rotate(double angle, Vec4d axis, Vec4d result) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result); }
|
||||
public default Vec4d rotate(double angle, Vec4d axis) { return rotate(angle, axis.x(), axis.y(), axis.z(), axis.w()); }
|
||||
public default Vec4d rotate(double angle, Vec4d axis, Vec4d result) { return rotate(angle, axis.x(), axis.y(), axis.z(), axis.w(), result); }
|
||||
public default Vec4d rotate(double angle, double x, double y, double z, double w) { return rotate(angle, x, y, z, w, this); }
|
||||
public default Vec4d rotate(double angle, double x, double y, double z, double w, Vec4d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double dot = dotProduct(x, y, z, w);
|
||||
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
|
||||
return result.set(xPos, yPos, zPos, getW());
|
||||
double xPos = x * dot * (1D - cos) + (x() * cos) + (-z * y() + y * z()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (y() * cos) + (z * x() - x * z()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (z() * cos) + (-y * x() + x * y()) * sin;
|
||||
return result.set(xPos, yPos, zPos, w());
|
||||
}
|
||||
|
||||
public default Vec4d rotateX(double angle) { return rotateX(angle, this); }
|
||||
public default Vec4d rotateX(double angle, Vec4d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double y = getY() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getY() * sin;
|
||||
return result.set(getX(), y, z, getW());
|
||||
double y = y() * cos + z() * sin;
|
||||
double z = z() * cos - y() * sin;
|
||||
return result.set(x(), y, z, w());
|
||||
}
|
||||
|
||||
public default Vec4d rotateY(double angle) { return rotateY(angle, this); }
|
||||
public default Vec4d rotateY(double angle, Vec4d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = getX() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getX() * sin;
|
||||
return result.set(x, getY(), z, getW());
|
||||
double x = x() * cos + z() * sin;
|
||||
double z = z() * cos - x() * sin;
|
||||
return result.set(x, y(), z, w());
|
||||
}
|
||||
|
||||
public default Vec4d rotateZ(double angle) { return rotateZ(angle, this); }
|
||||
public default Vec4d rotateZ(double angle, Vec4d result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = cos * getX() - sin * getY();
|
||||
double y = sin * getX() + cos * getY();
|
||||
return result.set(x, y, getZ(), getW());
|
||||
double x = cos * x() - sin * y();
|
||||
double y = sin * x() + cos * y();
|
||||
return result.set(x, y, z(), w());
|
||||
}
|
||||
|
||||
public default Vec4d smoothStep(Vec4d value, float progress, Vec4d result) { return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
|
||||
public default Vec4d smoothStep(Vec4d value, float progress, Vec4d result) { return smoothStep(value.x(), value.y(), value.z(), value.w(), progress, result); }
|
||||
public default Vec4d smoothStep(double x, double y, double z, double w, float progress, Vec4d result) {
|
||||
double t2 = progress * progress;
|
||||
double t3 = t2 * progress;
|
||||
double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX());
|
||||
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY());
|
||||
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ());
|
||||
double wPos = ((getW() + getW() - w - w) * t3 + (3.0D * w - 3.0D * getW()) * t2 + getW() * progress + getW());
|
||||
double xPos = ((x() + x() - x - x) * t3 + (3.0D * x - 3.0D * x()) * t2 + x() * progress + x());
|
||||
double yPos = ((y() + y() - y - y) * t3 + (3.0D * y - 3.0D * y()) * t2 + y() * progress + y());
|
||||
double zPos = ((z() + z() - z - z) * t3 + (3.0D * z - 3.0D * z()) * t2 + z() * progress + z());
|
||||
double wPos = ((w() + w() - w - w) * t3 + (3.0D * w - 3.0D * w()) * t2 + w() * progress + w());
|
||||
return result.set(xPos, yPos, zPos, wPos);
|
||||
}
|
||||
|
||||
public default Vec4d min(Vec4d other) { return min(other, this); }
|
||||
public default Vec4d min(Vec4d other, Vec4d result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4d min(Vec4d other, Vec4d result) { return min(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4d min(double x, double y, double z, double w) { return min(x, y, z, w, this); }
|
||||
public default Vec4d min(double x, double y, double z, double w, Vec4d result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
|
||||
public default Vec4d min(double x, double y, double z, double w, Vec4d result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z), Math.min(w(), w)); }
|
||||
public default Vec4d max(Vec4d other) { return max(other, this); }
|
||||
public default Vec4d max(Vec4d other, Vec4d result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4d max(Vec4d other, Vec4d result) { return max(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4d max(double x, double y, double z, double w) { return max(x, y, z, w, this); }
|
||||
public default Vec4d max(double x, double y, double z, double w, Vec4d result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
|
||||
public default Vec4d max(double x, double y, double z, double w, Vec4d result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z), Math.max(z(), z)); }
|
||||
public default Vec4d difference(Vec4d other) { return difference(other, this); }
|
||||
public default Vec4d difference(Vec4d other, Vec4d result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4d difference(Vec4d other, Vec4d result) { return difference(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4d difference(double x, double y, double z, double w) { return difference(x, y, z, w, this); }
|
||||
public default Vec4d difference(double x, double y, double z, double w, Vec4d result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4d difference(double x, double y, double z, double w, Vec4d result) { return result.set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4d clamp(double min, double max) { return clamp(min, max, ALL); }
|
||||
public default Vec4d clamp(double min, double max, Vec4d result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec4d clamp(double min, double max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec4d clamp(double min, double max, Vec4d result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
|
||||
public default Vec4d clamp(double min, double max, Vec4d result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
|
||||
|
||||
@Override
|
||||
public default Vec4d store(ByteBuffer buffer) {
|
||||
buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ()).putDouble(getW());
|
||||
buffer.putDouble(x()).putDouble(y()).putDouble(z()).putDouble(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -174,22 +174,22 @@ public interface Vec4d extends Vecd {
|
||||
|
||||
@Override
|
||||
public default Vec4d store(DoubleBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
|
||||
buffer.put(x()).put(y()).put(z()).put(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec4d load(DoubleBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())); }
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z()), (byte)MathUtils.floor(w())) : Vec4b.of((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z()), (byte)MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())); }
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z()), (short)MathUtils.floor(w())) : Vec4s.of((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z()), (short)MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())) : Vec4i.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())) : Vec4l.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable((float)getX(), (float)getY(), (float)getZ(), (float)getW()) : Vec4f.of((float)getX(), (float)getY(), (float)getZ(), (float)getW()); }
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable((float)x(), (float)y(), (float)z(), (float)w()) : Vec4f.of((float)x(), (float)y(), (float)z(), (float)w()); }
|
||||
@Override
|
||||
public default Vec4d asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -32,21 +32,21 @@ public class Vec4dImmutable implements Vec4d {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public double getX() { return x; }
|
||||
public double x() { return x; }
|
||||
@Override
|
||||
public double getY() { return y; }
|
||||
public double y() { return y; }
|
||||
@Override
|
||||
public double getZ() { return z; }
|
||||
public double z() { return z; }
|
||||
@Override
|
||||
public double getW() { return w; }
|
||||
public double w() { return w; }
|
||||
@Override
|
||||
public Vec4d setX(double x) { return this.x == x ? this : Vec4d.of(x, y, z, w); }
|
||||
public Vec4d x(double x) { return this.x == x ? this : Vec4d.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4d setY(double y) { return this.y == y ? this : Vec4d.of(x, y, z, w); }
|
||||
public Vec4d y(double y) { return this.y == y ? this : Vec4d.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4d setZ(double z) { return this.z == z ? this : Vec4d.of(x, y, z, w); }
|
||||
public Vec4d z(double z) { return this.z == z ? this : Vec4d.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4d setW(double w) { return this.w == w ? this : Vec4d.of(x, y, z, w); }
|
||||
public Vec4d w(double w) { return this.w == w ? this : Vec4d.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4d copy() { return Vec4d.of(this); }
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Vec4dImmutable implements Vec4d {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4d) {
|
||||
Vec4d vec = (Vec4d)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,34 +27,34 @@ public class Vec4dMutable implements Vec4d {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public double getX() { return x; }
|
||||
public double x() { return x; }
|
||||
@Override
|
||||
public double getY() { return y; }
|
||||
public double y() { return y; }
|
||||
@Override
|
||||
public double getZ() { return z; }
|
||||
public double z() { return z; }
|
||||
@Override
|
||||
public double getW() { return w; }
|
||||
public double w() { return w; }
|
||||
|
||||
@Override
|
||||
public Vec4d setX(double x) {
|
||||
public Vec4d x(double x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4d setY(double y) {
|
||||
public Vec4d y(double y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4d setZ(double z) {
|
||||
public Vec4d z(double z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4d setW(double w) {
|
||||
public Vec4d w(double w) {
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class Vec4dMutable implements Vec4d {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4d) {
|
||||
Vec4d vec = (Vec4d)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,27 +18,27 @@ public interface Vec2f extends Vecf {
|
||||
public static Vec2f mutable() { return new Vec2fMutable(); }
|
||||
public static Vec2f mutable(float value) { return new Vec2fMutable(value); }
|
||||
public static Vec2f mutable(float x, float y) { return new Vec2fMutable(x, y); }
|
||||
public static Vec2f mutable(Vec2f value) { return mutable(value.getX(), value.getY()); }
|
||||
public static Vec2f mutable(Vec2f value) { return mutable(value.x(), value.y()); }
|
||||
public static Vec2f of() { return new Vec2fImmutable(); }
|
||||
public static Vec2f of(float value) { return new Vec2fImmutable(value); }
|
||||
public static Vec2f of(float x, float y) { return new Vec2fImmutable(x, y); }
|
||||
public static Vec2f of(Vec2f value) { return of(value.getX(), value.getY()); }
|
||||
public static Vec2f of(Vec2f value) { return of(value.x(), value.y()); }
|
||||
|
||||
public float getX();
|
||||
public float getY();
|
||||
public Vec2f setX(float x);
|
||||
public Vec2f setY(float y);
|
||||
public float x();
|
||||
public float y();
|
||||
public Vec2f x(float x);
|
||||
public Vec2f y(float y);
|
||||
|
||||
@Override
|
||||
public default float[] asArray() { return new float[] {getX(), getY()}; }
|
||||
public default float[] asArray() { return new float[] {x(), y()}; }
|
||||
@Override
|
||||
public Vec2f copy();
|
||||
@Override
|
||||
public default Vec2f abs() { return set(Math.abs(getX()), Math.abs(getY())); }
|
||||
public default Vec2f abs() { return set(Math.abs(x()), Math.abs(y())); }
|
||||
@Override
|
||||
public default Vec2f negate() { return set(0F, 0F); }
|
||||
@Override
|
||||
public default Vec2f invert() { return set(-getX(), -getY()); };
|
||||
public default Vec2f invert() { return set(-x(), -y()); };
|
||||
public default Vec2f normalize() {
|
||||
float l = length();
|
||||
return l == 0F ? this : multiply(1F / l);
|
||||
@@ -46,83 +46,83 @@ public interface Vec2f extends Vecf {
|
||||
|
||||
@Override
|
||||
public default Vec2f add(float value) { return add(value, value); }
|
||||
public default Vec2f add(Vec2f value) { return add(value.getX(), value.getY()); }
|
||||
public default Vec2f add(float x, float y) { return set(x + getX(), y + getY()); }
|
||||
public default Vec2f add(Vec2f value) { return add(value.x(), value.y()); }
|
||||
public default Vec2f add(float x, float y) { return set(x + x(), y + y()); }
|
||||
@Override
|
||||
public default Vec2f sub(float value) { return sub(value, value); }
|
||||
public default Vec2f sub(Vec2f value) { return sub(value.getX(), value.getY()); }
|
||||
public default Vec2f sub(float x, float y) { return set(getX() - x, getY() - y); }
|
||||
public default Vec2f sub(Vec2f value) { return sub(value.x(), value.y()); }
|
||||
public default Vec2f sub(float x, float y) { return set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2f multiply(float value) { return multiply(value, value); }
|
||||
public default Vec2f multiply(Vec2f value) { return multiply(value.getX(), value.getY()); }
|
||||
public default Vec2f multiply(float x, float y) { return set(x * getX(), y * getY()); }
|
||||
public default Vec2f multiply(Vec2f value) { return multiply(value.x(), value.y()); }
|
||||
public default Vec2f multiply(float x, float y) { return set(x * x(), y * y()); }
|
||||
@Override
|
||||
public default Vec2f devide(float value) { return devide(value, value); }
|
||||
public default Vec2f devide(Vec2f value) { return devide(value.getX(), value.getY()); }
|
||||
public default Vec2f devide(float x, float y) { return set(getX() / x, getY() / y); }
|
||||
public default Vec2f devide(Vec2f value) { return devide(value.x(), value.y()); }
|
||||
public default Vec2f devide(float x, float y) { return set(x() / x, y() / y); }
|
||||
@Override
|
||||
public default Vec2f set(float value) { return set(value, value); };
|
||||
public default Vec2f set(Vec2f value) { return set(value.getX(), value.getY()); }
|
||||
public default Vec2f set(Vec2f value) { return set(value.x(), value.y()); }
|
||||
public Vec2f set(float x, float y);
|
||||
public default double distanceTo(Vec2f value) { return distanceTo(value.getX(), value.getY()); }
|
||||
public default double distanceTo(Vec2f value) { return distanceTo(value.x(), value.y()); }
|
||||
public default double distanceTo(float x, float y) { return Math.sqrt(distanceToSquared(x, y)); }
|
||||
public default double distanceToSquared(Vec2f value) { return distanceToSquared(value.getX(), value.getY()); }
|
||||
public default double distanceToSquared(Vec2f value) { return distanceToSquared(value.x(), value.y()); }
|
||||
public default double distanceToSquared(float x, float y) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
return (xPos * xPos) + (yPos * yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default float lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
|
||||
public default double dotProduct(Vec2f value) { return dotProduct(value.getX(), value.getY()); }
|
||||
public default double dotProduct(float x, float y) { return (getX() * x) + (getY() * y); }
|
||||
public default Vec2f lerp(Vec2f value, float progress, Vec2f result) { return lerp(value.getX(), value.getY(), progress, result); }
|
||||
public default Vec2f lerp(float x, float y, float progress, Vec2f result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress)); };
|
||||
public default float angle(Vec2f value) { return angle(value.getX(), value.getY()); }
|
||||
public default float angle(float x, float y) { return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y)); }
|
||||
public default float directionAngle(Vec2f value) { return directionAngle(value.getX(), value.getY()); }
|
||||
public default float directionAngle(float x, float y) { return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D); }
|
||||
public default Vec2f reflect(Vec2f value) { return reflect(value.getX(), value.getY(), this); }
|
||||
public default float lengthSquared() { return (x() * x()) + (y() * y()); }
|
||||
public default double dotProduct(Vec2f value) { return dotProduct(value.x(), value.y()); }
|
||||
public default double dotProduct(float x, float y) { return (x() * x) + (y() * y); }
|
||||
public default Vec2f lerp(Vec2f value, float progress, Vec2f result) { return lerp(value.x(), value.y(), progress, result); }
|
||||
public default Vec2f lerp(float x, float y, float progress, Vec2f result) { return result.set(MathUtils.lerp(x(), x, progress), MathUtils.lerp(y(), y, progress)); };
|
||||
public default float angle(Vec2f value) { return angle(value.x(), value.y()); }
|
||||
public default float angle(float x, float y) { return (float)Math.atan2((x() * y) - (y() * x), (x() * x) + (y() * y)); }
|
||||
public default float directionAngle(Vec2f value) { return directionAngle(value.x(), value.y()); }
|
||||
public default float directionAngle(float x, float y) { return (float)(-Math.toDegrees(Math.atan2(x() - x, y() - y)) % 360D); }
|
||||
public default Vec2f reflect(Vec2f value) { return reflect(value.x(), value.y(), this); }
|
||||
public default Vec2f reflect(float x, float y) { return reflect(x, y, this); };
|
||||
public default Vec2f reflect(Vec2f value, Vec2f result) { return reflect(value.getX(), value.getY(), result); }
|
||||
public default Vec2f reflect(Vec2f value, Vec2f result) { return reflect(value.x(), value.y(), result); }
|
||||
public default Vec2f reflect(float x, float y, Vec2f result) {
|
||||
double dot = dotProduct(x, y);
|
||||
float x2 = (float)((dot + dot) * x);
|
||||
float y2 = (float)((dot + dot) * y);
|
||||
return result.set(getX() - x2, getY() - y2);
|
||||
return result.set(x() - x2, y() - y2);
|
||||
}
|
||||
|
||||
public default Vec2f rotate(float angle, Vec2f center) { return rotate(angle, center.getX(), center.getY()); }
|
||||
public default Vec2f rotate(float angle, Vec2f center) { return rotate(angle, center.x(), center.y()); }
|
||||
public default Vec2f rotate(float angle, float x, float y) {
|
||||
float xPos = getX() - x;
|
||||
float yPos = getY() - y;
|
||||
float xPos = x() - x;
|
||||
float yPos = y() - y;
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y));
|
||||
}
|
||||
|
||||
public default Vec2f min(Vec2f other) { return min(other, this); }
|
||||
public default Vec2f min(Vec2f other, Vec2f result) { return min(other.getX(), other.getY(), result); }
|
||||
public default Vec2f min(Vec2f other, Vec2f result) { return min(other.x(), other.y(), result); }
|
||||
public default Vec2f min(float x, float y) { return min(x, y, this); }
|
||||
public default Vec2f min(float x, float y, Vec2f result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
|
||||
public default Vec2f min(float x, float y, Vec2f result) { return result.set(Math.min(x(), x), Math.min(y(), y)); }
|
||||
public default Vec2f max(Vec2f other) { return max(other, this); }
|
||||
public default Vec2f max(Vec2f other, Vec2f result) { return max(other.getX(), other.getY(), result); }
|
||||
public default Vec2f max(Vec2f other, Vec2f result) { return max(other.x(), other.y(), result); }
|
||||
public default Vec2f max(float x, float y) { return max(x, y, this); }
|
||||
public default Vec2f max(float x, float y, Vec2f result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
|
||||
public default Vec2f max(float x, float y, Vec2f result) { return result.set(Math.max(x(), x), Math.max(y(), y)); }
|
||||
public default Vec2f difference(Vec2f other) { return difference(other, this); }
|
||||
public default Vec2f difference(Vec2f other, Vec2f result) { return difference(other.getX(), other.getY(), result); }
|
||||
public default Vec2f difference(Vec2f other, Vec2f result) { return difference(other.x(), other.y(), result); }
|
||||
public default Vec2f difference(float x, float y) { return difference(x, y, this); }
|
||||
public default Vec2f difference(float x, float y, Vec2f result) { return result.set(getX() - x, getY() - y); }
|
||||
public default Vec2f difference(float x, float y, Vec2f result) { return result.set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2f clamp(float min, float max) { return clamp(min, max, ALL); }
|
||||
public default Vec2f clamp(float min, float max, Vec2f result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec2f clamp(float min, float max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec2f clamp(float min, float max, Vec2f result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
|
||||
public default Vec2f clamp(float min, float max, Vec2f result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
|
||||
@Override
|
||||
public default Vec2f store(ByteBuffer buffer) {
|
||||
buffer.putFloat(getX()).putFloat(getY());
|
||||
buffer.putFloat(x()).putFloat(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -130,22 +130,22 @@ public interface Vec2f extends Vecf {
|
||||
public default Vec2f load(ByteBuffer buffer) { return set(buffer.getFloat(), buffer.getFloat()); }
|
||||
@Override
|
||||
public default Vec2f store(FloatBuffer buffer) {
|
||||
buffer.put(getX()).put(getY());
|
||||
buffer.put(x()).put(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec2f load(FloatBuffer buffer) { return set(buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())); }
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y())) : Vec2b.of((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())); }
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)MathUtils.floor(x()), (short)MathUtils.floor(y())) : Vec2s.of((short)MathUtils.floor(x()), (short)MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(MathUtils.floor(x()), MathUtils.floor(y())) : Vec2i.of(MathUtils.floor(x()), MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(MathUtils.floor(x()), MathUtils.floor(y())) : Vec2l.of(MathUtils.floor(x()), MathUtils.floor(y())); }
|
||||
@Override
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(x(), y()) : Vec2d.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2f asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Vec2fImmutable implements Vec2f {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public float getX() { return x; }
|
||||
public float x() { return x; }
|
||||
@Override
|
||||
public float getY() { return y; }
|
||||
public float y() { return y; }
|
||||
@Override
|
||||
public Vec2f setX(float x) { return this.x == x ? this : Vec2f.of(x, y); }
|
||||
public Vec2f x(float x) { return this.x == x ? this : Vec2f.of(x, y); }
|
||||
@Override
|
||||
public Vec2f setY(float y) { return this.y == y ? this : Vec2f.of(x, y); }
|
||||
public Vec2f y(float y) { return this.y == y ? this : Vec2f.of(x, y); }
|
||||
@Override
|
||||
public Vec2f copy() { return Vec2f.of(x, y); }
|
||||
@Override
|
||||
@@ -43,7 +43,7 @@ public class Vec2fImmutable implements Vec2f {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2f) {
|
||||
Vec2f vec = (Vec2f)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ public class Vec2fMutable implements Vec2f {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public float getX() { return x; }
|
||||
public float x() { return x; }
|
||||
@Override
|
||||
public float getY() { return y; }
|
||||
public float y() { return y; }
|
||||
|
||||
@Override
|
||||
public Vec2f setX(float x) {
|
||||
public Vec2f x(float x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2f setY(float y) {
|
||||
public Vec2f y(float y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class Vec2fMutable implements Vec2f {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2f) {
|
||||
Vec2f vec = (Vec2f)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import speiger.src.coreengine.math.vector.bytes.Vec3b;
|
||||
import speiger.src.coreengine.math.vector.doubles.Vec3d;
|
||||
import speiger.src.coreengine.math.vector.ints.Vec3i;
|
||||
import speiger.src.coreengine.math.vector.longs.Vec3l;
|
||||
import speiger.src.coreengine.math.vector.matrix.Matrix4f;
|
||||
import speiger.src.coreengine.math.vector.shorts.Vec3s;
|
||||
|
||||
public interface Vec3f extends Vecf {
|
||||
@@ -18,29 +19,29 @@ public interface Vec3f extends Vecf {
|
||||
public static Vec3f mutable() { return new Vec3fMutable(); }
|
||||
public static Vec3f mutable(float value) { return new Vec3fMutable(value); }
|
||||
public static Vec3f mutable(float x, float y, float z) { return new Vec3fMutable(x, y, z); }
|
||||
public static Vec3f mutable(Vec3f vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3f mutable(Vec3f vec) { return mutable(vec.x(), vec.y(), vec.z()); }
|
||||
public static Vec3f of() { return new Vec3fImmutable(); }
|
||||
public static Vec3f of(float value) { return new Vec3fImmutable(value); }
|
||||
public static Vec3f of(float x, float y, float z) { return new Vec3fImmutable(x, y, z); }
|
||||
public static Vec3f of(Vec3f vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3f of(Vec3f vec) { return of(vec.x(), vec.y(), vec.z()); }
|
||||
|
||||
public float getX();
|
||||
public float getY();
|
||||
public float getZ();
|
||||
public Vec3f setX(float x);
|
||||
public Vec3f setY(float y);
|
||||
public Vec3f setZ(float z);
|
||||
public float x();
|
||||
public float y();
|
||||
public float z();
|
||||
public Vec3f x(float x);
|
||||
public Vec3f y(float y);
|
||||
public Vec3f z(float z);
|
||||
|
||||
@Override
|
||||
public default float[] asArray() { return new float[] {getX(), getY(), getZ()}; }
|
||||
public default float[] asArray() { return new float[] {x(), y(), z()}; }
|
||||
@Override
|
||||
public Vec3f copy();
|
||||
@Override
|
||||
public default Vec3f abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
|
||||
public default Vec3f abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z())); }
|
||||
@Override
|
||||
public default Vec3f negate() { return set(0F, 0F, 0F); }
|
||||
@Override
|
||||
public default Vec3f invert() { return set(-getX(), -getY(), -getZ()); }
|
||||
public default Vec3f invert() { return set(-x(), -y(), -z()); }
|
||||
public default Vec3f normalize() {
|
||||
float l = length();
|
||||
return l == 0F ? this : multiply(1.0F / l);
|
||||
@@ -48,72 +49,72 @@ public interface Vec3f extends Vecf {
|
||||
|
||||
@Override
|
||||
public default Vec3f add(float value) { return add(value, value, value); }
|
||||
public default Vec3f add(Vec3f value) { return add(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3f add(float x, float y, float z) { return set(getX() + x, getY() + y, getZ() + z); }
|
||||
public default Vec3f add(Vec3f value) { return add(value.x(), value.y(), value.z()); }
|
||||
public default Vec3f add(float x, float y, float z) { return set(x() + x, y() + y, z() + z); }
|
||||
@Override
|
||||
public default Vec3f sub(float value) { return sub(value, value, value); }
|
||||
public default Vec3f sub(Vec3f value) { return sub(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3f sub(float x, float y, float z) { return set(getX() - x, getY() - y, getZ() - z); }
|
||||
public default Vec3f sub(Vec3f value) { return sub(value.x(), value.y(), value.z()); }
|
||||
public default Vec3f sub(float x, float y, float z) { return set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3f multiply(float value) { return multiply(value, value, value); }
|
||||
public default Vec3f multiply(Vec3f value) { return multiply(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3f multiply(float x, float y, float z) { return set(getX() * x, getY() * y, getZ() * z); }
|
||||
public default Vec3f multiply(Vec3f value) { return multiply(value.x(), value.y(), value.z()); }
|
||||
public default Vec3f multiply(float x, float y, float z) { return set(x() * x, y() * y, z() * z); }
|
||||
@Override
|
||||
public default Vec3f devide(float value) { return devide(value, value, value); }
|
||||
public default Vec3f devide(Vec3f value) { return devide(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3f devide(float x, float y, float z) { return set(getX() / x, getY() / y, getZ() / z); }
|
||||
public default Vec3f devide(Vec3f value) { return devide(value.x(), value.y(), value.z()); }
|
||||
public default Vec3f devide(float x, float y, float z) { return set(x() / x, y() / y, z() / z); }
|
||||
@Override
|
||||
public default Vec3f set(float value) { return set(value, value, value); }
|
||||
public default Vec3f set(Vec3f value) { return set(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3f set(Vec3f value) { return set(value.x(), value.y(), value.z()); }
|
||||
public Vec3f set(float x, float y, float z);
|
||||
public default double distanceTo(Vec3f value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
|
||||
public default double distanceTo(Vec3f value) { return distanceTo(value.x(), value.y(), value.z()); }
|
||||
public default double distanceTo(float x, float y, float z) { return Math.sqrt(distanceToSquared(x, y, z)); }
|
||||
public default double distanceToSquared(Vec3f value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
|
||||
public default double distanceToSquared(Vec3f value) { return distanceToSquared(value.x(), value.y(), value.z()); }
|
||||
public default double distanceToSquared(float x, float y, float z) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double zPos = getZ() - z;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
double zPos = z() - z;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default float lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
|
||||
public default double dotProduct(Vec3f value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
|
||||
public default double dotProduct(float x, float y, float z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
|
||||
public default Vec3f lerp(Vec3f value, float progress, Vec3f result) { return lerp(value.getX(), value.getY(), value.getZ(), progress, result); }
|
||||
public default Vec3f lerp(float x, float y, float z, float progress, Vec3f result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress)); }
|
||||
public default float angle(Vec3f value) { return angle(value.getX(), value.getY(), value.getZ()); }
|
||||
public default float lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
|
||||
public default double dotProduct(Vec3f value) { return dotProduct(value.x(), value.y(), value.z()); }
|
||||
public default double dotProduct(float x, float y, float z) { return (x() * x) + (y() * y) + (z() * z); }
|
||||
public default Vec3f lerp(Vec3f value, float progress, Vec3f result) { return lerp(value.x(), value.y(), value.z(), progress, result); }
|
||||
public default Vec3f lerp(float x, float y, float z, float progress, Vec3f result) { return result.set(MathUtils.lerp(x(), x, progress), MathUtils.lerp(y(), y, progress), MathUtils.lerp(z(), z, progress)); }
|
||||
public default float angle(Vec3f value) { return angle(value.x(), value.y(), value.z()); }
|
||||
public default float angle(float x, float y, float z) { return (float)Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z))); }
|
||||
public default float angleCos(Vec3f value) { return angleCos(value.getX(), value.getY(), value.getZ()); }
|
||||
public default float angleCos(Vec3f value) { return angleCos(value.x(), value.y(), value.z()); }
|
||||
public default float angleCos(float x, float y, float z) {
|
||||
double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
|
||||
double myLength = (x() * x()) + (y() * y()) + (z() * z());
|
||||
double otherLength = (x * x) + (y * y) + (z * z);
|
||||
float dot = (getX() * x) + (getY() * y) + (getZ() * z);
|
||||
float dot = (x() * x) + (y() * y) + (z() * z);
|
||||
return dot / (float)(Math.sqrt(myLength * otherLength));
|
||||
}
|
||||
|
||||
public default Vec3f crossProduct(Vec3f value) { return crossProduct(value.getX(), value.getY(), value.getZ(), this); }
|
||||
public default Vec3f crossProduct(Vec3f value, Vec3f result) { return crossProduct(value.getX(), value.getY(), value.getZ(), result); }
|
||||
public default Vec3f crossProduct(Vec3f value) { return crossProduct(value.x(), value.y(), value.z(), this); }
|
||||
public default Vec3f crossProduct(Vec3f value, Vec3f result) { return crossProduct(value.x(), value.y(), value.z(), result); }
|
||||
public default Vec3f crossProduct(float x, float y, float z) { return crossProduct(x, y, z, this); }
|
||||
public default Vec3f crossProduct(float x, float y, float z, Vec3f result) { return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x)); }
|
||||
public default Vec3f reflect(Vec3f value) { return reflect(value.getX(), value.getY(), value.getZ(), this); }
|
||||
public default Vec3f reflect(Vec3f value, Vec3f result) { return reflect(value.getX(), value.getY(), value.getZ(), result); }
|
||||
public default Vec3f crossProduct(float x, float y, float z, Vec3f result) { return result.set((y() * z) - (z() * y), (z() * x) - (x() * z), (x() * y) - (y() * x)); }
|
||||
public default Vec3f reflect(Vec3f value) { return reflect(value.x(), value.y(), value.z(), this); }
|
||||
public default Vec3f reflect(Vec3f value, Vec3f result) { return reflect(value.x(), value.y(), value.z(), result); }
|
||||
public default Vec3f reflect(float x, float y, float z) { return reflect(x, y, z, this); }
|
||||
public default Vec3f reflect(float x, float y, float z, Vec3f result) {
|
||||
double dot = dotProduct(x, y, z) * 2D;
|
||||
return result.set(getX() - (float)(dot * x), getY() - (float)(dot * y), getZ() - (float)(dot * z));
|
||||
return result.set(x() - (float)(dot * x), y() - (float)(dot * y), z() - (float)(dot * z));
|
||||
}
|
||||
|
||||
public default Vec3f rotate(float angle, Vec3f axis) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ()); }
|
||||
public default Vec3f rotate(float angle, Vec3f axis, Vec3f result) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result); }
|
||||
public default Vec3f rotate(float angle, Vec3f axis) { return rotate(angle, axis.x(), axis.y(), axis.z()); }
|
||||
public default Vec3f rotate(float angle, Vec3f axis, Vec3f result) { return rotate(angle, axis.x(), axis.y(), axis.z(), result); }
|
||||
public default Vec3f rotate(float angle, float x, float y, float z) { return rotate(angle, x, y, z, this); }
|
||||
public default Vec3f rotate(float angle, float x, float y, float z, Vec3f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double dot = dotProduct(x, y, z);
|
||||
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
|
||||
double xPos = x * dot * (1D - cos) + (x() * cos) + (-z * y() + y * z()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (y() * cos) + (z * x() - x * z()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (z() * cos) + (-y * x() + x * y()) * sin;
|
||||
return result.set((float)xPos, (float)yPos, (float)zPos);
|
||||
}
|
||||
|
||||
@@ -121,61 +122,85 @@ public interface Vec3f extends Vecf {
|
||||
public default Vec3f rotateX(float angle, Vec3f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double y = getY() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getY() * sin;
|
||||
return result.set(getX(), (float)y, (float)z);
|
||||
double y = y() * cos + z() * sin;
|
||||
double z = z() * cos - y() * sin;
|
||||
return result.set(x(), (float)y, (float)z);
|
||||
}
|
||||
|
||||
public default Vec3f rotateY(float angle) { return rotateY(angle, this); }
|
||||
public default Vec3f rotateY(float angle, Vec3f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = getX() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getX() * sin;
|
||||
return result.set((float)x, getY(), (float)z);
|
||||
double x = x() * cos + z() * sin;
|
||||
double z = z() * cos - x() * sin;
|
||||
return result.set((float)x, y(), (float)z);
|
||||
}
|
||||
|
||||
public default Vec3f rotateZ(float angle) { return rotateZ(angle, this); }
|
||||
public default Vec3f rotateZ(float angle, Vec3f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = cos * getX() - sin * getY();
|
||||
double y = sin * getX() + cos * getY();
|
||||
return result.set((float)x, (float)y, getZ());
|
||||
double x = cos * x() - sin * y();
|
||||
double y = sin * x() + cos * y();
|
||||
return result.set((float)x, (float)y, z());
|
||||
}
|
||||
|
||||
public default Vec3f smoothStep(Vec3f value, float progress, Vec3f result) { return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result); }
|
||||
public default Vec3f transform(Matrix4f matrix) { return transform(matrix, true, this); }
|
||||
public default Vec3f transofrm(Matrix4f matrix, boolean pos) { return transform(matrix, pos, this); }
|
||||
public default Vec3f transform(Matrix4f matrix, boolean pos, Vec3f result) {
|
||||
if((matrix.properties() & Matrix4f.PROPERTY_IDENTITY) != 0) {
|
||||
return result.set(this);
|
||||
}
|
||||
if((matrix.properties() & Matrix4f.PROPERTY_ROTATION) != 0) {
|
||||
float w = pos ? 1F : 0F;
|
||||
return result.set(
|
||||
matrix.fma(Matrix4f.M00, Matrix4f.M10, Matrix4f.M20, Matrix4f.M30, x(), y(), z(), w),
|
||||
matrix.fma(Matrix4f.M01, Matrix4f.M11, Matrix4f.M21, Matrix4f.M31, x(), y(), z(), w),
|
||||
matrix.fma(Matrix4f.M02, Matrix4f.M12, Matrix4f.M22, Matrix4f.M32, x(), y(), z(), w));
|
||||
}
|
||||
if((matrix.properties() & Matrix4f.PROPERTY_SCALE) != 0) {
|
||||
if(pos) return set(
|
||||
Math.fma(matrix.get(Matrix4f.M00), x(), matrix.get(Matrix4f.M30)),
|
||||
Math.fma(matrix.get(Matrix4f.M01), y(), matrix.get(Matrix4f.M31)),
|
||||
Math.fma(matrix.get(Matrix4f.M02), z(), matrix.get(Matrix4f.M32)));
|
||||
return set(matrix.get(Matrix4f.M00) * x(), matrix.get(Matrix4f.M01) * y(), matrix.get(Matrix4f.M02) * z());
|
||||
}
|
||||
if(pos) return set(x() + matrix.get(Matrix4f.M30), y() + matrix.get(Matrix4f.M31), z() + matrix.get(Matrix4f.M32));
|
||||
return result.set(this);
|
||||
}
|
||||
|
||||
public default Vec3f smoothStep(Vec3f value, float progress, Vec3f result) { return smoothStep(value.x(), value.y(), value.z(), progress, result); }
|
||||
public default Vec3f smoothStep(float x, float y, float z, float progress, Vec3f result) {
|
||||
float t2 = progress * progress;
|
||||
float t3 = t2 * progress;
|
||||
float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX());
|
||||
float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY());
|
||||
float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
|
||||
float xPos = ((x() + x() - x - x) * t3 + (3.0F * x - 3.0F * x()) * t2 + x() * progress + x());
|
||||
float yPos = ((y() + y() - y - y) * t3 + (3.0F * y - 3.0F * y()) * t2 + y() * progress + y());
|
||||
float zPos = ((z() + z() - z - z) * t3 + (3.0F * z - 3.0F * z()) * t2 + z() * progress + z());
|
||||
return result.set(xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
public default Vec3f min(Vec3f other) { return min(other, this); }
|
||||
public default Vec3f min(Vec3f other, Vec3f result) { return min(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3f min(Vec3f other, Vec3f result) { return min(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3f min(float x, float y, float z) { return min(x, y, z, this); }
|
||||
public default Vec3f min(float x, float y, float z, Vec3f result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z)); }
|
||||
public default Vec3f min(float x, float y, float z, Vec3f result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z)); }
|
||||
public default Vec3f max(Vec3f other) { return max(other, this); }
|
||||
public default Vec3f max(Vec3f other, Vec3f result) { return max(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3f max(Vec3f other, Vec3f result) { return max(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3f max(float x, float y, float z) { return max(x, y, z, this); }
|
||||
public default Vec3f max(float x, float y, float z, Vec3f result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z)); }
|
||||
public default Vec3f max(float x, float y, float z, Vec3f result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z)); }
|
||||
public default Vec3f difference(Vec3f other) { return difference(other, this); }
|
||||
public default Vec3f difference(Vec3f other, Vec3f result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3f difference(Vec3f other, Vec3f result) { return difference(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3f difference(float x, float y, float z) { return difference(x, y, z, this); }
|
||||
public default Vec3f difference(float x, float y, float z, Vec3f result) { return result.set(getX() - x, getY() - y, getZ() - z); }
|
||||
public default Vec3f difference(float x, float y, float z, Vec3f result) { return result.set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3f clamp(float min, float max) { return clamp(min, max, ALL); }
|
||||
public default Vec3f clamp(float min, float max, Vec3f result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec3f clamp(float min, float max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec3f clamp(float min, float max, Vec3f result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
|
||||
public default Vec3f clamp(float min, float max, Vec3f result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
|
||||
|
||||
@Override
|
||||
public default Vec3f store(ByteBuffer buffer) {
|
||||
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ());
|
||||
buffer.putFloat(x()).putFloat(y()).putFloat(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -184,22 +209,22 @@ public interface Vec3f extends Vecf {
|
||||
|
||||
@Override
|
||||
public default Vec3f store(FloatBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ());
|
||||
buffer.put(x()).put(y()).put(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec3f load(FloatBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())); }
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z())) : Vec3b.of((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())); }
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z())) : Vec3s.of((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())); }
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())) : Vec3i.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())); }
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())) : Vec3l.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z())); }
|
||||
@Override
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(x(), y(), z()) : Vec3d.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3f asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -28,17 +28,17 @@ public class Vec3fImmutable implements Vec3f {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public float getX() { return x; }
|
||||
public float x() { return x; }
|
||||
@Override
|
||||
public float getY() { return y; }
|
||||
public float y() { return y; }
|
||||
@Override
|
||||
public float getZ() { return z; }
|
||||
public float z() { return z; }
|
||||
@Override
|
||||
public Vec3f setX(float x) { return this.x == x ? this : Vec3f.of(x, y, z); }
|
||||
public Vec3f x(float x) { return this.x == x ? this : Vec3f.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3f setY(float y) { return this.y == y ? this : Vec3f.of(x, y, z); }
|
||||
public Vec3f y(float y) { return this.y == y ? this : Vec3f.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3f setZ(float z) { return this.z == z ? this : Vec3f.of(x, y, z); }
|
||||
public Vec3f z(float z) { return this.z == z ? this : Vec3f.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3f copy() { return Vec3f.of(this); }
|
||||
@Override
|
||||
@@ -51,7 +51,7 @@ public class Vec3fImmutable implements Vec3f {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3f) {
|
||||
Vec3f vec = (Vec3f)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,26 +24,26 @@ public class Vec3fMutable implements Vec3f {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public float getX() { return x; }
|
||||
public float x() { return x; }
|
||||
@Override
|
||||
public float getY() { return y; }
|
||||
public float y() { return y; }
|
||||
@Override
|
||||
public float getZ() { return z; }
|
||||
public float z() { return z; }
|
||||
|
||||
@Override
|
||||
public Vec3f setX(float x) {
|
||||
public Vec3f x(float x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3f setY(float y) {
|
||||
public Vec3f y(float y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3f setZ(float z) {
|
||||
public Vec3f z(float z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class Vec3fMutable implements Vec3f {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3f) {
|
||||
Vec3f vec = (Vec3f)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import speiger.src.coreengine.math.vector.bytes.Vec4b;
|
||||
import speiger.src.coreengine.math.vector.doubles.Vec4d;
|
||||
import speiger.src.coreengine.math.vector.ints.Vec4i;
|
||||
import speiger.src.coreengine.math.vector.longs.Vec4l;
|
||||
import speiger.src.coreengine.math.vector.matrix.Matrix4f;
|
||||
import speiger.src.coreengine.math.vector.shorts.Vec4s;
|
||||
|
||||
public interface Vec4f extends Vecf {
|
||||
@@ -18,155 +19,177 @@ public interface Vec4f extends Vecf {
|
||||
public static Vec4f mutable() { return new Vec4fMutable(); }
|
||||
public static Vec4f mutable(float value) { return new Vec4fMutable(value); }
|
||||
public static Vec4f mutable(float x, float y, float z, float w) { return new Vec4fMutable(x, y, z, w); }
|
||||
public static Vec4f mutable(Vec4f vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4f mutable(Vec4f vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
public static Vec4f of() { return new Vec4fImmutable(); }
|
||||
public static Vec4f of(float value) { return new Vec4fImmutable(value); }
|
||||
public static Vec4f of(float x, float y, float z, float w) { return new Vec4fImmutable(x, y, z, w); }
|
||||
public static Vec4f of(Vec4f vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4f of(Vec4f vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
|
||||
public float getX();
|
||||
public float getY();
|
||||
public float getZ();
|
||||
public float getW();
|
||||
public Vec4f setX(float x);
|
||||
public Vec4f setY(float y);
|
||||
public Vec4f setZ(float z);
|
||||
public Vec4f setW(float w);
|
||||
public float x();
|
||||
public float y();
|
||||
public float z();
|
||||
public float w();
|
||||
public Vec4f x(float x);
|
||||
public Vec4f y(float y);
|
||||
public Vec4f z(float z);
|
||||
public Vec4f w(float w);
|
||||
|
||||
@Override
|
||||
public default float[] asArray() { return new float[] {getX(), getY(), getZ(), getW()}; }
|
||||
public default float[] asArray() { return new float[] {x(), y(), z(), w()}; }
|
||||
@Override
|
||||
public Vec4f copy();
|
||||
@Override
|
||||
public default Vec4f abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
|
||||
public default Vec4f abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z()), Math.abs(w())); }
|
||||
@Override
|
||||
public default Vec4f negate() { return set(0F, 0F, 0F, 0F); }
|
||||
@Override
|
||||
public default Vec4f invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
|
||||
public default Vec4f invert() { return set(-x(), -y(), -z(), -w()); }
|
||||
public default Vec4f normalize() {
|
||||
float l = length();
|
||||
return l == 0F ? this : multiply(1.0F / l);
|
||||
}
|
||||
|
||||
public default Vec4f normalize3D() {
|
||||
float value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
|
||||
float value = (x() * x()) + (y() * y()) + (z() * z());
|
||||
return value == 0F ? this : multiply(1F / value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec4f add(float value) { return add(value, value, value, value); }
|
||||
public default Vec4f add(Vec4f value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4f add(float x, float y, float z, float w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
|
||||
public default Vec4f add(Vec4f value) { return add(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4f add(float x, float y, float z, float w) { return set(x() + x, y() + y, z() + z, w() + w); }
|
||||
@Override
|
||||
public default Vec4f sub(float value) { return sub(value, value, value, value); }
|
||||
public default Vec4f sub(Vec4f value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4f sub(float x, float y, float z, float w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4f sub(Vec4f value) { return sub(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4f sub(float x, float y, float z, float w) { return set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4f multiply(float value) { return multiply(value, value, value, value); }
|
||||
public default Vec4f multiply(Vec4f value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4f multiply(float x, float y, float z, float w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
|
||||
public default Vec4f multiply(Vec4f value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4f multiply(float x, float y, float z, float w) { return set(x() * x, y() * y, z() * z, w() * w); }
|
||||
@Override
|
||||
public default Vec4f devide(float value) { return devide(value, value, value, value); }
|
||||
public default Vec4f devide(Vec4f value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4f devide(float x, float y, float z, float w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
|
||||
public default Vec4f devide(Vec4f value) { return devide(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4f devide(float x, float y, float z, float w) { return set(x() / x, y() / y, z() / z, w() / w); }
|
||||
@Override
|
||||
public default Vec4f set(float value) { return set(value, value, value, value); }
|
||||
public default Vec4f set(Vec4f value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4f set(Vec4f value) { return set(value.x(), value.y(), value.z(), value.w()); }
|
||||
public Vec4f set(float x, float y, float z, float w);
|
||||
public default double distanceTo(Vec4f value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceTo(Vec4f value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceTo(float x, float y, float z, float w) { return Math.sqrt(distanceTo(x, y, z, w)); }
|
||||
public default double distanceToSquared(Vec4f value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceToSquared(Vec4f value) { return distanceToSquared(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceToSquared(float x, float y, float z, float w) {
|
||||
double xPos = getX() - x;
|
||||
double yPos = getY() - y;
|
||||
double zPos = getZ() - z;
|
||||
double wPos = getW() - w;
|
||||
double xPos = x() - x;
|
||||
double yPos = y() - y;
|
||||
double zPos = z() - z;
|
||||
double wPos = w() - w;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default float lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
|
||||
public default double dotProduct(Vec4f value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double dotProduct(float x, float y, float z, float w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
|
||||
public default Vec4f lerp(Vec4f value, float progress, Vec4f result) { return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
|
||||
public default Vec4f lerp(float x, float y, float z, float w, float progress, Vec4f result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress)); }
|
||||
public default float angle(Vec4f value) { return angle(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default float lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
|
||||
public default double dotProduct(Vec4f value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double dotProduct(float x, float y, float z, float w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
|
||||
public default Vec4f lerp(Vec4f value, float progress, Vec4f result) { return lerp(value.x(), value.y(), value.z(), value.w(), progress, result); }
|
||||
public default Vec4f lerp(float x, float y, float z, float w, float progress, Vec4f result) { return result.set(MathUtils.lerp(x(), x, progress), MathUtils.lerp(y(), y, progress), MathUtils.lerp(z(), z, progress), MathUtils.lerp(w(), w, progress)); }
|
||||
public default float angle(Vec4f value) { return angle(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default float angle(float x, float y, float z, float w) { return (float)Math.acos(MathUtils.clamp(-1F, 1F, angleCos(x, y, z, w))); }
|
||||
public default float angleCos(Vec4f value) { return angleCos(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default float angleCos(Vec4f value) { return angleCos(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default float angleCos(float x, float y, float z, float w) { return (float)(dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w))); }
|
||||
public default Vec4f rotate(float angle, Vec4f axis) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW()); }
|
||||
public default Vec4f rotate(float angle, Vec4f axis, Vec4f result) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result); }
|
||||
public default Vec4f rotate(float angle, Vec4f axis) { return rotate(angle, axis.x(), axis.y(), axis.z(), axis.w()); }
|
||||
public default Vec4f rotate(float angle, Vec4f axis, Vec4f result) { return rotate(angle, axis.x(), axis.y(), axis.z(), axis.w(), result); }
|
||||
public default Vec4f rotate(float angle, float x, float y, float z, float w) { return rotate(angle, x, y, z, w, this); }
|
||||
public default Vec4f rotate(float angle, float x, float y, float z, float w, Vec4f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double dot = dotProduct(x, y, z, w);
|
||||
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
|
||||
return result.set((float)xPos, (float)yPos, (float)zPos, getW());
|
||||
double xPos = x * dot * (1D - cos) + (x() * cos) + (-z * y() + y * z()) * sin;
|
||||
double yPos = y * dot * (1D - cos) + (y() * cos) + (z * x() - x * z()) * sin;
|
||||
double zPos = z * dot * (1D - cos) + (z() * cos) + (-y * x() + x * y()) * sin;
|
||||
return result.set((float)xPos, (float)yPos, (float)zPos, w());
|
||||
}
|
||||
|
||||
public default Vec4f rotateX(float angle) { return rotateX(angle, this); }
|
||||
public default Vec4f rotateX(float angle, Vec4f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double y = getY() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getY() * sin;
|
||||
return result.set(getX(), (float)y, (float)z, getW());
|
||||
double y = y() * cos + z() * sin;
|
||||
double z = z() * cos - y() * sin;
|
||||
return result.set(x(), (float)y, (float)z, w());
|
||||
}
|
||||
|
||||
public default Vec4f rotateY(float angle) { return rotateY(angle, this); }
|
||||
public default Vec4f rotateY(float angle, Vec4f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = getX() * cos + getZ() * sin;
|
||||
double z = getZ() * cos - getX() * sin;
|
||||
return result.set((float)x, getY(), (float)z, getW());
|
||||
double x = x() * cos + z() * sin;
|
||||
double z = z() * cos - x() * sin;
|
||||
return result.set((float)x, y(), (float)z, w());
|
||||
}
|
||||
|
||||
public default Vec4f rotateZ(float angle) { return rotateZ(angle, this); }
|
||||
public default Vec4f rotateZ(float angle, Vec4f result) {
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
double x = cos * getX() - sin * getY();
|
||||
double y = sin * getX() + cos * getY();
|
||||
return result.set((float)x, (float)y, getZ(), getW());
|
||||
double x = cos * x() - sin * y();
|
||||
double y = sin * x() + cos * y();
|
||||
return result.set((float)x, (float)y, z(), w());
|
||||
}
|
||||
|
||||
public default Vec4f smoothStep(Vec4f value, float progress, Vec4f result) { return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
|
||||
public default Vec4f transform(Matrix4f matrix) { return transform(matrix, this); }
|
||||
public default Vec4f transform(Matrix4f matrix, Vec4f result) {
|
||||
if((matrix.properties() & Matrix4f.PROPERTY_IDENTITY) != 0) {
|
||||
return result.set(this);
|
||||
}
|
||||
if((matrix.properties() & Matrix4f.PROPERTY_ROTATION) != 0) {
|
||||
return result.set(
|
||||
matrix.fma(Matrix4f.M00, Matrix4f.M10, Matrix4f.M20, Matrix4f.M30, x(), y(), z(), w()),
|
||||
matrix.fma(Matrix4f.M01, Matrix4f.M11, Matrix4f.M21, Matrix4f.M31, x(), y(), z(), w()),
|
||||
matrix.fma(Matrix4f.M02, Matrix4f.M12, Matrix4f.M22, Matrix4f.M32, x(), y(), z(), w()),
|
||||
matrix.fma(Matrix4f.M03, Matrix4f.M13, Matrix4f.M23, Matrix4f.M33, x(), y(), z(), w()));
|
||||
}
|
||||
if((matrix.properties() & Matrix4f.PROPERTY_SCALE) != 0) {
|
||||
return set(
|
||||
Math.fma(matrix.get(Matrix4f.M00), x(), matrix.get(Matrix4f.M30)),
|
||||
Math.fma(matrix.get(Matrix4f.M01), y(), matrix.get(Matrix4f.M31)),
|
||||
Math.fma(matrix.get(Matrix4f.M02), z(), matrix.get(Matrix4f.M32)),
|
||||
Math.fma(matrix.get(Matrix4f.M03), w(), matrix.get(Matrix4f.M33)));
|
||||
}
|
||||
return set(x() + matrix.get(Matrix4f.M30), y() + matrix.get(Matrix4f.M31), z() + matrix.get(Matrix4f.M32), w() + matrix.get(Matrix4f.M33));
|
||||
}
|
||||
|
||||
public default Vec4f smoothStep(Vec4f value, float progress, Vec4f result) { return smoothStep(value.x(), value.y(), value.z(), value.w(), progress, result); }
|
||||
public default Vec4f smoothStep(float x, float y, float z, float w, float progress, Vec4f result) {
|
||||
float t2 = progress * progress;
|
||||
float t3 = t2 * progress;
|
||||
float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX());
|
||||
float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY());
|
||||
float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
|
||||
float wPos = ((getW() + getW() - w - w) * t3 + (3.0F * w - 3.0F * getW()) * t2 + getW() * progress + getW());
|
||||
float xPos = ((x() + x() - x - x) * t3 + (3.0F * x - 3.0F * x()) * t2 + x() * progress + x());
|
||||
float yPos = ((y() + y() - y - y) * t3 + (3.0F * y - 3.0F * y()) * t2 + y() * progress + y());
|
||||
float zPos = ((z() + z() - z - z) * t3 + (3.0F * z - 3.0F * z()) * t2 + z() * progress + z());
|
||||
float wPos = ((w() + w() - w - w) * t3 + (3.0F * w - 3.0F * w()) * t2 + w() * progress + w());
|
||||
return result.set(xPos, yPos, zPos, wPos);
|
||||
}
|
||||
|
||||
public default Vec4f min(Vec4f other) { return min(other, this); }
|
||||
public default Vec4f min(Vec4f other, Vec4f result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4f min(Vec4f other, Vec4f result) { return min(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4f min(float x, float y, float z, float w) { return min(x, y, z, w, this); }
|
||||
public default Vec4f min(float x, float y, float z, float w, Vec4f result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
|
||||
public default Vec4f min(float x, float y, float z, float w, Vec4f result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z), Math.min(w(), w)); }
|
||||
public default Vec4f max(Vec4f other) { return max(other, this); }
|
||||
public default Vec4f max(Vec4f other, Vec4f result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4f max(Vec4f other, Vec4f result) { return max(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4f max(float x, float y, float z, float w) { return max(x, y, z, w, this); }
|
||||
public default Vec4f max(float x, float y, float z, float w, Vec4f result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
|
||||
public default Vec4f max(float x, float y, float z, float w, Vec4f result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z), Math.max(z(), z)); }
|
||||
public default Vec4f difference(Vec4f other) { return difference(other, this); }
|
||||
public default Vec4f difference(Vec4f other, Vec4f result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4f difference(Vec4f other, Vec4f result) { return difference(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4f difference(float x, float y, float z, float w) { return difference(x, y, z, w, this); }
|
||||
public default Vec4f difference(float x, float y, float z, float w, Vec4f result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4f difference(float x, float y, float z, float w, Vec4f result) { return result.set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4f clamp(float min, float max) { return clamp(min, max, ALL); }
|
||||
public default Vec4f clamp(float min, float max, Vec4f result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec4f clamp(float min, float max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec4f clamp(float min, float max, Vec4f result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
|
||||
public default Vec4f clamp(float min, float max, Vec4f result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
|
||||
|
||||
@Override
|
||||
public default Vec4f store(ByteBuffer buffer) {
|
||||
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW());
|
||||
buffer.putFloat(x()).putFloat(y()).putFloat(z()).putFloat(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -175,7 +198,7 @@ public interface Vec4f extends Vecf {
|
||||
|
||||
@Override
|
||||
public default Vec4f store(FloatBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
|
||||
buffer.put(x()).put(y()).put(z()).put(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -183,15 +206,15 @@ public interface Vec4f extends Vecf {
|
||||
public default Vec4f load(FloatBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
|
||||
@Override
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())); }
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z()), (byte)MathUtils.floor(w())) : Vec4b.of((byte)MathUtils.floor(x()), (byte)MathUtils.floor(y()), (byte)MathUtils.floor(z()), (byte)MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())); }
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z()), (short)MathUtils.floor(w())) : Vec4s.of((short)MathUtils.floor(x()), (short)MathUtils.floor(y()), (short)MathUtils.floor(z()), (short)MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())) : Vec4i.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())) : Vec4l.of(MathUtils.floor(x()), MathUtils.floor(y()), MathUtils.floor(z()), MathUtils.floor(w())); }
|
||||
@Override
|
||||
public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(x(), y(), z(), w()) : Vec4d.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4f asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -32,21 +32,21 @@ public class Vec4fImmutable implements Vec4f {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public float getX() { return x; }
|
||||
public float x() { return x; }
|
||||
@Override
|
||||
public float getY() { return y; }
|
||||
public float y() { return y; }
|
||||
@Override
|
||||
public float getZ() { return z; }
|
||||
public float z() { return z; }
|
||||
@Override
|
||||
public float getW() { return w; }
|
||||
public float w() { return w; }
|
||||
@Override
|
||||
public Vec4f setX(float x) { return this.x == x ? this : Vec4f.of(x, y, z, w); }
|
||||
public Vec4f x(float x) { return this.x == x ? this : Vec4f.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4f setY(float y) { return this.y == y ? this : Vec4f.of(x, y, z, w); }
|
||||
public Vec4f y(float y) { return this.y == y ? this : Vec4f.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4f setZ(float z) { return this.z == z ? this : Vec4f.of(x, y, z, w); }
|
||||
public Vec4f z(float z) { return this.z == z ? this : Vec4f.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4f setW(float w) { return this.w == w ? this : Vec4f.of(x, y, z, w); }
|
||||
public Vec4f w(float w) { return this.w == w ? this : Vec4f.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4f copy() { return Vec4f.of(this); }
|
||||
@Override
|
||||
@@ -58,7 +58,7 @@ public class Vec4fImmutable implements Vec4f {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4f) {
|
||||
Vec4f vec = (Vec4f)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -32,34 +32,34 @@ public class Vec4fMutable implements Vec4f {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public float getX() { return x; }
|
||||
public float x() { return x; }
|
||||
@Override
|
||||
public float getY() { return y; }
|
||||
public float y() { return y; }
|
||||
@Override
|
||||
public float getZ() { return z; }
|
||||
public float z() { return z; }
|
||||
@Override
|
||||
public float getW() { return w; }
|
||||
public float w() { return w; }
|
||||
|
||||
@Override
|
||||
public Vec4f setX(float x) {
|
||||
public Vec4f x(float x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4f setY(float y) {
|
||||
public Vec4f y(float y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4f setZ(float z) {
|
||||
public Vec4f z(float z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4f setW(float w) {
|
||||
public Vec4f w(float w) {
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class Vec4fMutable implements Vec4f {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4f) {
|
||||
Vec4f vec = (Vec4f)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,91 +18,91 @@ public interface Vec2i extends Veci {
|
||||
public static Vec2i mutable() { return new Vec2iMutable(); }
|
||||
public static Vec2i mutable(int value) { return new Vec2iMutable(value); }
|
||||
public static Vec2i mutable(int x, int y) { return new Vec2iMutable(x, y); }
|
||||
public static Vec2i mutable(Vec2i value) { return mutable(value.getX(), value.getY()); }
|
||||
public static Vec2i mutable(Vec2i value) { return mutable(value.x(), value.y()); }
|
||||
public static Vec2i of() { return new Vec2iImmutable(); }
|
||||
public static Vec2i of(int value) { return new Vec2iImmutable(value); }
|
||||
public static Vec2i of(int x, int y) { return new Vec2iImmutable(x, y); }
|
||||
public static Vec2i of(Vec2i value) { return of(value.getX(), value.getY()); }
|
||||
public static Vec2i of(Vec2i value) { return of(value.x(), value.y()); }
|
||||
|
||||
public int getX();
|
||||
public int getY();
|
||||
public Vec2i setX(int x);
|
||||
public Vec2i setY(int y);
|
||||
public int x();
|
||||
public int y();
|
||||
public Vec2i x(int x);
|
||||
public Vec2i y(int y);
|
||||
|
||||
@Override
|
||||
public default int[] asArray() { return new int[] {getX(), getY()}; }
|
||||
public default int[] asArray() { return new int[] {x(), y()}; }
|
||||
@Override
|
||||
public Vec2i copy();
|
||||
@Override
|
||||
public default Vec2i abs() { return set(Math.abs(getX()), Math.abs(getY())); }
|
||||
public default Vec2i abs() { return set(Math.abs(x()), Math.abs(y())); }
|
||||
@Override
|
||||
public default Vec2i negate() { return set(0, 0); }
|
||||
@Override
|
||||
public default Vec2i invert() { return set(-getX(), -getY()); };
|
||||
public default Vec2i invert() { return set(-x(), -y()); };
|
||||
@Override
|
||||
public default Vec2i add(int value) { return add(value, value); }
|
||||
public default Vec2i add(Vec2i value) { return add(value.getX(), value.getY()); }
|
||||
public default Vec2i add(int x, int y) { return set(x + getX(), y + getY()); }
|
||||
public default Vec2i add(Vec2i value) { return add(value.x(), value.y()); }
|
||||
public default Vec2i add(int x, int y) { return set(x + x(), y + y()); }
|
||||
@Override
|
||||
public default Vec2i sub(int value) { return sub(value, value); }
|
||||
public default Vec2i sub(Vec2i value) { return sub(value.getX(), value.getY()); }
|
||||
public default Vec2i sub(int x, int y) { return set(getX() - x, getY() - y); }
|
||||
public default Vec2i sub(Vec2i value) { return sub(value.x(), value.y()); }
|
||||
public default Vec2i sub(int x, int y) { return set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2i multiply(int value) { return multiply(value, value); }
|
||||
public default Vec2i multiply(Vec2i value) { return multiply(value.getX(), value.getY()); }
|
||||
public default Vec2i multiply(int x, int y) { return set(x * getX(), y * getY()); }
|
||||
public default Vec2i multiply(Vec2i value) { return multiply(value.x(), value.y()); }
|
||||
public default Vec2i multiply(int x, int y) { return set(x * x(), y * y()); }
|
||||
@Override
|
||||
public default Vec2i devide(int value) { return devide(value, value); }
|
||||
public default Vec2i devide(Vec2i value) { return devide(value.getX(), value.getY()); }
|
||||
public default Vec2i devide(int x, int y) { return set(getX() / x, getY() / y); }
|
||||
public default Vec2i devide(Vec2i value) { return devide(value.x(), value.y()); }
|
||||
public default Vec2i devide(int x, int y) { return set(x() / x, y() / y); }
|
||||
@Override
|
||||
public default Vec2i set(int value) { return set(value, value); };
|
||||
public default Vec2i set(Vec2i value) { return set(value.getX(), value.getY()); }
|
||||
public default Vec2i set(Vec2i value) { return set(value.x(), value.y()); }
|
||||
public Vec2i set(int x, int y);
|
||||
public default double distanceTo(Vec2i value) { return distanceTo(value.getX(), value.getY()); }
|
||||
public default double distanceTo(Vec2i value) { return distanceTo(value.x(), value.y()); }
|
||||
public default double distanceTo(int x, int y) { return Math.sqrt(distanceToSquared(x, y)); }
|
||||
public default long distanceToSquared(Vec2i value) { return distanceToSquared(value.getX(), value.getY()); }
|
||||
public default long distanceToSquared(Vec2i value) { return distanceToSquared(value.x(), value.y()); }
|
||||
public default long distanceToSquared(int x, int y) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
return (xPos * xPos) + (yPos * yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
|
||||
public default long dotProduct(Vec2i value) { return dotProduct(value.getX(), value.getY()); }
|
||||
public default long dotProduct(int x, int y) { return (getX() * x) + (getY() * y); }
|
||||
public default Vec2i rotate(int angle, Vec2i center) { return rotate(angle, center.getX(), center.getY()); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()); }
|
||||
public default long dotProduct(Vec2i value) { return dotProduct(value.x(), value.y()); }
|
||||
public default long dotProduct(int x, int y) { return (x() * x) + (y() * y); }
|
||||
public default Vec2i rotate(int angle, Vec2i center) { return rotate(angle, center.x(), center.y()); }
|
||||
public default Vec2i rotate(int angle, int x, int y) {
|
||||
int xPos = getX() - x;
|
||||
int yPos = getY() - y;
|
||||
int xPos = x() - x;
|
||||
int yPos = y() - y;
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
return set((int)((xPos * cos) + (yPos * sin) + x), (int)(-(xPos * sin) + (yPos * cos) + y));
|
||||
}
|
||||
|
||||
public default Vec2i min(Vec2i other) { return min(other, this); }
|
||||
public default Vec2i min(Vec2i other, Vec2i result) { return min(other.getX(), other.getY(), result); }
|
||||
public default Vec2i min(Vec2i other, Vec2i result) { return min(other.x(), other.y(), result); }
|
||||
public default Vec2i min(int x, int y) { return min(x, y, this); }
|
||||
public default Vec2i min(int x, int y, Vec2i result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
|
||||
public default Vec2i min(int x, int y, Vec2i result) { return result.set(Math.min(x(), x), Math.min(y(), y)); }
|
||||
public default Vec2i max(Vec2i other) { return max(other, this); }
|
||||
public default Vec2i max(Vec2i other, Vec2i result) { return max(other.getX(), other.getY(), result); }
|
||||
public default Vec2i max(Vec2i other, Vec2i result) { return max(other.x(), other.y(), result); }
|
||||
public default Vec2i max(int x, int y) { return max(x, y, this); }
|
||||
public default Vec2i max(int x, int y, Vec2i result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
|
||||
public default Vec2i max(int x, int y, Vec2i result) { return result.set(Math.max(x(), x), Math.max(y(), y)); }
|
||||
public default Vec2i difference(Vec2i other) { return difference(other, this); }
|
||||
public default Vec2i difference(Vec2i other, Vec2i result) { return difference(other.getX(), other.getY(), result); }
|
||||
public default Vec2i difference(Vec2i other, Vec2i result) { return difference(other.x(), other.y(), result); }
|
||||
public default Vec2i difference(int x, int y) { return difference(x, y, this); }
|
||||
public default Vec2i difference(int x, int y, Vec2i result) { return result.set(getX() - x, getY() - y); }
|
||||
public default Vec2i difference(int x, int y, Vec2i result) { return result.set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2i clamp(int min, int max) { return clamp(min, max, ALL); }
|
||||
public default Vec2i clamp(int min, int max, Vec2i result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec2i clamp(int min, int max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec2i clamp(int min, int max, Vec2i result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
|
||||
public default Vec2i clamp(int min, int max, Vec2i result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
|
||||
|
||||
@Override
|
||||
public default Vec2i store(ByteBuffer buffer) {
|
||||
buffer.putInt(getX()).putInt(getY());
|
||||
buffer.putInt(x()).putInt(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -111,22 +111,22 @@ public interface Vec2i extends Veci {
|
||||
|
||||
@Override
|
||||
public default Vec2i store(IntBuffer buffer) {
|
||||
buffer.put(getX()).put(getY());
|
||||
buffer.put(x()).put(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec2i load(IntBuffer buffer) { return set(buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY()); }
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)x(), (byte)y()) : Vec2b.of((byte)x(), (byte)y()); }
|
||||
@Override
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)getX(), (short)getY()) : Vec2s.of((short)getX(), (short)getY()); }
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)x(), (short)y()) : Vec2s.of((short)x(), (short)y()); }
|
||||
@Override
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY()); }
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(x(), y()) : Vec2l.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(x(), y()) : Vec2f.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(x(), y()) : Vec2d.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2i asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Vec2iImmutable implements Vec2i {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
public int x() { return x; }
|
||||
@Override
|
||||
public int getY() { return y; }
|
||||
public int y() { return y; }
|
||||
@Override
|
||||
public Vec2i setX(int x) { return this.x == x ? this : Vec2i.of(x, y); }
|
||||
public Vec2i x(int x) { return this.x == x ? this : Vec2i.of(x, y); }
|
||||
@Override
|
||||
public Vec2i setY(int y) { return this.y == y ? this : Vec2i.of(x, y); }
|
||||
public Vec2i y(int y) { return this.y == y ? this : Vec2i.of(x, y); }
|
||||
@Override
|
||||
public Vec2i copy() { return Vec2i.of(this); }
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class Vec2iImmutable implements Vec2i {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2i) {
|
||||
Vec2i vec = (Vec2i)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ public class Vec2iMutable implements Vec2i {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
public int x() { return x; }
|
||||
@Override
|
||||
public int getY() { return y; }
|
||||
public int y() { return y; }
|
||||
|
||||
@Override
|
||||
public Vec2i setX(int x) {
|
||||
public Vec2i x(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2i setY(int y) {
|
||||
public Vec2i y(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class Vec2iMutable implements Vec2i {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2i) {
|
||||
Vec2i vec = (Vec2i)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,85 +18,85 @@ public interface Vec3i extends Veci {
|
||||
public static Vec3i mutable() { return new Vec3iMutable(); }
|
||||
public static Vec3i mutable(int value) { return new Vec3iMutable(value); }
|
||||
public static Vec3i mutable(int x, int y, int z) { return new Vec3iMutable(x, y, z); }
|
||||
public static Vec3i mutable(Vec3i vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3i mutable(Vec3i vec) { return mutable(vec.x(), vec.y(), vec.z()); }
|
||||
public static Vec3i of() { return new Vec3iImmutable(); }
|
||||
public static Vec3i of(int value) { return new Vec3iImmutable(value); }
|
||||
public static Vec3i of(int x, int y, int z) { return new Vec3iImmutable(x, y, z); }
|
||||
public static Vec3i of(Vec3i vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3i of(Vec3i vec) { return of(vec.x(), vec.y(), vec.z()); }
|
||||
|
||||
public int getX();
|
||||
public int getY();
|
||||
public int getZ();
|
||||
public Vec3i setX(int x);
|
||||
public Vec3i setY(int y);
|
||||
public Vec3i setZ(int z);
|
||||
public int x();
|
||||
public int y();
|
||||
public int z();
|
||||
public Vec3i x(int x);
|
||||
public Vec3i y(int y);
|
||||
public Vec3i z(int z);
|
||||
|
||||
@Override
|
||||
public default int[] asArray() { return new int[] {getX(), getY(), getZ()}; }
|
||||
public default int[] asArray() { return new int[] {x(), y(), z()}; }
|
||||
@Override
|
||||
public Vec3i copy();
|
||||
@Override
|
||||
public default Vec3i abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
|
||||
public default Vec3i abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z())); }
|
||||
@Override
|
||||
public default Vec3i negate() { return set(0, 0, 0); }
|
||||
@Override
|
||||
public default Vec3i invert() { return set(-getX(), -getY(), -getZ()); }
|
||||
public default Vec3i invert() { return set(-x(), -y(), -z()); }
|
||||
@Override
|
||||
public default Vec3i add(int value) { return add(value, value, value); }
|
||||
public default Vec3i add(Vec3i value) { return add(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3i add(int x, int y, int z) { return set(getX() + x, getY() + y, getZ() + z); }
|
||||
public default Vec3i add(Vec3i value) { return add(value.x(), value.y(), value.z()); }
|
||||
public default Vec3i add(int x, int y, int z) { return set(x() + x, y() + y, z() + z); }
|
||||
@Override
|
||||
public default Vec3i sub(int value) { return sub(value, value, value); }
|
||||
public default Vec3i sub(Vec3i value) { return sub(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3i sub(int x, int y, int z) { return set(getX() - x, getY() - y, getZ() - z); }
|
||||
public default Vec3i sub(Vec3i value) { return sub(value.x(), value.y(), value.z()); }
|
||||
public default Vec3i sub(int x, int y, int z) { return set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3i multiply(int value) { return multiply(value, value, value); }
|
||||
public default Vec3i multiply(Vec3i value) { return multiply(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3i multiply(int x, int y, int z) { return set(getX() * x, getY() * y, getZ() * z); }
|
||||
public default Vec3i multiply(Vec3i value) { return multiply(value.x(), value.y(), value.z()); }
|
||||
public default Vec3i multiply(int x, int y, int z) { return set(x() * x, y() * y, z() * z); }
|
||||
@Override
|
||||
public default Vec3i devide(int value) { return devide(value, value, value); }
|
||||
public default Vec3i devide(Vec3i value) { return devide(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3i devide(int x, int y, int z) { return set(getX() / x, getY() / y, getZ() / z); }
|
||||
public default Vec3i devide(Vec3i value) { return devide(value.x(), value.y(), value.z()); }
|
||||
public default Vec3i devide(int x, int y, int z) { return set(x() / x, y() / y, z() / z); }
|
||||
@Override
|
||||
public default Vec3i set(int value) { return set(value, value, value); }
|
||||
public default Vec3i set(Vec3i value) { return set(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3i set(Vec3i value) { return set(value.x(), value.y(), value.z()); }
|
||||
public Vec3i set(int x, int y, int z);
|
||||
public default double distanceTo(Vec3i value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
|
||||
public default double distanceTo(Vec3i value) { return distanceTo(value.x(), value.y(), value.z()); }
|
||||
public default double distanceTo(int x, int y, int z) { return Math.sqrt(distanceToSquared(x, y, z)); }
|
||||
public default long distanceToSquared(Vec3i value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
|
||||
public default long distanceToSquared(Vec3i value) { return distanceToSquared(value.x(), value.y(), value.z()); }
|
||||
public default long distanceToSquared(int x, int y, int z) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long zPos = getZ() - z;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
long zPos = z() - z;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
|
||||
public default long dotProduct(Vec3i value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
|
||||
public default long dotProduct(int x, int y, int z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
|
||||
public default long dotProduct(Vec3i value) { return dotProduct(value.x(), value.y(), value.z()); }
|
||||
public default long dotProduct(int x, int y, int z) { return (x() * x) + (y() * y) + (z() * z); }
|
||||
public default Vec3i min(Vec3i other) { return min(other, this); }
|
||||
public default Vec3i min(Vec3i other, Vec3i result) { return min(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3i min(Vec3i other, Vec3i result) { return min(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3i min(int x, int y, int z) { return min(x, y, z, this); }
|
||||
public default Vec3i min(int x, int y, int z, Vec3i result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z)); }
|
||||
public default Vec3i min(int x, int y, int z, Vec3i result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z)); }
|
||||
public default Vec3i max(Vec3i other) { return max(other, this); }
|
||||
public default Vec3i max(Vec3i other, Vec3i result) { return max(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3i max(Vec3i other, Vec3i result) { return max(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3i max(int x, int y, int z) { return max(x, y, z, this); }
|
||||
public default Vec3i max(int x, int y, int z, Vec3i result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z)); }
|
||||
public default Vec3i max(int x, int y, int z, Vec3i result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z)); }
|
||||
public default Vec3i difference(Vec3i other) { return difference(other, this); }
|
||||
public default Vec3i difference(Vec3i other, Vec3i result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3i difference(Vec3i other, Vec3i result) { return difference(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3i difference(int x, int y, int z) { return difference(x, y, z, this); }
|
||||
public default Vec3i difference(int x, int y, int z, Vec3i result) { return result.set(getX() - x, getY() - y, getZ() - z); }
|
||||
public default Vec3i difference(int x, int y, int z, Vec3i result) { return result.set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3i clamp(int min, int max) { return clamp(min, max, ALL); }
|
||||
public default Vec3i clamp(int min, int max, Vec3i result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec3i clamp(int min, int max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec3i clamp(int min, int max, Vec3i result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
|
||||
public default Vec3i clamp(int min, int max, Vec3i result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
|
||||
|
||||
@Override
|
||||
public default Vec3i store(ByteBuffer buffer) {
|
||||
buffer.putInt(getX()).putInt(getY()).putInt(getZ());
|
||||
buffer.putInt(x()).putInt(y()).putInt(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -105,22 +105,22 @@ public interface Vec3i extends Veci {
|
||||
|
||||
@Override
|
||||
public default Vec3i store(IntBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ());
|
||||
buffer.put(x()).put(y()).put(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec3i load(IntBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ()); }
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)x(), (byte)y(), (byte)z()) : Vec3b.of((byte)x(), (byte)y(), (byte)z()); }
|
||||
@Override
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.of((short)getX(), (short)getY(), (short)getZ()); }
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)x(), (short)y(), (short)z()) : Vec3s.of((short)x(), (short)y(), (short)z()); }
|
||||
@Override
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ()); }
|
||||
public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(x(), y(), z()) : Vec3l.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(x(), y(), z()) : Vec3f.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(x(), y(), z()) : Vec3d.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3i asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -28,17 +28,17 @@ public class Vec3iImmutable implements Vec3i {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
public int x() { return x; }
|
||||
@Override
|
||||
public int getY() { return y; }
|
||||
public int y() { return y; }
|
||||
@Override
|
||||
public int getZ() { return z; }
|
||||
public int z() { return z; }
|
||||
@Override
|
||||
public Vec3i setX(int x) { return this.x == x ? this : Vec3i.of(x, y, z); }
|
||||
public Vec3i x(int x) { return this.x == x ? this : Vec3i.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3i setY(int y) { return this.y == y ? this : Vec3i.of(x, y, z); }
|
||||
public Vec3i y(int y) { return this.y == y ? this : Vec3i.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3i setZ(int z) { return this.z == z ? this : Vec3i.of(x, y, z); }
|
||||
public Vec3i z(int z) { return this.z == z ? this : Vec3i.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3i copy() { return Vec3i.of(this); }
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public class Vec3iImmutable implements Vec3i {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3i) {
|
||||
Vec3i vec = (Vec3i)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,26 +24,26 @@ public class Vec3iMutable implements Vec3i {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
public int x() { return x; }
|
||||
@Override
|
||||
public int getY() { return y; }
|
||||
public int y() { return y; }
|
||||
@Override
|
||||
public int getZ() { return z; }
|
||||
public int z() { return z; }
|
||||
|
||||
@Override
|
||||
public Vec3i setX(int x) {
|
||||
public Vec3i x(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3i setY(int y) {
|
||||
public Vec3i y(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3i setZ(int z) {
|
||||
public Vec3i z(int z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class Vec3iMutable implements Vec3i {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3i) {
|
||||
Vec3i vec = (Vec3i)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,88 +18,88 @@ public interface Vec4i extends Veci {
|
||||
public static Vec4i mutable() { return new Vec4iMutable(); }
|
||||
public static Vec4i mutable(int value) { return new Vec4iMutable(value); }
|
||||
public static Vec4i mutable(int x, int y, int z, int w) { return new Vec4iMutable(x, y, z, w); }
|
||||
public static Vec4i mutable(Vec4i vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4i mutable(Vec4i vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
public static Vec4i of() { return new Vec4iImmutable(); }
|
||||
public static Vec4i of(int value) { return new Vec4iImmutable(value); }
|
||||
public static Vec4i of(int x, int y, int z, int w) { return new Vec4iImmutable(x, y, z, w); }
|
||||
public static Vec4i of(Vec4i vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4i of(Vec4i vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
|
||||
public int getX();
|
||||
public int getY();
|
||||
public int getZ();
|
||||
public int getW();
|
||||
public Vec4i setX(int x);
|
||||
public Vec4i setY(int y);
|
||||
public Vec4i setZ(int z);
|
||||
public Vec4i setW(int w);
|
||||
public int x();
|
||||
public int y();
|
||||
public int z();
|
||||
public int w();
|
||||
public Vec4i x(int x);
|
||||
public Vec4i y(int y);
|
||||
public Vec4i z(int z);
|
||||
public Vec4i w(int w);
|
||||
|
||||
@Override
|
||||
public default int[] asArray() { return new int[] {getX(), getY(), getZ(), getW()}; }
|
||||
public default int[] asArray() { return new int[] {x(), y(), z(), w()}; }
|
||||
@Override
|
||||
public Vec4i copy();
|
||||
@Override
|
||||
public default Vec4i abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
|
||||
public default Vec4i abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z()), Math.abs(w())); }
|
||||
@Override
|
||||
public default Vec4i negate() { return set(0, 0, 0, 0); }
|
||||
@Override
|
||||
public default Vec4i invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
|
||||
public default Vec4i invert() { return set(-x(), -y(), -z(), -w()); }
|
||||
@Override
|
||||
public default Vec4i add(int value) { return add(value, value, value, value); }
|
||||
public default Vec4i add(Vec4i value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4i add(int x, int y, int z, int w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
|
||||
public default Vec4i add(Vec4i value) { return add(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4i add(int x, int y, int z, int w) { return set(x() + x, y() + y, z() + z, w() + w); }
|
||||
@Override
|
||||
public default Vec4i sub(int value) { return sub(value, value, value, value); }
|
||||
public default Vec4i sub(Vec4i value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4i sub(int x, int y, int z, int w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4i sub(Vec4i value) { return sub(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4i sub(int x, int y, int z, int w) { return set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4i multiply(int value) { return multiply(value, value, value, value); }
|
||||
public default Vec4i multiply(Vec4i value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4i multiply(int x, int y, int z, int w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
|
||||
public default Vec4i multiply(Vec4i value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4i multiply(int x, int y, int z, int w) { return set(x() * x, y() * y, z() * z, w() * w); }
|
||||
@Override
|
||||
public default Vec4i devide(int value) { return devide(value, value, value, value); }
|
||||
public default Vec4i devide(Vec4i value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4i devide(int x, int y, int z, int w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
|
||||
public default Vec4i devide(Vec4i value) { return devide(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4i devide(int x, int y, int z, int w) { return set(x() / x, y() / y, z() / z, w() / w); }
|
||||
@Override
|
||||
public default Vec4i set(int value) { return set(value, value, value, value); }
|
||||
public default Vec4i set(Vec4i value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4i set(Vec4i value) { return set(value.x(), value.y(), value.z(), value.w()); }
|
||||
public Vec4i set(int x, int y, int z, int w);
|
||||
public default double distanceTo(Vec4i value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceTo(Vec4i value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceTo(int x, int y, int z, int w) { return Math.sqrt(distanceTo(x, y, z, w)); }
|
||||
public default long distanceToSquared(Vec4i value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default long distanceToSquared(Vec4i value) { return distanceToSquared(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default long distanceToSquared(int x, int y, int z, int w) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long zPos = getZ() - z;
|
||||
long wPos = getW() - w;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
long zPos = z() - z;
|
||||
long wPos = w() - w;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
|
||||
public default long dotProduct(Vec4i value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default long dotProduct(int x, int y, int z, int w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
|
||||
public default long dotProduct(Vec4i value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default long dotProduct(int x, int y, int z, int w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
|
||||
public default Vec4i min(Vec4i other) { return min(other, this); }
|
||||
public default Vec4i min(Vec4i other, Vec4i result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4i min(Vec4i other, Vec4i result) { return min(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4i min(int x, int y, int z, int w) { return min(x, y, z, w, this); }
|
||||
public default Vec4i min(int x, int y, int z, int w, Vec4i result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
|
||||
public default Vec4i min(int x, int y, int z, int w, Vec4i result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z), Math.min(w(), w)); }
|
||||
public default Vec4i max(Vec4i other) { return max(other, this); }
|
||||
public default Vec4i max(Vec4i other, Vec4i result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4i max(Vec4i other, Vec4i result) { return max(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4i max(int x, int y, int z, int w) { return max(x, y, z, w, this); }
|
||||
public default Vec4i max(int x, int y, int z, int w, Vec4i result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
|
||||
public default Vec4i max(int x, int y, int z, int w, Vec4i result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z), Math.max(z(), z)); }
|
||||
public default Vec4i difference(Vec4i other) { return difference(other, this); }
|
||||
public default Vec4i difference(Vec4i other, Vec4i result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4i difference(Vec4i other, Vec4i result) { return difference(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4i difference(int x, int y, int z, int w) { return difference(x, y, z, w, this); }
|
||||
public default Vec4i difference(int x, int y, int z, int w, Vec4i result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4i difference(int x, int y, int z, int w, Vec4i result) { return result.set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4i clamp(int min, int max) { return clamp(min, max, ALL); }
|
||||
public default Vec4i clamp(int min, int max, Vec4i result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec4i clamp(int min, int max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec4i clamp(int min, int max, Vec4i result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
|
||||
public default Vec4i clamp(int min, int max, Vec4i result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
|
||||
|
||||
@Override
|
||||
public default Vec4i store(ByteBuffer buffer) {
|
||||
buffer.putInt(getX()).putInt(getY()).putInt(getZ()).putInt(getW());
|
||||
buffer.putInt(x()).putInt(y()).putInt(z()).putInt(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -108,22 +108,22 @@ public interface Vec4i extends Veci {
|
||||
|
||||
@Override
|
||||
public default Vec4i store(IntBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
|
||||
buffer.put(x()).put(y()).put(z()).put(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec4i load(IntBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()); }
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)x(), (byte)y(), (byte)z(), (byte)w()) : Vec4b.of((byte)x(), (byte)y(), (byte)z(), (byte)w()); }
|
||||
@Override
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.of((short)getX(), (short)getY(), (short)getZ(), (short)getW()); }
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)x(), (short)y(), (short)z(), (short)w()) : Vec4s.of((short)x(), (short)y(), (short)z(), (short)w()); }
|
||||
@Override
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(x(), y(), z(), w()) : Vec4l.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(x(), y(), z(), w()) : Vec4f.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(x(), y(), z(), w()) : Vec4d.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4i asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -32,21 +32,21 @@ public class Vec4iImmutable implements Vec4i {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
public int x() { return x; }
|
||||
@Override
|
||||
public int getY() { return y; }
|
||||
public int y() { return y; }
|
||||
@Override
|
||||
public int getZ() { return z; }
|
||||
public int z() { return z; }
|
||||
@Override
|
||||
public int getW() { return w; }
|
||||
public int w() { return w; }
|
||||
@Override
|
||||
public Vec4i setX(int x) { return this.x == x ? this : Vec4i.of(x, y, z, w); }
|
||||
public Vec4i x(int x) { return this.x == x ? this : Vec4i.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4i setY(int y) { return this.y == y ? this : Vec4i.of(x, y, z, w); }
|
||||
public Vec4i y(int y) { return this.y == y ? this : Vec4i.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4i setZ(int z) { return this.z == z ? this : Vec4i.of(x, y, z, w); }
|
||||
public Vec4i z(int z) { return this.z == z ? this : Vec4i.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4i setW(int w) { return this.w == w ? this : Vec4i.of(x, y, z, w); }
|
||||
public Vec4i w(int w) { return this.w == w ? this : Vec4i.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4i copy() { return Vec4i.of(this); }
|
||||
@Override
|
||||
@@ -58,7 +58,7 @@ public class Vec4iImmutable implements Vec4i {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4i) {
|
||||
Vec4i vec = (Vec4i)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,34 +27,34 @@ public class Vec4iMutable implements Vec4i {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public int getX() { return x; }
|
||||
public int x() { return x; }
|
||||
@Override
|
||||
public int getY() { return y; }
|
||||
public int y() { return y; }
|
||||
@Override
|
||||
public int getZ() { return z; }
|
||||
public int z() { return z; }
|
||||
@Override
|
||||
public int getW() { return w; }
|
||||
public int w() { return w; }
|
||||
|
||||
@Override
|
||||
public Vec4i setX(int x) {
|
||||
public Vec4i x(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4i setY(int y) {
|
||||
public Vec4i y(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4i setZ(int z) {
|
||||
public Vec4i z(int z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4i setW(int w) {
|
||||
public Vec4i w(int w) {
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class Vec4iMutable implements Vec4i {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4i) {
|
||||
Vec4i vec = (Vec4i)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,91 +18,91 @@ public interface Vec2l extends Vecl {
|
||||
public static Vec2l mutable() { return new Vec2lMutable(); }
|
||||
public static Vec2l mutable(long value) { return new Vec2lMutable(value); }
|
||||
public static Vec2l mutable(long x, long y) { return new Vec2lMutable(x, y); }
|
||||
public static Vec2l mutable(Vec2l value) { return mutable(value.getX(), value.getY()); }
|
||||
public static Vec2l mutable(Vec2l value) { return mutable(value.x(), value.y()); }
|
||||
public static Vec2l of() { return new Vec2lImmutable(); }
|
||||
public static Vec2l of(long value) { return new Vec2lImmutable(value); }
|
||||
public static Vec2l of(long x, long y) { return new Vec2lImmutable(x, y); }
|
||||
public static Vec2l of(Vec2l value) { return of(value.getX(), value.getY()); }
|
||||
public static Vec2l of(Vec2l value) { return of(value.x(), value.y()); }
|
||||
|
||||
public long getX();
|
||||
public long getY();
|
||||
public Vec2l setX(long x);
|
||||
public Vec2l setY(long y);
|
||||
public long x();
|
||||
public long y();
|
||||
public Vec2l x(long x);
|
||||
public Vec2l y(long y);
|
||||
|
||||
@Override
|
||||
public default long[] asArray() { return new long[] {getX(), getY()}; }
|
||||
public default long[] asArray() { return new long[] {x(), y()}; }
|
||||
@Override
|
||||
public Vec2l copy();
|
||||
@Override
|
||||
public default Vec2l abs() { return set(Math.abs(getX()), Math.abs(getY())); }
|
||||
public default Vec2l abs() { return set(Math.abs(x()), Math.abs(y())); }
|
||||
@Override
|
||||
public default Vec2l negate() { return set(0L, 0L); }
|
||||
@Override
|
||||
public default Vec2l invert() { return set(-getX(), -getY()); };
|
||||
public default Vec2l invert() { return set(-x(), -y()); };
|
||||
@Override
|
||||
public default Vec2l add(long value) { return add(value, value); }
|
||||
public default Vec2l add(Vec2l value) { return add(value.getX(), value.getY()); }
|
||||
public default Vec2l add(long x, long y) { return set(x + getX(), y + getY()); }
|
||||
public default Vec2l add(Vec2l value) { return add(value.x(), value.y()); }
|
||||
public default Vec2l add(long x, long y) { return set(x + x(), y + y()); }
|
||||
@Override
|
||||
public default Vec2l sub(long value) { return sub(value, value); }
|
||||
public default Vec2l sub(Vec2l value) { return sub(value.getX(), value.getY()); }
|
||||
public default Vec2l sub(long x, long y) { return set(getX() - x, getY() - y); }
|
||||
public default Vec2l sub(Vec2l value) { return sub(value.x(), value.y()); }
|
||||
public default Vec2l sub(long x, long y) { return set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2l multiply(long value) { return multiply(value, value); }
|
||||
public default Vec2l multiply(Vec2l value) { return multiply(value.getX(), value.getY()); }
|
||||
public default Vec2l multiply(long x, long y) { return set(x * getX(), y * getY()); }
|
||||
public default Vec2l multiply(Vec2l value) { return multiply(value.x(), value.y()); }
|
||||
public default Vec2l multiply(long x, long y) { return set(x * x(), y * y()); }
|
||||
@Override
|
||||
public default Vec2l devide(long value) { return devide(value, value); }
|
||||
public default Vec2l devide(Vec2l value) { return devide(value.getX(), value.getY()); }
|
||||
public default Vec2l devide(long x, long y) { return set(getX() / x, getY() / y); }
|
||||
public default Vec2l devide(Vec2l value) { return devide(value.x(), value.y()); }
|
||||
public default Vec2l devide(long x, long y) { return set(x() / x, y() / y); }
|
||||
@Override
|
||||
public default Vec2l set(long value) { return set(value, value); };
|
||||
public default Vec2l set(Vec2l value) { return set(value.getX(), value.getY()); }
|
||||
public default Vec2l set(Vec2l value) { return set(value.x(), value.y()); }
|
||||
public Vec2l set(long x, long y);
|
||||
public default double distanceTo(Vec2l value) { return distanceTo(value.getX(), value.getY()); }
|
||||
public default double distanceTo(Vec2l value) { return distanceTo(value.x(), value.y()); }
|
||||
public default double distanceTo(long x, long y) { return Math.sqrt(distanceToSquared(x, y)); }
|
||||
public default long distanceToSquared(Vec2l value) { return distanceToSquared(value.getX(), value.getY()); }
|
||||
public default long distanceToSquared(Vec2l value) { return distanceToSquared(value.x(), value.y()); }
|
||||
public default long distanceToSquared(long x, long y) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
return (xPos * xPos) + (yPos * yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
|
||||
public default long dotProduct(Vec2l value) { return dotProduct(value.getX(), value.getY()); }
|
||||
public default long dotProduct(long x, long y) { return (getX() * x) + (getY() * y); }
|
||||
public default Vec2l rotate(long angle, Vec2l center) { return rotate(angle, center.getX(), center.getY()); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()); }
|
||||
public default long dotProduct(Vec2l value) { return dotProduct(value.x(), value.y()); }
|
||||
public default long dotProduct(long x, long y) { return (x() * x) + (y() * y); }
|
||||
public default Vec2l rotate(long angle, Vec2l center) { return rotate(angle, center.x(), center.y()); }
|
||||
public default Vec2l rotate(long angle, long x, long y) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
return set((long)((xPos * cos) + (yPos * sin) + x), (long)(-(xPos * sin) + (yPos * cos) + y));
|
||||
}
|
||||
|
||||
public default Vec2l min(Vec2l other) { return min(other, this); }
|
||||
public default Vec2l min(Vec2l other, Vec2l result) { return min(other.getX(), other.getY(), result); }
|
||||
public default Vec2l min(Vec2l other, Vec2l result) { return min(other.x(), other.y(), result); }
|
||||
public default Vec2l min(long x, long y) { return min(x, y, this); }
|
||||
public default Vec2l min(long x, long y, Vec2l result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
|
||||
public default Vec2l min(long x, long y, Vec2l result) { return result.set(Math.min(x(), x), Math.min(y(), y)); }
|
||||
public default Vec2l max(Vec2l other) { return max(other, this); }
|
||||
public default Vec2l max(Vec2l other, Vec2l result) { return max(other.getX(), other.getY(), result); }
|
||||
public default Vec2l max(Vec2l other, Vec2l result) { return max(other.x(), other.y(), result); }
|
||||
public default Vec2l max(long x, long y) { return max(x, y, this); }
|
||||
public default Vec2l max(long x, long y, Vec2l result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
|
||||
public default Vec2l max(long x, long y, Vec2l result) { return result.set(Math.max(x(), x), Math.max(y(), y)); }
|
||||
public default Vec2l difference(Vec2l other) { return difference(other, this); }
|
||||
public default Vec2l difference(Vec2l other, Vec2l result) { return difference(other.getX(), other.getY(), result); }
|
||||
public default Vec2l difference(Vec2l other, Vec2l result) { return difference(other.x(), other.y(), result); }
|
||||
public default Vec2l difference(long x, long y) { return difference(x, y, this); }
|
||||
public default Vec2l difference(long x, long y, Vec2l result) { return result.set(getX() - x, getY() - y); }
|
||||
public default Vec2l difference(long x, long y, Vec2l result) { return result.set(x() - x, y() - y); }
|
||||
@Override
|
||||
public default Vec2l clamp(long min, long max) { return clamp(min, max, ALL); }
|
||||
public default Vec2l clamp(long min, long max, Vec2l result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec2l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec2l clamp(long min, long max, Vec2l result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
|
||||
public default Vec2l clamp(long min, long max, Vec2l result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
|
||||
|
||||
@Override
|
||||
public default Vec2l store(ByteBuffer buffer) {
|
||||
buffer.putLong(getX()).putLong(getY());
|
||||
buffer.putLong(x()).putLong(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -111,22 +111,22 @@ public interface Vec2l extends Vecl {
|
||||
|
||||
@Override
|
||||
public default Vec2l store(LongBuffer buffer) {
|
||||
buffer.put(getX()).put(getY());
|
||||
buffer.put(x()).put(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec2l load(LongBuffer buffer) { return set(buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY()); }
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)x(), (byte)y()) : Vec2b.of((byte)x(), (byte)y()); }
|
||||
@Override
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)getX(), (short)getY()) : Vec2s.of((short)getX(), (short)getY()); }
|
||||
public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)x(), (short)y()) : Vec2s.of((short)x(), (short)y()); }
|
||||
@Override
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable((int)getX(), (int)getY()) : Vec2i.of((int)getX(), (int)getY()); }
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable((int)x(), (int)y()) : Vec2i.of((int)x(), (int)y()); }
|
||||
@Override
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(x(), y()) : Vec2f.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(x(), y()) : Vec2d.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2l asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Vec2lImmutable implements Vec2l {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public long getX() { return x; }
|
||||
public long x() { return x; }
|
||||
@Override
|
||||
public long getY() { return y; }
|
||||
public long y() { return y; }
|
||||
@Override
|
||||
public Vec2l setX(long x) { return this.x == x ? this : Vec2l.of(x, y); }
|
||||
public Vec2l x(long x) { return this.x == x ? this : Vec2l.of(x, y); }
|
||||
@Override
|
||||
public Vec2l setY(long y) { return this.y == y ? this : Vec2l.of(x, y); }
|
||||
public Vec2l y(long y) { return this.y == y ? this : Vec2l.of(x, y); }
|
||||
@Override
|
||||
public Vec2l copy() { return Vec2l.of(this); }
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class Vec2lImmutable implements Vec2l {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2l) {
|
||||
Vec2l vec = (Vec2l)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ public class Vec2lMutable implements Vec2l {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public long getX() { return x; }
|
||||
public long x() { return x; }
|
||||
@Override
|
||||
public long getY() { return y; }
|
||||
public long y() { return y; }
|
||||
|
||||
@Override
|
||||
public Vec2l setX(long x) {
|
||||
public Vec2l x(long x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec2l setY(long y) {
|
||||
public Vec2l y(long y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class Vec2lMutable implements Vec2l {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2l) {
|
||||
Vec2l vec = (Vec2l)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,85 +18,85 @@ public interface Vec3l extends Vecl {
|
||||
public static Vec3l mutable() { return new Vec3lMutable(); }
|
||||
public static Vec3l mutable(long value) { return new Vec3lMutable(value); }
|
||||
public static Vec3l mutable(long x, long y, long z) { return new Vec3lMutable(x, y, z); }
|
||||
public static Vec3l mutable(Vec3l vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3l mutable(Vec3l vec) { return mutable(vec.x(), vec.y(), vec.z()); }
|
||||
public static Vec3l of() { return new Vec3lImmutable(); }
|
||||
public static Vec3l of(long value) { return new Vec3lImmutable(value); }
|
||||
public static Vec3l of(long x, long y, long z) { return new Vec3lImmutable(x, y, z); }
|
||||
public static Vec3l of(Vec3l vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
|
||||
public static Vec3l of(Vec3l vec) { return of(vec.x(), vec.y(), vec.z()); }
|
||||
|
||||
public long getX();
|
||||
public long getY();
|
||||
public long getZ();
|
||||
public Vec3l setX(long x);
|
||||
public Vec3l setY(long y);
|
||||
public Vec3l setZ(long z);
|
||||
public long x();
|
||||
public long y();
|
||||
public long z();
|
||||
public Vec3l x(long x);
|
||||
public Vec3l y(long y);
|
||||
public Vec3l z(long z);
|
||||
|
||||
@Override
|
||||
public default long[] asArray() { return new long[] {getX(), getY(), getZ()}; }
|
||||
public default long[] asArray() { return new long[] {x(), y(), z()}; }
|
||||
@Override
|
||||
public Vec3l copy();
|
||||
@Override
|
||||
public default Vec3l abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
|
||||
public default Vec3l abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z())); }
|
||||
@Override
|
||||
public default Vec3l negate() { return set(0L, 0L, 0L); }
|
||||
@Override
|
||||
public default Vec3l invert() { return set(-getX(), -getY(), -getZ()); }
|
||||
public default Vec3l invert() { return set(-x(), -y(), -z()); }
|
||||
@Override
|
||||
public default Vec3l add(long value) { return add(value, value, value); }
|
||||
public default Vec3l add(Vec3l value) { return add(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3l add(long x, long y, long z) { return set(getX() + x, getY() + y, getZ() + z); }
|
||||
public default Vec3l add(Vec3l value) { return add(value.x(), value.y(), value.z()); }
|
||||
public default Vec3l add(long x, long y, long z) { return set(x() + x, y() + y, z() + z); }
|
||||
@Override
|
||||
public default Vec3l sub(long value) { return sub(value, value, value); }
|
||||
public default Vec3l sub(Vec3l value) { return sub(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3l sub(long x, long y, long z) { return set(getX() - x, getY() - y, getZ() - z); }
|
||||
public default Vec3l sub(Vec3l value) { return sub(value.x(), value.y(), value.z()); }
|
||||
public default Vec3l sub(long x, long y, long z) { return set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3l multiply(long value) { return multiply(value, value, value); }
|
||||
public default Vec3l multiply(Vec3l value) { return multiply(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3l multiply(long x, long y, long z) { return set(getX() * x, getY() * y, getZ() * z); }
|
||||
public default Vec3l multiply(Vec3l value) { return multiply(value.x(), value.y(), value.z()); }
|
||||
public default Vec3l multiply(long x, long y, long z) { return set(x() * x, y() * y, z() * z); }
|
||||
@Override
|
||||
public default Vec3l devide(long value) { return devide(value, value, value); }
|
||||
public default Vec3l devide(Vec3l value) { return devide(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3l devide(long x, long y, long z) { return set(getX() / x, getY() / y, getZ() / z); }
|
||||
public default Vec3l devide(Vec3l value) { return devide(value.x(), value.y(), value.z()); }
|
||||
public default Vec3l devide(long x, long y, long z) { return set(x() / x, y() / y, z() / z); }
|
||||
@Override
|
||||
public default Vec3l set(long value) { return set(value, value, value); }
|
||||
public default Vec3l set(Vec3l value) { return set(value.getX(), value.getY(), value.getZ()); }
|
||||
public default Vec3l set(Vec3l value) { return set(value.x(), value.y(), value.z()); }
|
||||
public Vec3l set(long x, long y, long z);
|
||||
public default double distanceTo(Vec3l value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
|
||||
public default double distanceTo(Vec3l value) { return distanceTo(value.x(), value.y(), value.z()); }
|
||||
public default double distanceTo(long x, long y, long z) { return Math.sqrt(distanceToSquared(x, y, z)); }
|
||||
public default long distanceToSquared(Vec3l value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
|
||||
public default long distanceToSquared(Vec3l value) { return distanceToSquared(value.x(), value.y(), value.z()); }
|
||||
public default long distanceToSquared(long x, long y, long z) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long zPos = getZ() - z;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
long zPos = z() - z;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
|
||||
public default long dotProduct(Vec3l value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
|
||||
public default long dotProduct(long x, long y, long z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
|
||||
public default long dotProduct(Vec3l value) { return dotProduct(value.x(), value.y(), value.z()); }
|
||||
public default long dotProduct(long x, long y, long z) { return (x() * x) + (y() * y) + (z() * z); }
|
||||
public default Vec3l min(Vec3l other) { return min(other, this); }
|
||||
public default Vec3l min(Vec3l other, Vec3l result) { return min(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3l min(Vec3l other, Vec3l result) { return min(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3l min(long x, long y, long z) { return min(x, y, z, this); }
|
||||
public default Vec3l min(long x, long y, long z, Vec3l result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z)); }
|
||||
public default Vec3l min(long x, long y, long z, Vec3l result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z)); }
|
||||
public default Vec3l max(Vec3l other) { return max(other, this); }
|
||||
public default Vec3l max(Vec3l other, Vec3l result) { return max(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3l max(Vec3l other, Vec3l result) { return max(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3l max(long x, long y, long z) { return max(x, y, z, this); }
|
||||
public default Vec3l max(long x, long y, long z, Vec3l result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z)); }
|
||||
public default Vec3l max(long x, long y, long z, Vec3l result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z)); }
|
||||
public default Vec3l difference(Vec3l other) { return difference(other, this); }
|
||||
public default Vec3l difference(Vec3l other, Vec3l result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
|
||||
public default Vec3l difference(Vec3l other, Vec3l result) { return difference(other.x(), other.y(), other.z(), result); }
|
||||
public default Vec3l difference(long x, long y, long z) { return difference(x, y, z, this); }
|
||||
public default Vec3l difference(long x, long y, long z, Vec3l result) { return result.set(getX() - x, getY() - y, getZ() - z); }
|
||||
public default Vec3l difference(long x, long y, long z, Vec3l result) { return result.set(x() - x, y() - y, z() - z); }
|
||||
@Override
|
||||
public default Vec3l clamp(long min, long max) { return clamp(min, max, ALL); }
|
||||
public default Vec3l clamp(long min, long max, Vec3l result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec3l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec3l clamp(long min, long max, Vec3l result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
|
||||
public default Vec3l clamp(long min, long max, Vec3l result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
|
||||
|
||||
@Override
|
||||
public default Vec3l store(ByteBuffer buffer) {
|
||||
buffer.putLong(getX()).putLong(getY()).putLong(getZ());
|
||||
buffer.putLong(x()).putLong(y()).putLong(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -105,22 +105,22 @@ public interface Vec3l extends Vecl {
|
||||
|
||||
@Override
|
||||
public default Vec3l store(LongBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ());
|
||||
buffer.put(x()).put(y()).put(z());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec3l load(LongBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ()); }
|
||||
public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)x(), (byte)y(), (byte)z()) : Vec3b.of((byte)x(), (byte)y(), (byte)z()); }
|
||||
@Override
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.of((short)getX(), (short)getY(), (short)getZ()); }
|
||||
public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)x(), (short)y(), (short)z()) : Vec3s.of((short)x(), (short)y(), (short)z()); }
|
||||
@Override
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable((int)getX(), (int)getY(), (int)getZ()) : Vec3i.of((int)getX(), (int)getY(), (int)getZ()); }
|
||||
public default Vec3i asInt() { return isMutable() ? Vec3i.mutable((int)x(), (int)y(), (int)z()) : Vec3i.of((int)x(), (int)y(), (int)z()); }
|
||||
@Override
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
|
||||
public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(x(), y(), z()) : Vec3f.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
|
||||
public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(x(), y(), z()) : Vec3d.of(x(), y(), z()); }
|
||||
@Override
|
||||
public default Vec3l asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -28,17 +28,17 @@ public class Vec3lImmutable implements Vec3l {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public long getX() { return x; }
|
||||
public long x() { return x; }
|
||||
@Override
|
||||
public long getY() { return y; }
|
||||
public long y() { return y; }
|
||||
@Override
|
||||
public long getZ() { return z; }
|
||||
public long z() { return z; }
|
||||
@Override
|
||||
public Vec3l setX(long x) { return this.x == x ? this : Vec3l.of(x, y, z); }
|
||||
public Vec3l x(long x) { return this.x == x ? this : Vec3l.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3l setY(long y) { return this.y == y ? this : Vec3l.of(x, y, z); }
|
||||
public Vec3l y(long y) { return this.y == y ? this : Vec3l.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3l setZ(long z) { return this.z == z ? this : Vec3l.of(x, y, z); }
|
||||
public Vec3l z(long z) { return this.z == z ? this : Vec3l.of(x, y, z); }
|
||||
@Override
|
||||
public Vec3l copy() { return Vec3l.of(this); }
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public class Vec3lImmutable implements Vec3l {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3l) {
|
||||
Vec3l vec = (Vec3l)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,26 +24,26 @@ public class Vec3lMutable implements Vec3l {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public long getX() { return x; }
|
||||
public long x() { return x; }
|
||||
@Override
|
||||
public long getY() { return y; }
|
||||
public long y() { return y; }
|
||||
@Override
|
||||
public long getZ() { return z; }
|
||||
public long z() { return z; }
|
||||
|
||||
@Override
|
||||
public Vec3l setX(long x) {
|
||||
public Vec3l x(long x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3l setY(long y) {
|
||||
public Vec3l y(long y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3l setZ(long z) {
|
||||
public Vec3l z(long z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class Vec3lMutable implements Vec3l {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec3l) {
|
||||
Vec3l vec = (Vec3l)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,88 +18,88 @@ public interface Vec4l extends Vecl {
|
||||
public static Vec4l mutable() { return new Vec4lMutable(); }
|
||||
public static Vec4l mutable(long value) { return new Vec4lMutable(value); }
|
||||
public static Vec4l mutable(long x, long y, long z, long w) { return new Vec4lMutable(x, y, z, w); }
|
||||
public static Vec4l mutable(Vec4l vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4l mutable(Vec4l vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
public static Vec4l of() { return new Vec4lImmutable(); }
|
||||
public static Vec4l of(long value) { return new Vec4lImmutable(value); }
|
||||
public static Vec4l of(long x, long y, long z, long w) { return new Vec4lImmutable(x, y, z, w); }
|
||||
public static Vec4l of(Vec4l vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
|
||||
public static Vec4l of(Vec4l vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
|
||||
|
||||
public long getX();
|
||||
public long getY();
|
||||
public long getZ();
|
||||
public long getW();
|
||||
public Vec4l setX(long x);
|
||||
public Vec4l setY(long y);
|
||||
public Vec4l setZ(long z);
|
||||
public Vec4l setW(long w);
|
||||
public long x();
|
||||
public long y();
|
||||
public long z();
|
||||
public long w();
|
||||
public Vec4l x(long x);
|
||||
public Vec4l y(long y);
|
||||
public Vec4l z(long z);
|
||||
public Vec4l w(long w);
|
||||
|
||||
@Override
|
||||
public default long[] asArray() { return new long[] {getX(), getY(), getZ(), getW()}; }
|
||||
public default long[] asArray() { return new long[] {x(), y(), z(), w()}; }
|
||||
@Override
|
||||
public Vec4l copy();
|
||||
@Override
|
||||
public default Vec4l abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
|
||||
public default Vec4l abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z()), Math.abs(w())); }
|
||||
@Override
|
||||
public default Vec4l negate() { return set(0L, 0L, 0L, 0L); }
|
||||
@Override
|
||||
public default Vec4l invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
|
||||
public default Vec4l invert() { return set(-x(), -y(), -z(), -w()); }
|
||||
@Override
|
||||
public default Vec4l add(long value) { return add(value, value, value, value); }
|
||||
public default Vec4l add(Vec4l value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4l add(long x, long y, long z, long w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
|
||||
public default Vec4l add(Vec4l value) { return add(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4l add(long x, long y, long z, long w) { return set(x() + x, y() + y, z() + z, w() + w); }
|
||||
@Override
|
||||
public default Vec4l sub(long value) { return sub(value, value, value, value); }
|
||||
public default Vec4l sub(Vec4l value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4l sub(long x, long y, long z, long w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4l sub(Vec4l value) { return sub(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4l sub(long x, long y, long z, long w) { return set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4l multiply(long value) { return multiply(value, value, value, value); }
|
||||
public default Vec4l multiply(Vec4l value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4l multiply(long x, long y, long z, long w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
|
||||
public default Vec4l multiply(Vec4l value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4l multiply(long x, long y, long z, long w) { return set(x() * x, y() * y, z() * z, w() * w); }
|
||||
@Override
|
||||
public default Vec4l devide(long value) { return devide(value, value, value, value); }
|
||||
public default Vec4l devide(Vec4l value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4l devide(long x, long y, long z, long w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
|
||||
public default Vec4l devide(Vec4l value) { return devide(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Vec4l devide(long x, long y, long z, long w) { return set(x() / x, y() / y, z() / z, w() / w); }
|
||||
@Override
|
||||
public default Vec4l set(long value) { return set(value, value, value, value); }
|
||||
public default Vec4l set(Vec4l value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Vec4l set(Vec4l value) { return set(value.x(), value.y(), value.z(), value.w()); }
|
||||
public Vec4l set(long x, long y, long z, long w);
|
||||
public default double distanceTo(Vec4l value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default double distanceTo(Vec4l value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default double distanceTo(long x, long y, long z, long w) { return Math.sqrt(distanceTo(x, y, z, w)); }
|
||||
public default long distanceToSquared(Vec4l value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default long distanceToSquared(Vec4l value) { return distanceToSquared(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default long distanceToSquared(long x, long y, long z, long w) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long zPos = getZ() - z;
|
||||
long wPos = getW() - w;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
long zPos = z() - z;
|
||||
long wPos = w() - w;
|
||||
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
|
||||
public default long dotProduct(Vec4l value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default long dotProduct(long x, long y, long z, long w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
|
||||
public default long dotProduct(Vec4l value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default long dotProduct(long x, long y, long z, long w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
|
||||
public default Vec4l min(Vec4l other) { return min(other, this); }
|
||||
public default Vec4l min(Vec4l other, Vec4l result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4l min(Vec4l other, Vec4l result) { return min(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4l min(long x, long y, long z, long w) { return min(x, y, z, w, this); }
|
||||
public default Vec4l min(long x, long y, long z, long w, Vec4l result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
|
||||
public default Vec4l min(long x, long y, long z, long w, Vec4l result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z), Math.min(w(), w)); }
|
||||
public default Vec4l max(Vec4l other) { return max(other, this); }
|
||||
public default Vec4l max(Vec4l other, Vec4l result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4l max(Vec4l other, Vec4l result) { return max(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4l max(long x, long y, long z, long w) { return max(x, y, z, w, this); }
|
||||
public default Vec4l max(long x, long y, long z, long w, Vec4l result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
|
||||
public default Vec4l max(long x, long y, long z, long w, Vec4l result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z), Math.max(z(), z)); }
|
||||
public default Vec4l difference(Vec4l other) { return difference(other, this); }
|
||||
public default Vec4l difference(Vec4l other, Vec4l result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
|
||||
public default Vec4l difference(Vec4l other, Vec4l result) { return difference(other.x(), other.y(), other.z(), other.w(), result); }
|
||||
public default Vec4l difference(long x, long y, long z, long w) { return difference(x, y, z, w, this); }
|
||||
public default Vec4l difference(long x, long y, long z, long w, Vec4l result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
|
||||
public default Vec4l difference(long x, long y, long z, long w, Vec4l result) { return result.set(x() - x, y() - y, z() - z, w() - w); }
|
||||
@Override
|
||||
public default Vec4l clamp(long min, long max) { return clamp(min, max, ALL); }
|
||||
public default Vec4l clamp(long min, long max, Vec4l result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec4l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec4l clamp(long min, long max, Vec4l result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
|
||||
public default Vec4l clamp(long min, long max, Vec4l result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
|
||||
|
||||
@Override
|
||||
public default Vec4l store(ByteBuffer buffer) {
|
||||
buffer.putLong(getX()).putLong(getY()).putLong(getZ()).putLong(getW());
|
||||
buffer.putLong(x()).putLong(y()).putLong(z()).putLong(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -108,22 +108,22 @@ public interface Vec4l extends Vecl {
|
||||
|
||||
@Override
|
||||
public default Vec4l store(LongBuffer buffer) {
|
||||
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
|
||||
buffer.put(x()).put(y()).put(z()).put(w());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec4l load(LongBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()); }
|
||||
public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)x(), (byte)y(), (byte)z(), (byte)w()) : Vec4b.of((byte)x(), (byte)y(), (byte)z(), (byte)w()); }
|
||||
@Override
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.of((short)getX(), (short)getY(), (short)getZ(), (short)getW()); }
|
||||
public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)x(), (short)y(), (short)z(), (short)w()) : Vec4s.of((short)x(), (short)y(), (short)z(), (short)w()); }
|
||||
@Override
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable((int)getX(), (int)getY(), (int)getZ(), (int)getW()) : Vec4i.of((int)getX(), (int)getY(), (int)getZ(), (int)getW()); }
|
||||
public default Vec4i asInt() { return isMutable() ? Vec4i.mutable((int)x(), (int)y(), (int)z(), (int)w()) : Vec4i.of((int)x(), (int)y(), (int)z(), (int)w()); }
|
||||
@Override
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(x(), y(), z(), w()) : Vec4f.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
|
||||
public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(x(), y(), z(), w()) : Vec4d.of(x(), y(), z(), w()); }
|
||||
@Override
|
||||
public default Vec4l asMutable() { return isMutable() ? this : mutable(this); }
|
||||
@Override
|
||||
|
||||
@@ -32,21 +32,21 @@ public class Vec4lImmutable implements Vec4l {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public long getX() { return x; }
|
||||
public long x() { return x; }
|
||||
@Override
|
||||
public long getY() { return y; }
|
||||
public long y() { return y; }
|
||||
@Override
|
||||
public long getZ() { return z; }
|
||||
public long z() { return z; }
|
||||
@Override
|
||||
public long getW() { return w; }
|
||||
public long w() { return w; }
|
||||
@Override
|
||||
public Vec4l setX(long x) { return this.x == x ? this : Vec4l.of(x, y, z, w); }
|
||||
public Vec4l x(long x) { return this.x == x ? this : Vec4l.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4l setY(long y) { return this.y == y ? this : Vec4l.of(x, y, z, w); }
|
||||
public Vec4l y(long y) { return this.y == y ? this : Vec4l.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4l setZ(long z) { return this.z == z ? this : Vec4l.of(x, y, z, w); }
|
||||
public Vec4l z(long z) { return this.z == z ? this : Vec4l.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4l setW(long w) { return this.w == w ? this : Vec4l.of(x, y, z, w); }
|
||||
public Vec4l w(long w) { return this.w == w ? this : Vec4l.of(x, y, z, w); }
|
||||
@Override
|
||||
public Vec4l copy() { return Vec4l.of(this); }
|
||||
@Override
|
||||
@@ -58,7 +58,7 @@ public class Vec4lImmutable implements Vec4l {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4l) {
|
||||
Vec4l vec = (Vec4l)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,34 +27,34 @@ public class Vec4lMutable implements Vec4l {
|
||||
@Override
|
||||
public boolean isMutable() { return true; }
|
||||
@Override
|
||||
public long getX() { return x; }
|
||||
public long x() { return x; }
|
||||
@Override
|
||||
public long getY() { return y; }
|
||||
public long y() { return y; }
|
||||
@Override
|
||||
public long getZ() { return z; }
|
||||
public long z() { return z; }
|
||||
@Override
|
||||
public long getW() { return w; }
|
||||
public long w() { return w; }
|
||||
|
||||
@Override
|
||||
public Vec4l setX(long x) {
|
||||
public Vec4l x(long x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4l setY(long y) {
|
||||
public Vec4l y(long y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4l setZ(long z) {
|
||||
public Vec4l z(long z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec4l setW(long w) {
|
||||
public Vec4l w(long w) {
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class Vec4lMutable implements Vec4l {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec4l) {
|
||||
Vec4l vec = (Vec4l)obj;
|
||||
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
|
||||
return vec.x() == x && vec.y() == y && vec.z() == z && vec.w() == w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package speiger.src.coreengine.math.vector.matrix;
|
||||
|
||||
public interface ITransformOutput {
|
||||
public void accept(float...output);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -61,7 +61,7 @@ public interface Quaternion {
|
||||
return set(getX() * cos + getY() * sin, getY() * cos - getX() * sin, getW() * sin + getZ() * cos, getW() * cos - getZ() * sin);
|
||||
}
|
||||
|
||||
public default Quaternion set(Vec4f value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
public default Quaternion set(Vec4f value) { return set(value.x(), value.y(), value.z(), value.w()); }
|
||||
public default Quaternion set(Quaternion value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
|
||||
|
||||
public default Quaternion set(Matrix4f matrix) {
|
||||
|
||||
@@ -18,90 +18,90 @@ public interface Vec2s extends Vecs {
|
||||
public static Vec2s mutable() { return new Vec2sMutable(); }
|
||||
public static Vec2s mutable(short value) { return new Vec2sMutable(value); }
|
||||
public static Vec2s mutable(short x, short y) { return new Vec2sMutable(x, y); }
|
||||
public static Vec2s mutable(Vec2s value) { return mutable(value.getX(), value.getY()); }
|
||||
public static Vec2s mutable(Vec2s value) { return mutable(value.x(), value.y()); }
|
||||
public static Vec2s of() { return new Vec2sImmutable(); }
|
||||
public static Vec2s of(short value) { return new Vec2sImmutable(value); }
|
||||
public static Vec2s of(short x, short y) { return new Vec2sImmutable(x, y); }
|
||||
public static Vec2s of(Vec2s value) { return of(value.getX(), value.getY()); }
|
||||
public static Vec2s of(Vec2s value) { return of(value.x(), value.y()); }
|
||||
|
||||
public short getX();
|
||||
public short getY();
|
||||
public Vec2s setX(short x);
|
||||
public Vec2s setY(short y);
|
||||
public short x();
|
||||
public short y();
|
||||
public Vec2s x(short x);
|
||||
public Vec2s y(short y);
|
||||
|
||||
@Override
|
||||
public default short[] asArray() { return new short[] {getX(), getY()}; }
|
||||
public default short[] asArray() { return new short[] {x(), y()}; }
|
||||
@Override
|
||||
public Vec2s copy();
|
||||
@Override
|
||||
public default Vec2s abs() { return set((short)Math.abs(getX()), (short)Math.abs(getY())); }
|
||||
public default Vec2s abs() { return set((short)Math.abs(x()), (short)Math.abs(y())); }
|
||||
@Override
|
||||
public default Vec2s negate() { return set((short)0, (short)0); }
|
||||
@Override
|
||||
public default Vec2s invert() { return set((short)(-getX()), (short)(-getY())); };
|
||||
public default Vec2s invert() { return set((short)(-x()), (short)(-y())); };
|
||||
@Override
|
||||
public default Vec2s add(short value) { return add(value, value); }
|
||||
public default Vec2s add(Vec2s value) { return add(value.getX(), value.getY()); }
|
||||
public default Vec2s add(short x, short y) { return set((short)(x + getX()), (short)(y + getY())); }
|
||||
public default Vec2s add(Vec2s value) { return add(value.x(), value.y()); }
|
||||
public default Vec2s add(short x, short y) { return set((short)(x + x()), (short)(y + y())); }
|
||||
@Override
|
||||
public default Vec2s sub(short value) { return sub(value, value); }
|
||||
public default Vec2s sub(Vec2s value) { return sub(value.getX(), value.getY()); }
|
||||
public default Vec2s sub(short x, short y) { return set((short)(getX() - x), (short)(getY() - y)); }
|
||||
public default Vec2s sub(Vec2s value) { return sub(value.x(), value.y()); }
|
||||
public default Vec2s sub(short x, short y) { return set((short)(x() - x), (short)(y() - y)); }
|
||||
@Override
|
||||
public default Vec2s multiply(short value) { return multiply(value, value); }
|
||||
public default Vec2s multiply(Vec2s value) { return multiply(value.getX(), value.getY()); }
|
||||
public default Vec2s multiply(short x, short y) { return set((short)(x * getX()), (short)(y * getY())); }
|
||||
public default Vec2s multiply(Vec2s value) { return multiply(value.x(), value.y()); }
|
||||
public default Vec2s multiply(short x, short y) { return set((short)(x * x()), (short)(y * y())); }
|
||||
@Override
|
||||
public default Vec2s devide(short value) { return devide(value, value); }
|
||||
public default Vec2s devide(Vec2s value) { return devide(value.getX(), value.getY()); }
|
||||
public default Vec2s devide(short x, short y) { return set((short)(getX() / x), (short)(getY() / y)); }
|
||||
public default Vec2s devide(Vec2s value) { return devide(value.x(), value.y()); }
|
||||
public default Vec2s devide(short x, short y) { return set((short)(x() / x), (short)(y() / y)); }
|
||||
@Override
|
||||
public default Vec2s set(short value) { return set(value, value); };
|
||||
public default Vec2s set(Vec2s value) { return set(value.getX(), value.getY()); }
|
||||
public default Vec2s set(Vec2s value) { return set(value.x(), value.y()); }
|
||||
public Vec2s set(short x, short y);
|
||||
public default double distanceTo(Vec2s value) { return distanceTo(value.getX(), value.getY()); }
|
||||
public default double distanceTo(Vec2s value) { return distanceTo(value.x(), value.y()); }
|
||||
public default double distanceTo(short x, short y) { return Math.sqrt(distanceToSquared(x, y)); }
|
||||
public default long distanceToSquared(Vec2s value) { return distanceToSquared(value.getX(), value.getY()); }
|
||||
public default long distanceToSquared(Vec2s value) { return distanceToSquared(value.x(), value.y()); }
|
||||
public default long distanceToSquared(short x, short y) {
|
||||
long xPos = getX() - x;
|
||||
long yPos = getY() - y;
|
||||
long xPos = x() - x;
|
||||
long yPos = y() - y;
|
||||
return (xPos * xPos) + (yPos * yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
|
||||
public default long dotProduct(Vec2s value) { return dotProduct(value.getX(), value.getY()); }
|
||||
public default long dotProduct(short x, short y) { return (getX() * x) + (getY() * y); }
|
||||
public default Vec2s rotate(short angle, Vec2s center) { return rotate(angle, center.getX(), center.getY()); }
|
||||
public default long lengthSquared() { return (x() * x()) + (y() * y()); }
|
||||
public default long dotProduct(Vec2s value) { return dotProduct(value.x(), value.y()); }
|
||||
public default long dotProduct(short x, short y) { return (x() * x) + (y() * y); }
|
||||
public default Vec2s rotate(short angle, Vec2s center) { return rotate(angle, center.x(), center.y()); }
|
||||
public default Vec2s rotate(short angle, short x, short y) {
|
||||
short xPos = (short)(getX() - x);
|
||||
short yPos = (short)(getY() - y);
|
||||
short xPos = (short)(x() - x);
|
||||
short yPos = (short)(y() - y);
|
||||
double cos = MathUtils.cos(angle);
|
||||
double sin = MathUtils.sin(angle);
|
||||
return set((short)((xPos * cos) + (yPos * sin) + x), (short)(-(xPos * sin) + (yPos * cos) + y));
|
||||
}
|
||||
|
||||
public default Vec2s min(Vec2s other) { return min(other, this); }
|
||||
public default Vec2s min(Vec2s other, Vec2s result) { return min(other.getX(), other.getY(), result); }
|
||||
public default Vec2s min(Vec2s other, Vec2s result) { return min(other.x(), other.y(), result); }
|
||||
public default Vec2s min(short x, short y) { return min(x, y, this); }
|
||||
public default Vec2s min(short x, short y, Vec2s result) { return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y)); }
|
||||
public default Vec2s min(short x, short y, Vec2s result) { return result.set((short)Math.min(x(), x), (short)Math.min(y(), y)); }
|
||||
public default Vec2s max(Vec2s other) { return max(other, this); }
|
||||
public default Vec2s max(Vec2s other, Vec2s result) { return max(other.getX(), other.getY(), result); }
|
||||
public default Vec2s max(Vec2s other, Vec2s result) { return max(other.x(), other.y(), result); }
|
||||
public default Vec2s max(short x, short y) { return max(x, y, this); }
|
||||
public default Vec2s max(short x, short y, Vec2s result) { return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y)); }
|
||||
public default Vec2s max(short x, short y, Vec2s result) { return result.set((short)Math.max(x(), x), (short)Math.max(y(), y)); }
|
||||
public default Vec2s difference(Vec2s other) { return difference(other, this); }
|
||||
public default Vec2s difference(Vec2s other, Vec2s result) { return difference(other.getX(), other.getY(), result); }
|
||||
public default Vec2s difference(Vec2s other, Vec2s result) { return difference(other.x(), other.y(), result); }
|
||||
public default Vec2s difference(short x, short y) { return difference(x, y, this); }
|
||||
public default Vec2s difference(short x, short y, Vec2s result) { return result.set((short)(getX() - x), (short)(getY() - y)); }
|
||||
public default Vec2s difference(short x, short y, Vec2s result) { return result.set((short)(x() - x), (short)(y() - y)); }
|
||||
@Override
|
||||
public default Vec2s clamp(short min, short max) { return clamp(min, max, ALL); }
|
||||
public default Vec2s clamp(short min, short max, Vec2s result) { return clamp(min, max, result, ALL); }
|
||||
@Override
|
||||
public default Vec2s clamp(short min, short max, int filter) { return clamp(min, max, this, filter); }
|
||||
public default Vec2s clamp(short min, short max, Vec2s result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
|
||||
public default Vec2s clamp(short min, short max, Vec2s result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
|
||||
@Override
|
||||
public default Vec2s store(ByteBuffer buffer) {
|
||||
buffer.putShort(getX()).putShort(getY());
|
||||
buffer.putShort(x()).putShort(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -110,22 +110,22 @@ public interface Vec2s extends Vecs {
|
||||
|
||||
@Override
|
||||
public default Vec2s store(ShortBuffer buffer) {
|
||||
buffer.put(getX()).put(getY());
|
||||
buffer.put(x()).put(y());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public default Vec2s load(ShortBuffer buffer) { return set(buffer.get(), buffer.get()); }
|
||||
@Override
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY()); }
|
||||
public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)x(), (byte)y()) : Vec2b.of((byte)x(), (byte)y()); }
|
||||
@Override
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(getX(), getY()) : Vec2i.of(getX(), getY()); }
|
||||
public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(x(), y()) : Vec2i.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY()); }
|
||||
public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(x(), y()) : Vec2l.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
|
||||
public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(x(), y()) : Vec2f.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
|
||||
public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(x(), y()) : Vec2d.of(x(), y()); }
|
||||
@Override
|
||||
public default Vec2s asMutable() { return isMutable() ? this : of(this); }
|
||||
@Override
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Vec2sImmutable implements Vec2s {
|
||||
@Override
|
||||
public boolean isMutable() { return false; }
|
||||
@Override
|
||||
public short getX() { return x; }
|
||||
public short x() { return x; }
|
||||
@Override
|
||||
public short getY() { return y; }
|
||||
public short y() { return y; }
|
||||
@Override
|
||||
public Vec2s setX(short x) { return this.x == x ? this : Vec2s.of(x, y); }
|
||||
public Vec2s x(short x) { return this.x == x ? this : Vec2s.of(x, y); }
|
||||
@Override
|
||||
public Vec2s setY(short y) { return this.y == y ? this : Vec2s.of(x, y); }
|
||||
public Vec2s y(short y) { return this.y == y ? this : Vec2s.of(x, y); }
|
||||
@Override
|
||||
public Vec2s copy() { return Vec2s.of(this); }
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class Vec2sImmutable implements Vec2s {
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Vec2s) {
|
||||
Vec2s vec = (Vec2s)obj;
|
||||
return vec.getX() == x && vec.getY() == y;
|
||||
return vec.x() == x && vec.y() == y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user