Compare commits

...

5 Commits
main ... dev

40 changed files with 843 additions and 960 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Ewol" local="false">
<fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="out/eclipse/classes-test" path="test/src">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/spotbugs-annotations-4.2.2.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-reggol">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="out/eclipse/classes"/>
</classpath>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="net.sf.eclipsecs.core.CheckstyleBuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>atriasoft-etk</name>
<comment></comment>
<projects>
<project>atriasoft-etk</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
<filteredResources>
<filter>
<id>1664626602847</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>1.0-name-matches-false-true-node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

Binary file not shown.

View File

@ -52,7 +52,7 @@ def configure(target, my_module):
'src/org/atriasoft/etk/util/Pair.java',
'src/org/atriasoft/etk/util/Dynamic.java',
'src/org/atriasoft/etk/util/ArraysTools.java',
'src/org/atriasoft/etk/internal/Log.java',
'src/org/atriasoft/etk/internal/LOGGER.java',
'src/org/atriasoft/etk/theme/Theme.java',
'src/org/atriasoft/etk/Tools.java',
'src/org/atriasoft/etk/Configs.java',

123
pom.xml Normal file
View File

@ -0,0 +1,123 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atriasoft</groupId>
<artifactId>etk</artifactId>
<version>0.1.0</version>
<properties>
<maven.compiler.version>3.13.0</maven.compiler.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.dependency.version>3.1.1</maven.dependency.version>
</properties>
<repositories>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
<snapshotRepository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.1.0-alpha1</version>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>4.8.5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<!--<encoding>${project.build.sourceEncoding}</encoding>-->
</configuration>
</plugin>
<!-- Create the source bundle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- junit results -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Java-doc generation for stand-alone site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
</plugins>
</build>
<!-- Generate Java-docs As Part Of Project Reports -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>public</show>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -7,6 +7,6 @@ open module org.atriasoft.etk {
exports org.atriasoft.etk.math;
exports org.atriasoft.etk.util;
requires transitive org.atriasoft.reggol;
requires transitive org.slf4j;
requires com.github.spotbugs.annotations;
}

View File

@ -4,7 +4,6 @@ import java.util.Map;
import org.atriasoft.etk.math.FMath;
@SuppressWarnings("preview")
//@formatter:off
public record Color(

View File

@ -3,7 +3,8 @@ package org.atriasoft.etk;
import java.util.HashMap;
import java.util.Map;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** @file
* @author Edouard DUPIN
@ -12,6 +13,7 @@ import org.atriasoft.etk.internal.Log;
*/
public class ConfigFont {
final static Logger LOGGER = LoggerFactory.getLogger(ConfigFont.class);
private final Map<String, Uri> fonts = new HashMap<>();
private String name = "FreeSans";
private int size = 12;
@ -23,7 +25,7 @@ public class ConfigFont {
public Uri getFontUri(final String fontName) {
Uri out = this.fonts.get(fontName);
if (out == null) {
Log.warning(" try to get unexistant font : " + fontName);
LOGGER.warn(" try to get unexistant font : " + fontName);
}
return out;
}
@ -52,7 +54,7 @@ public class ConfigFont {
public void set(final String fontName, final int size) {
this.name = fontName;
this.size = size;
Log.debug("Set default Font : '" + this.name + "' size=" + this.size);
LOGGER.trace("Set default Font : '" + this.name + "' size=" + this.size);
}
/**
@ -61,7 +63,7 @@ public class ConfigFont {
*/
public void setName(final String fontName) {
this.name = fontName;
Log.debug("Set default Font : '" + this.name + "' size=" + this.size + " (change name only)");
LOGGER.trace("Set default Font : '" + this.name + "' size=" + this.size + " (change name only)");
}
/**
@ -70,6 +72,6 @@ public class ConfigFont {
*/
public void setSize(final int size) {
this.size = size;
Log.debug("Set default Font : '" + this.name + "' size=" + this.size + " (change size only)");
LOGGER.trace("Set default Font : '" + this.name + "' size=" + this.size + " (change size only)");
}
}

View File

@ -1,6 +1,10 @@
package org.atriasoft.etk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Configs {
final static Logger LOGGER = LoggerFactory.getLogger(Configs.class);
private static ConfigFont fonts = new ConfigFont();
public static ConfigFont getConfigFonts() {

View File

@ -5,7 +5,8 @@
*/
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* in the dimension class we store the data as the more usefull unit (pixel)
@ -14,6 +15,7 @@ import org.atriasoft.etk.internal.Log;
public record Dimension1f(
float size,
Distance type) {
final static Logger LOGGER = LoggerFactory.getLogger(Dimension1f.class);
private static final float BASIC_RATIO = 72.0f / 25.4f;
public static final Dimension1f ZERO = new Dimension1f(0);
@ -61,26 +63,17 @@ public record Dimension1f(
* @return dimension in Pixel
*/
public float getPixel(final float upperSize) {
switch (this.type) {
case POURCENT:
return upperSize * this.size * 0.01f;
case PIXEL:
return this.size;
case METER:
return this.size * METER_TO_MILLIMETER * BASIC_RATIO;
case CENTIMETER:
return this.size * CENTIMETER_TO_MILLIMETER * BASIC_RATIO;
case MILLIMETER:
return this.size * BASIC_RATIO;
case KILOMETER:
return this.size * KILOMETER_TO_MILLIMETER * BASIC_RATIO;
case INCH:
return this.size * INCH_TO_MILLIMETER * BASIC_RATIO;
case FOOT:
return this.size * FOOT_TO_MILLIMETER * BASIC_RATIO;
default:
return 128.0f;
}
return switch (this.type) {
case POURCENT -> upperSize * this.size * 0.01f;
case PIXEL -> this.size;
case METER -> this.size * METER_TO_MILLIMETER * BASIC_RATIO;
case CENTIMETER -> this.size * CENTIMETER_TO_MILLIMETER * BASIC_RATIO;
case MILLIMETER -> this.size * BASIC_RATIO;
case KILOMETER -> this.size * KILOMETER_TO_MILLIMETER * BASIC_RATIO;
case INCH -> this.size * INCH_TO_MILLIMETER * BASIC_RATIO;
case FOOT -> this.size * FOOT_TO_MILLIMETER * BASIC_RATIO;
default -> 128.0f;
};
}
/**
@ -96,16 +89,14 @@ public record Dimension1f(
* @param config dimension configuration.
*/
public static Dimension1f valueOf(String config) {
final Distance type = Distance.parseEndSmallString(config);
Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
return null;
LOGGER.error("FATAL: Can not parse dimension : '{}' CAn not deterùmine extention ... px, cm, ...", config);
type = Distance.PIXEL;
}
final float tmp = Float.valueOf(config);
final Dimension1f ret = new Dimension1f(tmp, type);
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
return ret;
return new Dimension1f(tmp, type);
}
/**

View File

@ -5,9 +5,10 @@
*/
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* in the dimension class we store the data as the more usefull unit (pixel)
@ -16,6 +17,7 @@ import org.atriasoft.etk.math.Vector2i;
public record Dimension2f(
Vector2f size,
Distance type) {
final static Logger LOGGER = LoggerFactory.getLogger(Dimension2f.class);
public static final Dimension2f ZERO = new Dimension2f(Vector2f.ZERO, Distance.PIXEL);
private static Vector2f ratio = new Vector2f(9999999, 888888);
@ -76,12 +78,12 @@ public record Dimension2f(
* @note: same as @ref setPixelPerInch (internal manage convention)
*/
public static void setPixelRatio(final Vector2f ratio, final Distance type) {
Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
LOGGER.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
final Dimension2f conversion = new Dimension2f(ratio, type);
Log.info(" == > " + conversion);
LOGGER.info(" == > " + conversion);
Dimension2f.ratio = conversion.getMillimeter();
invRatio = new Vector2f(1.0f / Dimension2f.ratio.x(), 1.0f / Dimension2f.ratio.y());
Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension2f.ratio);
LOGGER.info("Set a new screen ratio for the screen : ratioMm=" + Dimension2f.ratio);
}
/**
@ -90,7 +92,6 @@ public record Dimension2f(
*/
public static void setPixelWindowsSize(final Vector2f size) {
windowsSize = new Dimension2f(size);
Log.verbose("Set a new Windows property size " + windowsSize + "px");
}
/**
@ -131,7 +132,8 @@ public record Dimension2f(
case ELEMENT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case EX -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case PC -> {
Log.error("Does not support other than Px and % type of dimention : " + type + " automaticly convert with {72,72} pixel/inch");
LOGGER.error("Does not support other than Px and % type of dimention : " + type
+ " automaticly convert with {72,72} pixel/inch");
yield null;
}
case POINT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
@ -216,7 +218,8 @@ public record Dimension2f(
if (this.type != Distance.POURCENT) {
return new Vector2i((int) this.size.x(), (int) this.size.y());
}
final Vector2i res = new Vector2i((int) (uppersize.x() * this.size.x() * 0.01f), (int) (uppersize.y() * this.size.y() * 0.01f));
final Vector2i res = new Vector2i((int) (uppersize.x() * this.size.x() * 0.01f),
(int) (uppersize.y() * this.size.y() * 0.01f));
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res;
}
@ -252,12 +255,11 @@ public record Dimension2f(
final Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
LOGGER.error("Can not parse dimension : '" + config + "'");
return null;
}
final Vector2f tmp = Vector2f.valueOf(config);
final Dimension2f ret = new Dimension2f(tmp, type);
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
return ret;
}
@ -269,13 +271,13 @@ public record Dimension2f(
return get(getType()).toString() + getType().toSmallString();
}
public static Dimension2f valueOf(String contentX, final String contentY) {
public static Dimension2f valueOf(String contentX, String contentY) {
final Distance typeX = Distance.parseEndSmallString(contentX);
contentX = typeX.removeEndString(contentX);
final float tmpX = Float.valueOf(contentX);
final Distance typeY = Distance.parseEndSmallString(contentY);
contentX = typeY.removeEndString(contentY);
contentY = typeY.removeEndString(contentY);
final float tmpY = Float.valueOf(contentY);
if (typeX != Distance.UNKNOW) {

View File

@ -5,9 +5,10 @@
*/
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* in the dimension class we store the data as the more usefull unit (pixel)
@ -16,6 +17,7 @@ import org.atriasoft.etk.math.Vector3f;
public record Dimension3f(
Vector3f size,
Distance type) {
final static Logger LOGGER = LoggerFactory.getLogger(Dimension3f.class);
public static final Dimension3f ZERO = new Dimension3f(Vector3f.ZERO, Distance.PIXEL);
private static Vector3f ratio = new Vector3f(9999999, 888888, 7777777);
@ -68,12 +70,12 @@ public record Dimension3f(
* @note: same as @ref setPixelPerInch (internal manage convertion)
*/
public static void setPixelRatio(final Vector3f ratio, final Distance type) {
Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
LOGGER.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
final Dimension3f conversion = new Dimension3f(ratio, type);
Log.info(" == > " + conversion);
LOGGER.info(" == > " + conversion);
Dimension3f.ratio = conversion.getMillimeter();
invRatio = new Vector3f(1.0f / Dimension3f.ratio.x(), 1.0f / Dimension3f.ratio.y(), 1.0f / Dimension3f.ratio.z());
Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension3f.ratio);
LOGGER.info("Set a new screen ratio for the screen : ratioMm=" + Dimension3f.ratio);
}
/**
@ -82,7 +84,6 @@ public record Dimension3f(
*/
public static void setPixelWindowsSize(final Vector3f size) {
windowsSize = new Dimension3f(size);
Log.verbose("Set a new Windows property size " + windowsSize + "px");
}
/**
@ -123,7 +124,7 @@ public record Dimension3f(
case ELEMENT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case EX -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case PC -> {
Log.error("Does not support other than Px and % type of dimention : " + type + " automaticly convert with {72,72} pixel/inch");
LOGGER.error("Does not support other than Px and % type of dimention : " + type + " automaticly convert with {72,72} pixel/inch");
yield null;
}
case POINT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
@ -244,12 +245,11 @@ public record Dimension3f(
final Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
LOGGER.error("Can not parse dimension : '" + config + "'");
return null;
}
final Vector3f tmp = Vector3f.valueOf(config);
final Dimension3f ret = new Dimension3f(tmp, type);
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
return ret;
}

View File

@ -1,5 +1,6 @@
package org.atriasoft.etk;
public enum Distance {
UNKNOW, //!< "%"
POURCENT, //!< "%"

View File

@ -5,9 +5,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NativeLoader {
final static Logger LOGGER = LoggerFactory.getLogger(NativeLoader.class);
private NativeLoader() {}
/**
@ -16,7 +19,7 @@ public class NativeLoader {
* @throws IOException the library can not be loaded...
*/
public static void load(final Uri fileToLoad) throws IOException {
Log.error("Start load library native ...");
LOGGER.error("Start load library native ...");
// in java the loading of .so need to be externalized to be loaded by the system as native library. then we copy in an external temporary folder and remove it when application close.
try {
InputStream is = Uri.getStream(fileToLoad);

View File

@ -1,10 +1,13 @@
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
public class Platform {
final static Logger LOGGER = LoggerFactory.getLogger(Platform.class);
private Platform() {}
/**
* Get the current OS we are running:
@ -67,7 +70,7 @@ public class Platform {
} else if (osArch.startsWith("arm")) {
osArch = "arm";
} else {
Log.warning("Maybe unknowx system... osArch=" + osArch + " abiType=" + abiType + " libPath=" + libPath);
LOGGER.warn("Maybe unknowx system... osArch=" + osArch + " abiType=" + abiType + " libPath=" + libPath);
}
return System.getProperty("org.atriasoft.etk.platform.arch", osArch);
}

View File

@ -1,6 +1,10 @@
package org.atriasoft.etk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class ThreadAbstract {
final static Logger LOGGER = LoggerFactory.getLogger(ThreadAbstract.class);
// thread section:
private boolean threadStopRequested = false;
private Thread threadInstance = null;

View File

@ -5,10 +5,13 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.util.FilePos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Tools {
final static Logger LOGGER = LoggerFactory.getLogger(Tools.class);
/**
* Add indentation of the string input.
@ -131,11 +134,11 @@ public class Tools {
*/
public static void drawElementParsed(final Character val, final FilePos filePos) {
// if (val == '\n') {
// Log.error(filePos + " parse '\\n'");
// LOGGER.error(filePos + " parse '\\n'");
// } else if (val == '\t') {
// Log.error(filePos + " parse '\\t'");
// LOGGER.error(filePos + " parse '\\t'");
// } else {
// Log.error(filePos + " parse '" + val + "'");
// LOGGER.error(filePos + " parse '" + val + "'");
// }
}
@ -191,7 +194,7 @@ public class Tools {
}
val *= 2;
}
Log.critical("impossible CASE....");
LOGGER.error("impossible CASE....");
return val;
}

View File

@ -15,27 +15,31 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Uri {
final static Logger LOGGER = LoggerFactory.getLogger(Uri.class);
private record LibraryElement(
Class<?> klass,
String basePath) {}
private static Map<String, String> genericMap = new HashMap<>();
private static Map<String, LibraryElement> libraries = new HashMap<>();
private static Class<?> applicationClass = null;
private static String applicationBasePath = "";
static {
Uri.genericMap.put("DATA", "data/");
Uri.genericMap.put("THEME", "theme/");
Uri.genericMap.put("FONTS", "fonts/");
Uri.genericMap.put("TRANSLATE", "translate/");
}
public static void addLibrary(final String libName, final Class<?> classHandle, String basePath) {
Log.verbose("Add library reference: lib={} ==> {} base path={}", libName, classHandle.getCanonicalName(), basePath);
LOGGER.trace("Add library reference: lib={} ==> {} base path={}", libName, classHandle.getCanonicalName(),
basePath);
if (basePath == null || basePath.isEmpty()) {
basePath = "/";
}
@ -47,7 +51,7 @@ public class Uri {
}
Uri.libraries.put(libName.toLowerCase(), new LibraryElement(classHandle, basePath));
}
public static byte[] getAllData(final Uri resourceName) {
final InputStream out = Uri.getStream(resourceName);
if (out == null) {
@ -62,43 +66,12 @@ public class Uri {
}
return data;
}
// public static Stream<Path> getResources(final URL element) {
// try {
// final URI uri = element.toURI();
// FileSystem fs;
// Path path;
// if (uri.getScheme().contentEquals("jar")) {
// try {
// fs = FileSystems.getFileSystem(uri);
// } catch (final FileSystemNotFoundException e) {
// fs = FileSystems.newFileSystem(uri, Collections.<String, String> emptyMap());
// }
// String pathInJar = "/";
// final String tmpPath = element.getPath();
// final int idSeparate = tmpPath.indexOf('!');
// if (idSeparate != -1) {
// pathInJar = tmpPath.substring(idSeparate + 1);
// while (pathInJar.startsWith("/")) {
// pathInJar = pathInJar.substring(1);
// }
// }
// path = fs.getPath(pathInJar);
// } else {
// fs = FileSystems.getDefault();
// path = Paths.get(uri);
// }
// return Files.walk(path, 1);
// } catch (URISyntaxException | IOException e) {
// e.printStackTrace();
// return Stream.of();
// }
// }
private static List<String> getResourceFiles(final Class<?> clazz, final String path) throws IOException {
final List<String> filenames = new ArrayList<>();
try (InputStream in = clazz.getResourceAsStream(path); BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
try (InputStream in = clazz.getResourceAsStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
String resource;
while ((resource = br.readLine()) != null) {
filenames.add(resource);
@ -106,13 +79,14 @@ public class Uri {
}
return filenames;
}
public static InputStream getStream(final Uri uri) {
Log.verbose("Load resource: {}", uri);
LOGGER.trace("????????????????????????????????????????????");
LOGGER.trace("Load resource: {}", uri);
String offsetGroup = "";
if (uri.group != null) {
if (uri.group.equals("FILE")) {
Log.verbose("Load resource direct file: {}", uri);
LOGGER.trace("Load resource direct file: {}", uri);
try {
return new FileInputStream(new File(uri.getPath()));
} catch (final FileNotFoundException e) {
@ -121,90 +95,98 @@ public class Uri {
return null;
}
}
Log.verbose(" find group: {}", uri.group);
LOGGER.trace(" find group: {}", uri.group);
final String ret = Uri.genericMap.get(uri.group);
if (ret != null) {
Log.verbose(" ==> {}", ret);
LOGGER.trace(" ==> {}", ret);
offsetGroup = ret;
}
}
InputStream out = null;
if (Uri.applicationClass == null) {
Log.verbose(" !! Application data class is not defined ...");
LOGGER.trace(" !! Application data class is not defined ...");
} else {
String tmpPath = Uri.applicationBasePath + offsetGroup + uri.path;
tmpPath = tmpPath.replace("//", "/");
Log.verbose("(appl) Try to load '{}' in {}", tmpPath, Uri.applicationClass.getCanonicalName());// + " ==> " + applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath());
String tmpPath = "/" + Uri.applicationBasePath + offsetGroup + uri.path;
tmpPath = tmpPath.replace("///", "/").replace("//", "/").replaceFirst("^/*", "");
LOGGER.trace("(appl) Try to load '{}' in {}", tmpPath, Uri.applicationClass.getCanonicalName());
final URL realFileName = Uri.applicationClass.getClassLoader().getResource(tmpPath);
if (realFileName != null) {
Log.verbose("(appl) >>> {}", realFileName.getFile());
LOGGER.trace("(appl) >>> {}", realFileName.getFile());
} else {
Log.verbose("(appl) ??? base folder: {}", Uri.applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath() + Uri.applicationBasePath + offsetGroup + uri.path);
LOGGER.trace("(appl) ??? base folder: {}",
Uri.applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath() + tmpPath);
}
out = Uri.applicationClass.getResourceAsStream(tmpPath);
LOGGER.trace("(appl) {} getResourceAsStream({})", Uri.applicationClass.getCanonicalName(), tmpPath);
out = Uri.applicationClass.getResourceAsStream("/" + tmpPath);
if (out == null) {
Log.verbose("(appl) ==> element does not exist ...");
// try {
// Log.warning("elements: " + getResourceFiles(applicationClass, applicationBasePath + offsetGroup + "/*.*"));
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
LOGGER.error("(appl) ==> element does not exist ... {}", uri);
/*
try {
LOGGER.warn("elements: " + getResourceFiles(applicationClass,
BASE_RESOURCE_FOLDER + applicationBasePath + offsetGroup + "/*.*"));
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
}
}
if (out == null) {
// search in the libraries ...
if (uri.properties.get("lib") == null) {
Log.verbose(" !! No library specified");
LOGGER.trace(" !! No library specified");
return null;
}
final LibraryElement libraryElement = Uri.libraries.get(uri.properties.get("lib"));
if (libraryElement == null) {
Log.verbose(" Can not get element in library");
LOGGER.trace(" Can not get element in library");
return null;
}
// try {
// Log.warning("elements: " + getResourceFiles(libraryElement.klass, libraryElement.basePath + offsetGroup + "/"));
// LOGGER.warn("elements: " + getResourceFiles(libraryElement.klass, libraryElement.basePath + offsetGroup + "/"));
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
String tmpPath = libraryElement.basePath + offsetGroup + uri.path;
tmpPath = tmpPath.replace("//", "/");
Log.verbose("(lib) Try to load '{}' in {}", tmpPath, libraryElement.klass.getCanonicalName());
String tmpPath = "/" + libraryElement.basePath + offsetGroup + uri.path;
tmpPath = tmpPath.replace("///", "/").replace("//", "/").replaceFirst("^/*", "");
;
LOGGER.trace("(lib) Try to load '{}' in {}", tmpPath, libraryElement.klass.getCanonicalName());
final URL realFileName = libraryElement.klass.getClassLoader().getResource(tmpPath);
if (realFileName != null) {
Log.verbose("(lib) >>> {}", realFileName.getFile());
LOGGER.trace("(lib) >>> {}", realFileName.getFile());
} else {
Log.verbose("(lib) ??? base folder: {}", libraryElement.klass.getProtectionDomain().getCodeSource().getLocation().getPath() + libraryElement.basePath + offsetGroup + uri.path);
LOGGER.trace("(lib) ??? base folder: {}",
libraryElement.klass.getProtectionDomain().getCodeSource().getLocation().getPath() + tmpPath);
}
out = libraryElement.klass.getResourceAsStream(tmpPath);
out = libraryElement.klass.getResourceAsStream("/" + tmpPath);
if (out == null) {
Log.verbose("(lib) ==> element does not exist ...");
LOGGER.trace("(lib) ==> element does not exist ...");
}
}
if (out == null) {
Log.error("Can not load resource: '" + uri + "'");
LOGGER.error("Can not load resource: '" + uri + "'");
} else {
Log.verbose(" =====> DATA LOADED <====== ");
LOGGER.trace(" =====> DATA LOADED <====== ");
}
return out;
}
public static List<Uri> listRecursive(final Uri uri) {
final List<Uri> out = new ArrayList<>();
Log.todo("not implemented function ...");
LOGGER.error("TODO: not implemented function ...");
return out;
}
public static void setApplication(final Class<?> classHandle) {
Uri.setApplication(classHandle, "");
}
public static void setApplication(final Class<?> classHandle, String basePath) {
Log.info("Set application reference : {} base path={}", classHandle.getCanonicalName(), basePath);
LOGGER.info("Set application reference : {} base path={}", classHandle.getCanonicalName(), basePath);
Uri.applicationClass = classHandle;
if (basePath == null || basePath.isEmpty()) {
basePath = "/";
@ -217,9 +199,9 @@ public class Uri {
}
Uri.applicationBasePath = basePath;
}
public static void setGroup(final String groupName, String basePath) {
Log.info("Set Group : {} base path={}", groupName, basePath);
LOGGER.info("Set Group : {} base path={}", groupName, basePath);
if (basePath == null || basePath.isEmpty()) {
basePath = "/";
}
@ -228,7 +210,7 @@ public class Uri {
}
Uri.genericMap.put(groupName.toUpperCase(), basePath);
}
public static Uri valueOf(String value) {
String group = null;
String path = null;
@ -244,16 +226,14 @@ public class Uri {
if (index != -1) {
final String valuesMetadata = value.substring(index + 1);
final String[] elementMetaData = valuesMetadata.split("&");
for (int iii = 0; iii < elementMetaData.length; iii++) {
final String[] keyVal = elementMetaData[iii].split("=", 2);
for (final String element : elementMetaData) {
final String[] keyVal = element.split("=", 2);
if (keyVal.length == 1) {
prop.put(keyVal[0], "");
} else if (keyVal[0].equals("lib")) {
prop.put(keyVal[0], keyVal[1].toLowerCase());
} else {
if (keyVal[0].equals("lib")) {
prop.put(keyVal[0], keyVal[1].toLowerCase());
} else {
prop.put(keyVal[0], keyVal[1]);
}
prop.put(keyVal[0], keyVal[1]);
}
}
path = value.substring(0, index);
@ -262,7 +242,7 @@ public class Uri {
}
return new Uri(group, path, prop);
}
public static void writeAll(final Uri uri, final String data) throws IOException {
BufferedWriter out = null;
try {
@ -270,7 +250,7 @@ public class Uri {
out = new BufferedWriter(fstream);
out.write(data);
} catch (final IOException e) {
Log.error("Error: {}", e.getMessage());
LOGGER.error("Error: {}", e.getMessage());
throw e;
} finally {
if (out != null) {
@ -278,13 +258,13 @@ public class Uri {
out.close();
} catch (final IOException e) {
// TODO Auto-generated catch block
Log.error("Error: ", e);
LOGGER.error("Error: ", e);
throw e;
}
}
}
}
public static void writeAllAppend(final Uri uri, final String data) {
BufferedWriter out = null;
try {
@ -292,29 +272,29 @@ public class Uri {
out = new BufferedWriter(fstream);
out.write(data);
} catch (final IOException e) {
Log.error("Error: " + e.getMessage());
LOGGER.error("Error: " + e.getMessage());
} finally {
if (out != null) {
try {
out.close();
} catch (final IOException e) {
// TODO Auto-generated catch block
Log.error("Error: ", e);
LOGGER.error("Error: ", e);
}
}
}
}
private final String group;
private final String path;
private final Map<String, String> properties;
public Uri(final String path) {
this(null, path);
}
public Uri(final String group, final String path) {
if (group == null) {
this.group = null;
@ -324,7 +304,7 @@ public class Uri {
this.path = path;
this.properties = new HashMap<>();
}
public Uri(final String group, final String path, final Map<String, String> properties) {
if (group == null) {
this.group = null;
@ -334,19 +314,19 @@ public class Uri {
this.path = path;
this.properties = new HashMap<>(properties);
}
public Uri(final String group, final String path, final String lib) {
this(group, path);
if (lib != null) {
this.properties.put("lib", lib.toLowerCase());
}
}
@Override
public Uri clone() {
return new Uri(this.group, this.path, new HashMap<>(this.properties));
}
public boolean exist() {
final InputStream stream = Uri.getStream(this);
if (stream == null) {
@ -360,16 +340,16 @@ public class Uri {
}
return true;
}
public String get() {
return getPath();
}
public String getExtention() {
final String[] ret = this.path.split("\\.");
return ret[ret.length - 1];
}
/**
* Get the filename of the URI with the extension "plop.txt"
* @return simple filename
@ -377,7 +357,7 @@ public class Uri {
public String getFileName() {
return this.path.substring(this.path.lastIndexOf("/") + 1);
}
/**
* Get the filename of the URI without the extension "plop"
* @return simple filename
@ -386,51 +366,51 @@ public class Uri {
final String ext = getExtention();
return this.path.substring(this.path.lastIndexOf("/") + 1, this.path.length() - ext.length() + 1);
}
public String getGroup() {
return this.group;
}
public Uri getParent() {
final String path = this.path.substring(0, this.path.lastIndexOf("/"));
return new Uri(getGroup(), path, this.properties);
}
public String getPath() {
return this.path;
}
public Map<String, String> getproperties() {
return this.properties;
}
public String getProperty(final String key) {
return this.properties.get(key);
}
public String getValue() {
return toString();
}
public boolean hasProperty(final String key) {
return this.properties.containsKey(key);
}
public boolean isEmpty() {
return this.path == null || this.path.isEmpty();
}
public Uri pathAdd(final String value) {
if (this.path.charAt(this.path.length() - 1) == '/') {
return withPath(this.path + value);
}
return withPath(this.path + "/" + value);
}
public void setProperty(final String key, final String value) {
this.properties.put(key, value);
}
@Override
public String toString() {
final StringBuilder out = new StringBuilder();
@ -455,18 +435,18 @@ public class Uri {
}
return out.toString();
}
// Format : DATA:jlfqkjsdflkjqs/sqldkhjflqksdjf/lll.png?lib=ewol
public Uri withGroup(final String group) {
return new Uri(group, this.path, new HashMap<>(this.properties));
}
public Uri withLib(final String lib) {
final Map<String, String> tmp = new HashMap<>(this.properties);
tmp.put("lib", lib);
return new Uri(this.group, this.path, tmp);
}
public Uri withPath(final String path) {
return new Uri(this.group, path, new HashMap<>(this.properties));
}

View File

@ -1,76 +0,0 @@
package org.atriasoft.etk.internal;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log {
private static final boolean FORCE_ALL = false;
private static final String LIB_NAME = "etk";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
public static void critical(final Exception e, final String data) {
e.printStackTrace();
if (PRINT_CRITICAL || FORCE_ALL) {
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
}
}
public static void critical(final String data, final Object... objects) {
if (PRINT_CRITICAL || FORCE_ALL) {
Logger.critical(LIB_NAME_DRAW, data, objects);
}
}
public static void debug(final String data, final Object... objects) {
if (PRINT_DEBUG || FORCE_ALL) {
Logger.debug(LIB_NAME_DRAW, data, objects);
}
}
public static void error(final String data, final Object... objects) {
if (PRINT_ERROR || FORCE_ALL) {
Logger.error(LIB_NAME_DRAW, data, objects);
}
}
public static void info(final String data, final Object... objects) {
if (PRINT_INFO || FORCE_ALL) {
Logger.info(LIB_NAME_DRAW, data, objects);
}
}
public static void print(final String data, final Object... objects) {
if (PRINT_PRINT || FORCE_ALL) {
Logger.print(LIB_NAME_DRAW, data, objects);
}
}
public static void todo(final String data, final Object... objects) {
if (PRINT_TODO || FORCE_ALL) {
Logger.todo(LIB_NAME_DRAW, data, objects);
}
}
public static void verbose(final String data, final Object... objects) {
if (PRINT_VERBOSE || FORCE_ALL) {
Logger.verbose(LIB_NAME_DRAW, data, objects);
}
}
public static void warning(final String data, final Object... objects) {
if (PRINT_WARNING || FORCE_ALL) {
Logger.warning(LIB_NAME_DRAW, data, objects);
}
}
private Log() {}
}

View File

@ -2,9 +2,12 @@ package org.atriasoft.etk.math;
import java.text.DecimalFormat;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FMath {
final static Logger LOGGER = LoggerFactory.getLogger(FMath.class);
public static final float PI = (float) Math.PI;
public static float abs(final float a) {
@ -202,7 +205,7 @@ public class FMath {
}
val *= 2;
}
Log.critical("impossible CASE....");
LOGGER.error("impossible CASE....");
return val;
}

View File

@ -5,7 +5,6 @@ package org.atriasoft.etk.math;
* sx shx tx
* sy shy ty
*/
@SuppressWarnings("preview")
public record Matrix2x3f(
float sx,
float shy,

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Matrix3f(
float a1,
float a2,
@ -13,16 +12,17 @@ public record Matrix3f(
float c1,
float c2,
float c3) {
/**
* create a skew-symmetric matrix using a given vector that can be used to compute cross product with another vector using matrix multiplication
* @param vector Vector to comute
* @return Matrix to compute
*/
public static Matrix3f computeSkewSymmetricMatrixForCrossProduct(final Vector3f vector) {
return new Matrix3f(0.0f, -vector.z(), vector.y(), vector.z(), 0.0f, -vector.x(), -vector.y(), vector.x(), 0.0f);
return new Matrix3f(0.0f, -vector.z(), vector.y(), vector.z(), 0.0f, -vector.x(), -vector.y(), vector.x(),
0.0f);
}
/**
* Create a matrix 3D with a simple rotation
* @param normal vector aroud witch apply the rotation
@ -33,33 +33,33 @@ public record Matrix3f(
final float cosVal = (float) Math.cos(angleRad);
final float sinVal = (float) Math.sin(angleRad);
final float invVal = 1.0f - cosVal;
// set rotation :
float a1 = normal.x() * normal.x() * invVal + cosVal;
float a2 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
float a3 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
float b1 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
float b2 = normal.y() * normal.y() * invVal + cosVal;
float b3 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
float c1 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
float c2 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
float c3 = normal.z() * normal.z() * invVal + cosVal;
// set rotation :
final float a1 = normal.x() * normal.x() * invVal + cosVal;
final float a2 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
final float a3 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
final float b1 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
final float b2 = normal.y() * normal.y() * invVal + cosVal;
final float b3 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
final float c1 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
final float c2 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
final float c3 = normal.z() * normal.z() * invVal + cosVal;
return new Matrix3f(a1, a2, a3, b1, b2, b3, c1, c2, c3);
}
/**
* create a Identity matrix
* @return created new matrix
*/
public static final Matrix3f IDENTITY = new Matrix3f(1, 0, 0, 0, 1, 0, 0, 0, 1);
/**
* create a ZERO matrix
* @return created new matrix
*/
public static final Matrix3f ZERO = new Matrix3f(0, 0, 0, 0, 0, 0, 0, 0, 0);
/**
* Configuration constructorwith single value.
* @param value single value
@ -67,7 +67,7 @@ public record Matrix3f(
public Matrix3f(final float value) {
this(value, value, value, value, value, value, value, value, value);
}
/**
* Configuration constructor.
* @param a1 element 0x0
@ -80,7 +80,8 @@ public record Matrix3f(
* @param c2 element 2x1
* @param c3 element 2x2
*/
public Matrix3f(final float a1, final float a2, final float a3, final float b1, final float b2, final float b3, final float c1, final float c2, final float c3) {
public Matrix3f(final float a1, final float a2, final float a3, final float b1, final float b2, final float b3,
final float c1, final float c2, final float c3) {
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
@ -91,15 +92,16 @@ public record Matrix3f(
this.c2 = c2;
this.c3 = c3;
}
/**
* absolutise the matrix
*/
@CheckReturnValue
public Matrix3f abs() {
return new Matrix3f(Math.abs(this.a1), Math.abs(this.a2), Math.abs(this.a3), Math.abs(this.b1), Math.abs(this.b2), Math.abs(this.b3), Math.abs(this.c1), Math.abs(this.c2), Math.abs(this.c3));
return new Matrix3f(Math.abs(this.a1), Math.abs(this.a2), Math.abs(this.a3), Math.abs(this.b1),
Math.abs(this.b2), Math.abs(this.b3), Math.abs(this.c1), Math.abs(this.c2), Math.abs(this.c3));
}
/**
* Operator+= Addition an other matrix with this one
* @param obj Reference on the external object
@ -107,60 +109,53 @@ public record Matrix3f(
*/
@CheckReturnValue
public Matrix3f add(final Matrix3f obj) {
return new Matrix3f(this.a1 + obj.a1, this.a2 + obj.a2, this.a3 + obj.a3, this.b1 + obj.b1, this.b2 + obj.b2, this.b3 + obj.b3, this.c1 + obj.c1, this.c2 + obj.c2, this.c3 + obj.c3);
return new Matrix3f(this.a1 + obj.a1, this.a2 + obj.a2, this.a3 + obj.a3, this.b1 + obj.b1, this.b2 + obj.b2,
this.b3 + obj.b3, this.c1 + obj.c1, this.c2 + obj.c2, this.c3 + obj.c3);
}
// Return a skew-symmetric matrix using a given vector that can be used
// to compute cross product with another vector using matrix multiplication
@CheckReturnValue
public Matrix3f computeSkewSymmetricMatrixForCrossProductNew(final Vector3f vector) {
return new Matrix3f(0.0f, -vector.z(), vector.y(), vector.z(), 0, -vector.x(), -vector.y(), vector.x(), 0.0f);
}
/**
* Computes the determinant of the matrix.
* @return The determinent Value.
*/
@CheckReturnValue
public float determinant() {
return this.a1 * (this.b2 * this.c3 - this.c2 * this.b3) - this.a2 * (this.b1 * this.c3 - this.c1 * this.b3) + this.a3 * (this.b1 * this.c2 - this.c1 * this.b2);
return this.a1 * (this.b2 * this.c3 - this.c2 * this.b3) - this.a2 * (this.b1 * this.c3 - this.c1 * this.b3)
+ this.a3 * (this.b1 * this.c2 - this.c1 * this.b2);
}
/**
* devide a value
* @param value value to devide all the matrix
*/
@CheckReturnValue
public Matrix3f divide(final float value) {
return new Matrix3f(this.a1 / value, this.a2 / value, this.a3 / value, this.b1 / value, this.b2 / value, this.b3 / value, this.c1 / value, this.c2 / value, this.c3 / value);
return new Matrix3f(this.a1 / value, this.a2 / value, this.a3 / value, this.b1 / value, this.b2 / value,
this.b3 / value, this.c1 / value, this.c2 / value, this.c3 / value);
}
@CheckReturnValue
public float get(final int iii) {
switch (iii) {
case 0:
return this.a1;
case 1:
return this.a2;
case 2:
return this.a3;
case 3:
return this.b1;
case 4:
return this.b2;
case 5:
return this.b3;
case 6:
return this.c1;
case 7:
return this.c2;
case 8:
return this.c3;
default:
return 0;
}
return switch (iii) {
case 0 -> this.a1;
case 1 -> this.a2;
case 2 -> this.a3;
case 3 -> this.b1;
case 4 -> this.b2;
case 5 -> this.b3;
case 6 -> this.c1;
case 7 -> this.c2;
case 8 -> this.c3;
default -> 0;
};
}
/**
* get the colom id values
* @param iii Id of the colomn
@ -175,7 +170,7 @@ public record Matrix3f(
}
return new Vector3f(this.a3, this.b3, this.c3);
}
/**
* get the row id values
* @param iii Id of the row
@ -190,7 +185,7 @@ public record Matrix3f(
}
return new Vector3f(this.c1, this.c2, this.c3);
}
/**
* Calculate the trace of the matrix
* @return value of addition of all element in the diagonal
@ -199,7 +194,7 @@ public record Matrix3f(
public float getTrace() {
return (this.a1 + this.b2 + this.c3);
}
/**
* Inverts the current matrix.
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
@ -208,17 +203,19 @@ public record Matrix3f(
public Matrix3f inverse() {
final float det = determinant();
//assert(Math.abs(det) > MACHINEEPSILON);
return new Matrix3f((this.b2 * this.c3 - this.c2 * this.b3) / det, -(this.a2 * this.c3 - this.c2 * this.a3) / det, (this.a2 * this.b3 - this.a3 * this.b2) / det,
-(this.b1 * this.c3 - this.c1 * this.b3) / det, (this.a1 * this.c3 - this.c1 * this.a3) / det, -(this.a1 * this.b3 - this.b1 * this.a3) / det,
(this.b1 * this.c2 - this.c1 * this.b2) / det, -(this.a1 * this.c2 - this.c1 * this.a2) / det, (this.a1 * this.b2 - this.a2 * this.b1) / det);
return new Matrix3f((this.b2 * this.c3 - this.c2 * this.b3) / det,
-(this.a2 * this.c3 - this.c2 * this.a3) / det, (this.a2 * this.b3 - this.a3 * this.b2) / det,
-(this.b1 * this.c3 - this.c1 * this.b3) / det, (this.a1 * this.c3 - this.c1 * this.a3) / det,
-(this.a1 * this.b3 - this.b1 * this.a3) / det, (this.b1 * this.c2 - this.c1 * this.b2) / det,
-(this.a1 * this.c2 - this.c1 * this.a2) / det, (this.a1 * this.b2 - this.a2 * this.b1) / det);
}
// Overloaded operator for the negative of the matrix
@CheckReturnValue
public Matrix3f invert() {
return new Matrix3f(-this.a1, -this.a2, -this.a3, -this.b1, -this.b2, -this.b3, -this.c1, -this.c2, -this.c3);
}
/**
* In-Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -227,12 +224,13 @@ public record Matrix3f(
*/
@CheckReturnValue
public boolean isDifferent(final Matrix3f obj) {
if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2 || this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) {
if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2
|| this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) {
return true;
}
return false;
}
/**
* Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -241,12 +239,13 @@ public record Matrix3f(
*/
@CheckReturnValue
boolean isEqual(final Matrix3f obj) {
if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2 || this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) {
if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2
|| this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) {
return false;
}
return true;
}
/**
* Operator-= Decrement an other matrix with this one
* @param obj Reference on the external object
@ -254,9 +253,10 @@ public record Matrix3f(
*/
@CheckReturnValue
public Matrix3f less(final Matrix3f obj) {
return new Matrix3f(this.a1 - obj.a1, this.a2 - obj.a2, this.a3 - obj.a3, this.b1 - obj.b1, this.b2 - obj.b2, this.b3 - obj.b3, this.c1 - obj.c1, this.c2 - obj.c2, this.c3 - obj.c3);
return new Matrix3f(this.a1 - obj.a1, this.a2 - obj.a2, this.a3 - obj.a3, this.b1 - obj.b1, this.b2 - obj.b2,
this.b3 - obj.b3, this.c1 - obj.c1, this.c2 - obj.c2, this.c3 - obj.c3);
}
/**
* Operator*= Multiplication a value
* @param value value to multiply all the matrix
@ -264,9 +264,10 @@ public record Matrix3f(
*/
@CheckReturnValue
public Matrix3f multiply(final float value) {
return new Matrix3f(this.a1 * value, this.a2 * value, this.a3 * value, this.b1 * value, this.b2 * value, this.b3 * value, this.c1 * value, this.c2 * value, this.c3 * value);
return new Matrix3f(this.a1 * value, this.a2 * value, this.a3 * value, this.b1 * value, this.b2 * value,
this.b3 * value, this.c1 * value, this.c2 * value, this.c3 * value);
}
/**
* Operator*= Multiplication an other matrix with this one
* @param obj Reference on the external object
@ -280,12 +281,12 @@ public record Matrix3f(
final float a2 = this.a1 * obj.a2 + this.a2 * obj.b2 + this.a3 * obj.c2;
final float b2 = this.b1 * obj.a2 + this.b2 * obj.b2 + this.b3 * obj.c2;
final float c2 = this.c1 * obj.a2 + this.c2 * obj.b2 + this.c3 * obj.c2;
float tmpA3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3;
float tmpB3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * obj.c3;
float tmpC3 = this.c1 * obj.a3 + this.c2 * obj.b3 + this.c3 * obj.c3;
final float tmpA3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3;
final float tmpB3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * obj.c3;
final float tmpC3 = this.c1 * obj.a3 + this.c2 * obj.b3 + this.c3 * obj.c3;
return new Matrix3f(a1, a2, tmpA3, b1, b2, tmpB3, c1, c2, tmpC3);
}
/**
* Operator* apply matrix on a vector
* @param point Point value to apply the matrix
@ -293,18 +294,20 @@ public record Matrix3f(
*/
@CheckReturnValue
public Vector3f multiply(final Vector3f point) {
return new Vector3f((float) (point.x() * (double) this.a1 + point.y() * (double) this.a2 + point.z() * (double) this.a3),
return new Vector3f(
(float) (point.x() * (double) this.a1 + point.y() * (double) this.a2 + point.z() * (double) this.a3),
(float) (point.x() * (double) this.b1 + point.y() * (double) this.b2 + point.z() * (double) this.b3),
(float) (point.x() * (double) this.c1 + point.y() * (double) this.c2 + point.z() * (double) this.c3));
}
@Override
public String toString() {
return "Matrix3f(" + FMath.floatToString(this.a1) + "," + FMath.floatToString(this.a2) + "," + FMath.floatToString(this.a3) + "," + FMath.floatToString(this.b1) + ","
+ FMath.floatToString(this.b2) + "," + FMath.floatToString(this.b3) + "," + FMath.floatToString(this.c1) + "," + FMath.floatToString(this.c2) + "," + FMath.floatToString(this.c3)
+ ")";
return "Matrix3f(" + FMath.floatToString(this.a1) + "," + FMath.floatToString(this.a2) + ","
+ FMath.floatToString(this.a3) + "," + FMath.floatToString(this.b1) + "," + FMath.floatToString(this.b2)
+ "," + FMath.floatToString(this.b3) + "," + FMath.floatToString(this.c1) + ","
+ FMath.floatToString(this.c2) + "," + FMath.floatToString(this.c3) + ")";
}
/**
* get a transpose matrix of this one.
* @return the transpose matrix

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Matrix4f(
float a1,
float b1,
@ -30,27 +29,33 @@ public record Matrix4f(
* @param zFar Z maximum size of the frustum
* @return New matrix of the transformation requested
*/
public static Matrix4f createMatrixFrustum(final float xmin, final float xmax, final float ymin, final float ymax, final float zNear, final float zFar) {
float a1 = (2.0f * zNear) / (xmax - xmin);
float b1 = 0;
float c1 = (xmax + xmin) / (xmax - xmin);
float d1 = 0;
float a2 = 0;
float b2 = (2.0f * zNear) / (ymax - ymin);
float c2 = (ymax + ymin) / (ymax - ymin);
float d2 = 0;
float a3 = 0;
float b3 = 0;
float c3 = -(zFar + zNear) / (zFar - zNear);
float d3 = -(2.0f * zFar * zNear) / (zFar - zNear);
float a4 = 0;
float b4 = 0;
float c4 = -1.0f;
float d4 = 0;
public static Matrix4f createMatrixFrustum(
final float xmin,
final float xmax,
final float ymin,
final float ymax,
final float zNear,
final float zFar) {
final float a1 = (2.0f * zNear) / (xmax - xmin);
final float b1 = 0;
final float c1 = (xmax + xmin) / (xmax - xmin);
final float d1 = 0;
final float a2 = 0;
final float b2 = (2.0f * zNear) / (ymax - ymin);
final float c2 = (ymax + ymin) / (ymax - ymin);
final float d2 = 0;
final float a3 = 0;
final float b3 = 0;
final float c3 = -(zFar + zNear) / (zFar - zNear);
final float d3 = -(2.0f * zFar * zNear) / (zFar - zNear);
final float a4 = 0;
final float b4 = 0;
final float c4 = -1.0f;
final float d4 = 0;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
}
/**
* Create projection matrix with camera property (camera view in -z axis)
* @param eye Optical center of the camera
@ -64,29 +69,29 @@ public record Matrix4f(
xaxis = xaxis.safeNormalize();
final Vector3f up2 = xaxis.cross(forward);
xaxis = xaxis.safeNormalize(); // TODO ??????
float a1 = xaxis.x();
float b1 = up2.x();
float c1 = forward.x();
float d1 = eye.x();
float a2 = xaxis.y();
float b2 = up2.y();
float c2 = forward.y();
float d2 = eye.y();
float a3 = xaxis.z();
float b3 = up2.z();
float c3 = forward.z();
float d3 = eye.z();
float a4 = 0.0f;
float b4 = 0.0f;
float c4 = 0.0f;
float d4 = 1.0f;
final float a1 = xaxis.x();
final float b1 = up2.x();
final float c1 = forward.x();
final float d1 = eye.x();
final float a2 = xaxis.y();
final float b2 = up2.y();
final float c2 = forward.y();
final float d2 = eye.y();
final float a3 = xaxis.z();
final float b3 = up2.z();
final float c3 = forward.z();
final float d3 = eye.z();
final float a4 = 0.0f;
final float b4 = 0.0f;
final float c4 = 0.0f;
final float d4 = 1.0f;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
}
/**
* Create orthogonal projection matrix with the box parameter (camera view in -z axis)
* @param left left size of the camera
@ -97,29 +102,35 @@ public record Matrix4f(
* @param farVal Z far size of the camera
* @return New matrix of the transformation requested
*/
public static Matrix4f createMatrixOrtho(final float left, final float right, final float bottom, final float top, final float nearVal, final float farVal) {
float b1 = 0;
float c1 = 0;
float a2 = 0;
float c2 = 0;
float a3 = 0;
float b3 = 0;
float a4 = 0;
float b4 = 0;
float c4 = 0;
float a1 = 2.0f / (right - left);
float b2 = 2.0f / (top - bottom);
float c3 = -2.0f / (farVal - nearVal);
float d1 = -1.0f * (right + left) / (right - left);
float d2 = -1.0f * (top + bottom) / (top - bottom);
float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
float d4 = 1.0f;
public static Matrix4f createMatrixOrtho(
final float left,
final float right,
final float bottom,
final float top,
final float nearVal,
final float farVal) {
final float b1 = 0;
final float c1 = 0;
final float a2 = 0;
final float c2 = 0;
final float a3 = 0;
final float b3 = 0;
final float a4 = 0;
final float b4 = 0;
final float c4 = 0;
final float a1 = 2.0f / (right - left);
final float b2 = 2.0f / (top - bottom);
final float c3 = -2.0f / (farVal - nearVal);
final float d1 = -1.0f * (right + left) / (right - left);
final float d2 = -1.0f * (top + bottom) / (top - bottom);
final float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
final float d4 = 1.0f;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
}
/**
* Create projection matrix with human repensentation view (camera view in -z axis)
* @param foxy Focal in radian of the camera
@ -128,17 +139,21 @@ public record Matrix4f(
* @param zFar Z far size of the camera
* @return New matrix of the transformation requested
*/
public static Matrix4f createMatrixPerspective(final float foxy, final float aspect, final float zNear, final float zFar) {
public static Matrix4f createMatrixPerspective(
final float foxy,
final float aspect,
final float zNear,
final float zFar) {
//TKDEBUG("drax perspective: foxy=" << foxy << "->" << aspect << " " << zNear << "->" << zFar);
final float xmax = zNear * (float) Math.tan(foxy / 2.0);
final float xmin = -xmax;
final float ymin = xmin / aspect;
final float ymax = xmax / aspect;
//TKDEBUG("drax perspective: " << xmin << "->" << xmax << " & " << ymin << "->" << ymax << " " << zNear << "->" << zFar);
return createMatrixFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
/**
* Create a matrix 3D with a simple rotation
* @param normal vector aroud witch apply the rotation
@ -149,20 +164,20 @@ public record Matrix4f(
float a1 = 1.0f;
float b1 = 0;
float c1 = 0;
float d1 = 0;
final float d1 = 0;
float a2 = 0;
float b2 = 1.0f;
float c2 = 0;
float d2 = 0;
final float d2 = 0;
float a3 = 0;
float b3 = 0;
float c3 = 1.0f;
float d3 = 0;
float a4 = 0;
float b4 = 0;
float c4 = 0;
float d4 = 1.0f;
final float d3 = 0;
final float a4 = 0;
final float b4 = 0;
final float c4 = 0;
final float d4 = 1.0f;
final float cosVal = (float) Math.cos(angleRad);
final float sinVal = (float) Math.sin(angleRad);
final float invVal = 1.0f - cosVal;
@ -170,22 +185,22 @@ public record Matrix4f(
a1 = normal.x() * normal.x() * invVal + cosVal;
b1 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
c1 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
a2 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
b2 = normal.y() * normal.y() * invVal + cosVal;
c2 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
a3 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
b3 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
c3 = normal.z() * normal.z() * invVal + cosVal;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
}
//! @notindoc
public static Matrix4f createMatrixRotate2(final Vector3f vect) {
return createMatrixLookAt(vect, new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
}
/**
* Create a matrix 3D with a simple scale
* @param scale 3 dimension scale
@ -194,37 +209,37 @@ public record Matrix4f(
public static Matrix4f createMatrixScale(final Vector3f scale) {
return new Matrix4f(scale.x(), 0, 0, 0, 0, scale.y(), 0, 0, 0, 0, scale.z(), 0, 0, 0, 0, 1);
}
public static Matrix4f createMatrixScale(final float xxx, final float yyy, final float zzz) {
return new Matrix4f(xxx, 0, 0, 0, 0, yyy, 0, 0, 0, 0, zzz, 0, 0, 0, 0, 1);
}
/**
* Create a matrix 3D with a simple translation
* @param translate 3 dimention translation
* @return New matrix of the transformation requested
*/
public static Matrix4f createMatrixTranslate(final Vector3f translate) {
float a1 = 1.0f;
float b1 = 0;
float c1 = 0;
float d1 = translate.x();
float a2 = 0;
float b2 = 1.0f;
float c2 = 0;
float d2 = translate.y();
float a3 = 0;
float b3 = 0;
float c3 = 1.0f;
float d3 = translate.z();
float a4 = 0;
float b4 = 0;
float c4 = 0;
float d4 = 1.0f;
final float a1 = 1.0f;
final float b1 = 0;
final float c1 = 0;
final float d1 = translate.x();
final float a2 = 0;
final float b2 = 1.0f;
final float c2 = 0;
final float d2 = translate.y();
final float a3 = 0;
final float b3 = 0;
final float c3 = 1.0f;
final float d3 = translate.z();
final float a4 = 0;
final float b4 = 0;
final float c4 = 0;
final float d4 = 1.0f;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
}
/**
* Configuration constructor.
* @param a1 1st colomn, 1 line value
@ -244,8 +259,9 @@ public record Matrix4f(
* @param c4 3rd colomn, 4 line value
* @param d4 4th colomn, 4 line value
*/
public Matrix4f(final float a1, final float b1, final float c1, final float d1, final float a2, final float b2, final float c2, final float d2, final float a3, final float b3, final float c3,
final float d3, final float a4, final float b4, final float c4, final float d4) {
public Matrix4f(final float a1, final float b1, final float c1, final float d1, final float a2, final float b2,
final float c2, final float d2, final float a3, final float b3, final float c3, final float d3,
final float a4, final float b4, final float c4, final float d4) {
this.a1 = a1;
this.b1 = b1;
this.c1 = c1;
@ -263,112 +279,135 @@ public record Matrix4f(
this.c4 = c4;
this.d4 = d4;
}
/**
* Configuration constructor.
* @param values vector of values
*/
public Matrix4f(final float[] values) {
this(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10], values[11], values[12], values[13], values[14], values[15]);
this(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8],
values[9], values[10], values[11], values[12], values[13], values[14], values[15]);
}
public Matrix4f(final Matrix3f matrix) {
this(matrix.a1(), matrix.a2(), matrix.a3(), 0, matrix.b1(), matrix.b2(), matrix.b3(), 0, matrix.c1(), matrix.c2(), matrix.c3(), 0, 0, 0, 0, 1);
this(matrix.a1(), matrix.a2(), matrix.a3(), 0, matrix.b1(), matrix.b2(), matrix.b3(), 0, matrix.c1(),
matrix.c2(), matrix.c3(), 0, 0, 0, 0, 1);
}
/**
* Operator+= Addition an other matrix with this one
* @param obj Reference on the external object
*/
@CheckReturnValue
public Matrix4f add(final Matrix4f obj) {
return new Matrix4f(this.a1 + obj.a1, this.b1 + obj.b1, this.c1 + obj.c1, this.d1 + obj.d1, this.a2 + obj.a2, this.b2 + obj.b2, this.c2 + obj.c2, this.d2 + obj.d2, this.a3 + obj.a3,
this.b3 + obj.b3, this.c3 + obj.c3, this.d3 + obj.d3, this.a4 + obj.a4, this.b4 + obj.b4, this.c4 + obj.c4, this.d4 + obj.d4);
return new Matrix4f(this.a1 + obj.a1, this.b1 + obj.b1, this.c1 + obj.c1, this.d1 + obj.d1, this.a2 + obj.a2,
this.b2 + obj.b2, this.c2 + obj.c2, this.d2 + obj.d2, this.a3 + obj.a3, this.b3 + obj.b3,
this.c3 + obj.c3, this.d3 + obj.d3, this.a4 + obj.a4, this.b4 + obj.b4, this.c4 + obj.c4,
this.d4 + obj.d4);
}
/**
* Operator-= Decrement an other matrix with this one
* @param obj Reference on the external object
*/
@CheckReturnValue
public Matrix4f decrement(final Matrix4f obj) {
return new Matrix4f(this.a1 - obj.a1, this.b1 - obj.b1, this.c1 - obj.c1, this.d1 - obj.d1, this.a2 - obj.a2, this.b2 - obj.b2, this.c2 - obj.c2, this.d2 - obj.d2, this.a3 - obj.a3,
this.b3 - obj.b3, this.c3 - obj.c3, this.d3 - obj.d3, this.a4 - obj.a4, this.b4 - obj.b4, this.c4 - obj.c4, this.d4 - obj.d4);
return new Matrix4f(this.a1 - obj.a1, this.b1 - obj.b1, this.c1 - obj.c1, this.d1 - obj.d1, this.a2 - obj.a2,
this.b2 - obj.b2, this.c2 - obj.c2, this.d2 - obj.d2, this.a3 - obj.a3, this.b3 - obj.b3,
this.c3 - obj.c3, this.d3 - obj.d3, this.a4 - obj.a4, this.b4 - obj.b4, this.c4 - obj.c4,
this.d4 - obj.d4);
}
private float coFactorRaw0Col0() {
return this.b2 * this.c3 * this.d4 - this.b2 * this.d3 * this.c4 - this.c2 * this.b3 * this.d4 + this.c2 * this.d3 * this.b4 + this.d2 * this.b3 * this.c4 - this.d2 * this.c3 * this.b4;
return this.b2 * this.c3 * this.d4 - this.b2 * this.d3 * this.c4 - this.c2 * this.b3 * this.d4
+ this.c2 * this.d3 * this.b4 + this.d2 * this.b3 * this.c4 - this.d2 * this.c3 * this.b4;
}
private float coFactorRaw0Col1() {
return this.a2 * this.c3 * this.d4 - this.a2 * this.d3 * this.c4 - this.c2 * this.a3 * this.d4 + this.c2 * this.d3 * this.a4 + this.d2 * this.a3 * this.c4 - this.d2 * this.c3 * this.a4;
return this.a2 * this.c3 * this.d4 - this.a2 * this.d3 * this.c4 - this.c2 * this.a3 * this.d4
+ this.c2 * this.d3 * this.a4 + this.d2 * this.a3 * this.c4 - this.d2 * this.c3 * this.a4;
}
private float coFactorRaw0Col2() {
return this.a2 * this.b3 * this.d4 - this.a2 * this.d3 * this.b4 - this.b2 * this.a3 * this.d4 + this.b2 * this.d3 * this.a4 + this.d2 * this.a3 * this.b4 - this.d2 * this.b3 * this.a4;
return this.a2 * this.b3 * this.d4 - this.a2 * this.d3 * this.b4 - this.b2 * this.a3 * this.d4
+ this.b2 * this.d3 * this.a4 + this.d2 * this.a3 * this.b4 - this.d2 * this.b3 * this.a4;
}
private float coFactorRaw0Col3() {
return this.a2 * this.b3 * this.c4 - this.a2 * this.c3 * this.b4 - this.b2 * this.a3 * this.c4 + this.b2 * this.c3 * this.a4 + this.c2 * this.a3 * this.b4 - this.c2 * this.b3 * this.a4;
return this.a2 * this.b3 * this.c4 - this.a2 * this.c3 * this.b4 - this.b2 * this.a3 * this.c4
+ this.b2 * this.c3 * this.a4 + this.c2 * this.a3 * this.b4 - this.c2 * this.b3 * this.a4;
}
private float coFactorRaw1Col0() {
return this.b1 * this.c3 * this.d4 - this.b1 * this.d3 * this.c4 - this.c1 * this.b3 * this.d4 + this.c1 * this.d3 * this.b4 + this.d1 * this.b3 * this.c4 - this.d1 * this.c3 * this.b4;
return this.b1 * this.c3 * this.d4 - this.b1 * this.d3 * this.c4 - this.c1 * this.b3 * this.d4
+ this.c1 * this.d3 * this.b4 + this.d1 * this.b3 * this.c4 - this.d1 * this.c3 * this.b4;
}
private float coFactorRaw1Col1() {
return this.a1 * this.c3 * this.d4 - this.a1 * this.d3 * this.c4 - this.c1 * this.a3 * this.d4 + this.c1 * this.d3 * this.a4 + this.d1 * this.a3 * this.c4 - this.d1 * this.c3 * this.a4;
return this.a1 * this.c3 * this.d4 - this.a1 * this.d3 * this.c4 - this.c1 * this.a3 * this.d4
+ this.c1 * this.d3 * this.a4 + this.d1 * this.a3 * this.c4 - this.d1 * this.c3 * this.a4;
}
private float coFactorRaw1Col2() {
return this.a1 * this.b3 * this.d4 - this.a1 * this.d3 * this.b4 - this.b1 * this.a3 * this.d4 + this.b1 * this.d3 * this.a4 + this.d1 * this.a3 * this.b4 - this.d1 * this.b3 * this.a4;
return this.a1 * this.b3 * this.d4 - this.a1 * this.d3 * this.b4 - this.b1 * this.a3 * this.d4
+ this.b1 * this.d3 * this.a4 + this.d1 * this.a3 * this.b4 - this.d1 * this.b3 * this.a4;
}
private float coFactorRaw1Col3() {
return this.a1 * this.b3 * this.c4 - this.a1 * this.c3 * this.b4 - this.b1 * this.a3 * this.c4 + this.b1 * this.c3 * this.a4 + this.c1 * this.a3 * this.b4 - this.c1 * this.b3 * this.a4;
return this.a1 * this.b3 * this.c4 - this.a1 * this.c3 * this.b4 - this.b1 * this.a3 * this.c4
+ this.b1 * this.c3 * this.a4 + this.c1 * this.a3 * this.b4 - this.c1 * this.b3 * this.a4;
}
private float coFactorRaw2Col0() {
return this.b1 * this.c2 * this.d4 - this.b1 * this.d2 * this.c4 - this.c1 * this.b2 * this.d4 + this.c1 * this.d2 * this.b4 + this.d1 * this.b2 * this.c4 - this.d1 * this.c2 * this.b4;
return this.b1 * this.c2 * this.d4 - this.b1 * this.d2 * this.c4 - this.c1 * this.b2 * this.d4
+ this.c1 * this.d2 * this.b4 + this.d1 * this.b2 * this.c4 - this.d1 * this.c2 * this.b4;
}
private float coFactorRaw2Col1() {
return this.a1 * this.c2 * this.d4 - this.a1 * this.d2 * this.c4 - this.c1 * this.a2 * this.d4 + this.c1 * this.d2 * this.a4 + this.d1 * this.a2 * this.c4 - this.d1 * this.c2 * this.a4;
return this.a1 * this.c2 * this.d4 - this.a1 * this.d2 * this.c4 - this.c1 * this.a2 * this.d4
+ this.c1 * this.d2 * this.a4 + this.d1 * this.a2 * this.c4 - this.d1 * this.c2 * this.a4;
}
private float coFactorRaw2Col2() {
return this.a1 * this.b2 * this.d4 - this.a1 * this.d2 * this.b4 - this.b1 * this.a2 * this.d4 + this.b1 * this.d2 * this.a4 + this.d1 * this.a2 * this.b4 - this.d1 * this.b2 * this.a4;
return this.a1 * this.b2 * this.d4 - this.a1 * this.d2 * this.b4 - this.b1 * this.a2 * this.d4
+ this.b1 * this.d2 * this.a4 + this.d1 * this.a2 * this.b4 - this.d1 * this.b2 * this.a4;
}
private float coFactorRaw2Col3() {
return this.a1 * this.b2 * this.c4 - this.a1 * this.c2 * this.b4 - this.b1 * this.a2 * this.c4 + this.b1 * this.c2 * this.a4 + this.c1 * this.a2 * this.b4 - this.c1 * this.b2 * this.a4;
return this.a1 * this.b2 * this.c4 - this.a1 * this.c2 * this.b4 - this.b1 * this.a2 * this.c4
+ this.b1 * this.c2 * this.a4 + this.c1 * this.a2 * this.b4 - this.c1 * this.b2 * this.a4;
}
private float coFactorRaw3Col0() {
return this.b1 * this.c2 * this.d3 - this.b1 * this.d2 * this.c3 - this.c1 * this.b2 * this.d3 + this.c1 * this.d2 * this.b3 + this.d1 * this.b2 * this.c3 - this.d1 * this.c2 * this.b3;
return this.b1 * this.c2 * this.d3 - this.b1 * this.d2 * this.c3 - this.c1 * this.b2 * this.d3
+ this.c1 * this.d2 * this.b3 + this.d1 * this.b2 * this.c3 - this.d1 * this.c2 * this.b3;
}
private float coFactorRaw3Col1() {
return this.a1 * this.c2 * this.d3 - this.a1 * this.d2 * this.c3 - this.c1 * this.a2 * this.d3 + this.c1 * this.d2 * this.a3 + this.d1 * this.a2 * this.c3 - this.d1 * this.c2 * this.a3;
return this.a1 * this.c2 * this.d3 - this.a1 * this.d2 * this.c3 - this.c1 * this.a2 * this.d3
+ this.c1 * this.d2 * this.a3 + this.d1 * this.a2 * this.c3 - this.d1 * this.c2 * this.a3;
}
private float coFactorRaw3Col2() {
return this.a1 * this.b2 * this.d3 - this.a1 * this.d2 * this.b3 - this.b1 * this.a2 * this.d3 + this.b1 * this.d2 * this.a3 + this.d1 * this.a2 * this.b3 - this.d1 * this.b2 * this.a3;
return this.a1 * this.b2 * this.d3 - this.a1 * this.d2 * this.b3 - this.b1 * this.a2 * this.d3
+ this.b1 * this.d2 * this.a3 + this.d1 * this.a2 * this.b3 - this.d1 * this.b2 * this.a3;
}
private float coFactorRaw3Col3() {
return this.a1 * this.b2 * this.c3 - this.a1 * this.c2 * this.b3 - this.b1 * this.a2 * this.c3 + this.b1 * this.c2 * this.a3 + this.c1 * this.a2 * this.b3 - this.c1 * this.b2 * this.a3;
return this.a1 * this.b2 * this.c3 - this.a1 * this.c2 * this.b3 - this.b1 * this.a2 * this.c3
+ this.b1 * this.c2 * this.a3 + this.c1 * this.a2 * this.b3 - this.c1 * this.b2 * this.a3;
}
/**
* Computes the determinant of the matrix.
* @return The determinent Value.
*/
// https://www.dcode.fr/determinant-matrice
@CheckReturnValue
public float determinant() {
return this.a1 * coFactorRaw0Col0() - this.b1 * coFactorRaw0Col1() + this.c1 * coFactorRaw0Col2() - this.d1 * coFactorRaw0Col3();
return this.a1 * coFactorRaw0Col0() - this.b1 * coFactorRaw0Col1() + this.c1 * coFactorRaw0Col2()
- this.d1 * coFactorRaw0Col3();
/*
return a *(f *k *p f *l *o g *j *p +g *l *n +h *j *o h *k *n )b *(e *k *p e *l *o g *i *p +g *l *m +h *i *o h *k *m )+c *(e *j *p e *l *n f *i *p +f *l *m +h *i *n h *j *m )d *(e *j *o e *k *n f *i *o +f *k *m +g *i *n g *j *m );
a b c d
@ -377,11 +416,11 @@ public record Matrix4f(
m n o p
*/
}
@CheckReturnValue
@Deprecated
public float[] getTable() {
float[] mat = new float[16];
final float[] mat = new float[16];
mat[0] = this.a1;
mat[1] = this.b1;
mat[2] = this.c1;
@ -400,10 +439,10 @@ public record Matrix4f(
mat[15] = this.d4;
return mat;
}
@CheckReturnValue
public float[] asArray() {
float[] mat = new float[16];
final float[] mat = new float[16];
mat[0] = this.a1;
mat[1] = this.b1;
mat[2] = this.c1;
@ -422,10 +461,10 @@ public record Matrix4f(
mat[15] = this.d4;
return mat;
}
@CheckReturnValue
public float[] asArrayTransposed() {
float[] mat = new float[16];
final float[] mat = new float[16];
mat[0] = this.a1;
mat[1] = this.a2;
mat[2] = this.a3;
@ -444,7 +483,7 @@ public record Matrix4f(
mat[15] = this.d4;
return mat;
}
/**
* Inverts the matrix.
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
@ -457,30 +496,30 @@ public record Matrix4f(
// The matrix is not invertible! Singular case!
return this;
}
float a1 = coFactorRaw0Col0() / det;
float b1 = -coFactorRaw0Col1() / det;
float c1 = coFactorRaw0Col2() / det;
float d1 = -coFactorRaw0Col3() / det;
float a2 = -coFactorRaw1Col0() / det;
float b2 = coFactorRaw1Col1() / det;
float c2 = -coFactorRaw1Col2() / det;
float d2 = coFactorRaw1Col3() / det;
float a3 = coFactorRaw2Col0() / det;
float b3 = -coFactorRaw2Col1() / det;
float c3 = coFactorRaw2Col2() / det;
float d3 = -coFactorRaw2Col3() / det;
float a4 = -coFactorRaw3Col0() / det;
float b4 = coFactorRaw3Col1() / det;
float c4 = -coFactorRaw3Col2() / det;
float d4 = coFactorRaw3Col3() / det;
final float a1 = coFactorRaw0Col0() / det;
final float b1 = -coFactorRaw0Col1() / det;
final float c1 = coFactorRaw0Col2() / det;
final float d1 = -coFactorRaw0Col3() / det;
final float a2 = -coFactorRaw1Col0() / det;
final float b2 = coFactorRaw1Col1() / det;
final float c2 = -coFactorRaw1Col2() / det;
final float d2 = coFactorRaw1Col3() / det;
final float a3 = coFactorRaw2Col0() / det;
final float b3 = -coFactorRaw2Col1() / det;
final float c3 = coFactorRaw2Col2() / det;
final float d3 = -coFactorRaw2Col3() / det;
final float a4 = -coFactorRaw3Col0() / det;
final float b4 = coFactorRaw3Col1() / det;
final float c4 = -coFactorRaw3Col2() / det;
final float d4 = coFactorRaw3Col3() / det;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, b1, c1, a4, a2, b2, c2, b4, a3, b3, c3, c4, d1, d2, d3, d4);
}
/**
* Operator*= Multiplication an other matrix with this one
* @param obj Reference on the external object
@ -492,45 +531,45 @@ public record Matrix4f(
float b1 = this.b1 * obj.a1 + this.b2 * obj.b1 + this.b3 * obj.c1 + this.b3 * obj.d1;
float c1 = this.c1 * obj.a1 + this.c2 * obj.b1 + this.c3 * obj.c1 + this.c3 * obj.d1;
float d1 = this.d1 * obj.a1 + this.d2 * obj.b1 + this.d3 * obj.c1 + this.d3 * obj.d1;
float a2 = this.a1 * obj.a2 + this.a2 * obj.b2 + this.a3 * obj.c2 + this.a3 * obj.d2;
float b2 = this.b1 * obj.a2 + this.b2 * obj.b2 + this.b3 * obj.c2 + this.b3 * obj.d2;
float c2 = this.c1 * obj.a2 + this.c2 * obj.b2 + this.c3 * obj.c2 + this.c3 * obj.d2;
float d2 = this.d1 * obj.a2 + this.d2 * obj.b2 + this.d3 * obj.c2 + this.d3 * obj.d2;
float a3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3 + this.a3 * obj.d3;
float b3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * obj.c3 + this.b3 * obj.d3;
float c3 = this.c1 * obj.a3 + this.c2 * obj.b3 + this.c3 * obj.c3 + this.c3 * obj.d3;
float d3 = this.d1 * obj.a3 + this.d2 * obj.b3 + this.d3 * obj.c3 + this.d3 * obj.d3;
float a4 = this.a1 * obj.a4 + this.a2 * obj.b4 + this.a3 * obj.c4 + this.a3 * obj.d4;
float b4 = this.b1 * obj.a4 + this.b2 * obj.b4 + this.b3 * obj.c4 + this.b3 * obj.d4;
float c4 = this.c1 * obj.a4 + this.c2 * obj.b4 + this.c3 * obj.c4 + this.c3 * obj.d4;
float d4 = this.d1 * obj.a4 + this.d2 * obj.b4 + this.d3 * obj.c4 + this.d3 * obj.d4;
*/
float a1 = this.a1 * obj.a1 + this.b1 * obj.a2 + this.c1 * obj.a3 + this.d1 * obj.a4;
float b1 = this.a1 * obj.b1 + this.b1 * obj.b2 + this.c1 * obj.b3 + this.d1 * obj.b4;
float c1 = this.a1 * obj.c1 + this.b1 * obj.c2 + this.c1 * obj.c3 + this.d1 * obj.c4;
float d1 = this.a1 * obj.d1 + this.b1 * obj.d2 + this.c1 * obj.d3 + this.d1 * obj.d4;
float a2 = this.a2 * obj.a1 + this.b2 * obj.a2 + this.c2 * obj.a3 + this.d2 * obj.a4;
float b2 = this.a2 * obj.b1 + this.b2 * obj.b2 + this.c2 * obj.b3 + this.d2 * obj.b4;
float c2 = this.a2 * obj.c1 + this.b2 * obj.c2 + this.c2 * obj.c3 + this.d2 * obj.c4;
float d2 = this.a2 * obj.d1 + this.b2 * obj.d2 + this.c2 * obj.d3 + this.d2 * obj.d4;
float a3 = this.a3 * obj.a1 + this.b3 * obj.a2 + this.c3 * obj.a3 + this.d3 * obj.a4;
float b3 = this.a3 * obj.b1 + this.b3 * obj.b2 + this.c3 * obj.b3 + this.d3 * obj.b4;
float c3 = this.a3 * obj.c1 + this.b3 * obj.c2 + this.c3 * obj.c3 + this.d3 * obj.c4;
float d3 = this.a3 * obj.d1 + this.b3 * obj.d2 + this.c3 * obj.d3 + this.d3 * obj.d4;
float a4 = this.a4 * obj.a1 + this.b4 * obj.a2 + this.c4 * obj.a3 + this.d4 * obj.a4;
float b4 = this.a4 * obj.b1 + this.b4 * obj.b2 + this.c4 * obj.b3 + this.d4 * obj.b4;
float c4 = this.a4 * obj.c1 + this.b4 * obj.c2 + this.c4 * obj.c3 + this.d4 * obj.c4;
float d4 = this.a4 * obj.d1 + this.b4 * obj.d2 + this.c4 * obj.d3 + this.d4 * obj.d4;
final float a1 = this.a1 * obj.a1 + this.b1 * obj.a2 + this.c1 * obj.a3 + this.d1 * obj.a4;
final float b1 = this.a1 * obj.b1 + this.b1 * obj.b2 + this.c1 * obj.b3 + this.d1 * obj.b4;
final float c1 = this.a1 * obj.c1 + this.b1 * obj.c2 + this.c1 * obj.c3 + this.d1 * obj.c4;
final float d1 = this.a1 * obj.d1 + this.b1 * obj.d2 + this.c1 * obj.d3 + this.d1 * obj.d4;
final float a2 = this.a2 * obj.a1 + this.b2 * obj.a2 + this.c2 * obj.a3 + this.d2 * obj.a4;
final float b2 = this.a2 * obj.b1 + this.b2 * obj.b2 + this.c2 * obj.b3 + this.d2 * obj.b4;
final float c2 = this.a2 * obj.c1 + this.b2 * obj.c2 + this.c2 * obj.c3 + this.d2 * obj.c4;
final float d2 = this.a2 * obj.d1 + this.b2 * obj.d2 + this.c2 * obj.d3 + this.d2 * obj.d4;
final float a3 = this.a3 * obj.a1 + this.b3 * obj.a2 + this.c3 * obj.a3 + this.d3 * obj.a4;
final float b3 = this.a3 * obj.b1 + this.b3 * obj.b2 + this.c3 * obj.b3 + this.d3 * obj.b4;
final float c3 = this.a3 * obj.c1 + this.b3 * obj.c2 + this.c3 * obj.c3 + this.d3 * obj.c4;
final float d3 = this.a3 * obj.d1 + this.b3 * obj.d2 + this.c3 * obj.d3 + this.d3 * obj.d4;
final float a4 = this.a4 * obj.a1 + this.b4 * obj.a2 + this.c4 * obj.a3 + this.d4 * obj.a4;
final float b4 = this.a4 * obj.b1 + this.b4 * obj.b2 + this.c4 * obj.b3 + this.d4 * obj.b4;
final float c4 = this.a4 * obj.c1 + this.b4 * obj.c2 + this.c4 * obj.c3 + this.d4 * obj.c4;
final float d4 = this.a4 * obj.d1 + this.b4 * obj.d2 + this.c4 * obj.d3 + this.d4 * obj.d4;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
}
/**
* Operator* apply matrix on a vector
* @param point Point value to apply the matrix
@ -542,7 +581,7 @@ public record Matrix4f(
this.a2 * point.x() + this.b2 * point.y() + this.c2 * point.z() + this.d2, // Y
this.a3 * point.x() + this.b3 * point.y() + this.c3 * point.z() + this.d3); // Z
}
/**
* Operator* apply matrix on a vector
* @param point Point value to apply the matrix
@ -555,7 +594,7 @@ public record Matrix4f(
this.a3 * point.x() + this.b3 * point.y() + this.c3 * point.z() + this.d3 * point.w(), // Z
this.a4 * point.x() + this.b4 * point.y() + this.c4 * point.z() + this.d4 * point.w()); // W
}
/**
* Makes a rotation matrix about an arbitrary axis.
* @param vect vector to apply the angle.
@ -566,7 +605,7 @@ public record Matrix4f(
final Matrix4f tmpMat = createMatrixRotate(vect, angleRad);
return this.multiply(tmpMat);
}
/**
* Scale the current Matrix in all direction with 1 value.
* @param scale Scale XYZ value to apply.
@ -575,7 +614,7 @@ public record Matrix4f(
public Matrix4f scale(final float scale) {
return scale(scale, scale, scale);
}
/**
* Scale the current Matrix.
* @param sx Scale X value to apply.
@ -584,18 +623,19 @@ public record Matrix4f(
*/
@CheckReturnValue
public Matrix4f scale(final float sx, final float sy, final float sz) {
float a1 = this.a1 * sx;
float b1 = this.b1 * sy;
float c1 = this.c1 * sz;
float a2 = this.a2 * sx;
float b2 = this.b2 * sy;
float c2 = this.c2 * sz;
float a3 = this.a3 * sx;
float b3 = this.b3 * sy;
float c3 = this.c3 * sz;
return new Matrix4f(a1, b1, c1, this.d1, a2, b2, c2, this.d2, a3, b3, c3, this.d3, this.a4, this.b4, this.c4, this.d4);
final float a1 = this.a1 * sx;
final float b1 = this.b1 * sy;
final float c1 = this.c1 * sz;
final float a2 = this.a2 * sx;
final float b2 = this.b2 * sy;
final float c2 = this.c2 * sz;
final float a3 = this.a3 * sx;
final float b3 = this.b3 * sy;
final float c3 = this.c3 * sz;
return new Matrix4f(a1, b1, c1, this.d1, a2, b2, c2, this.d2, a3, b3, c3, this.d3, this.a4, this.b4, this.c4,
this.d4);
}
/**
* Scale the current Matrix.
* @param vect Scale vector to apply.
@ -604,12 +644,12 @@ public record Matrix4f(
public Matrix4f scale(final Vector3f vect) {
return scale(vect.x(), vect.y(), vect.z());
}
/**
* configure identity of the matrix
*/
public static final Matrix4f IDENTITY = new Matrix4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
/**
* Makes a translation of the matrix
* @param vect Translation to apply.
@ -619,13 +659,14 @@ public record Matrix4f(
final Matrix4f tmpMat = createMatrixTranslate(vect);
return this.multiply(tmpMat);
}
/**
* Transpose the current matix (usefull for OpenGL display)
*/
@CheckReturnValue
public Matrix4f transpose() {
return new Matrix4f(this.a1, this.a2, this.a3, this.a4, this.b1, this.b2, this.b3, this.b4, this.c1, this.c2, this.c3, this.c4, this.d1, this.d2, this.d3, this.d4);
return new Matrix4f(this.a1, this.a2, this.a3, this.a4, this.b1, this.b2, this.b3, this.b4, this.c1, this.c2,
this.c3, this.c4, this.d1, this.d2, this.d3, this.d4);
}
}

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Quaternion(
float x,
float y,
@ -10,11 +9,11 @@ public record Quaternion(
float w) {
// a * diff = b
public static Quaternion diff(final Quaternion a, final Quaternion b) {
// Log.info("diff " + a + " " + b);
// LOGGER.info("diff " + a + " " + b);
final Quaternion inv = a.inverse();
return inv.multiply(b);
}
/* void checkValues() { if ( isinf(this.x) == true || isnan(this.x) == true || isinf(this.y) == true || isnan(this.y) == true || isinf(this.z) == true || isnan(this.z) == true || isinf(this.w) ==
* true || isnan(this.w) == true) { TKCRITICAL(" set transform: (" << this.x << "," << this.y << "," << this.z << "," << this.w << ")"); } } */
/**
@ -29,7 +28,7 @@ public record Quaternion(
this.z = z;
this.w = w;
}
/**
* Constructor with the component w and a vector 3D.
* @param www W value
@ -38,7 +37,7 @@ public record Quaternion(
public Quaternion(final float www, final Vector3f vec) {
this(vec.x(), vec.y(), vec.z(), www);
}
/** Create a unit quaternion from a rotation matrix
* @param matrix generic matrix */
public static Quaternion createFromMatrix(final Matrix3f matrix) {
@ -86,13 +85,13 @@ public record Quaternion(
}
return new Quaternion(x, y, z, w);
}
/** Set the absolute values of each element */
@CheckReturnValue
public Quaternion absolute() {
return new Quaternion(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z), Math.abs(this.w));
}
/** Add a vector to this one.
* @param obj The vector to add to this one
* @return New vector containing the value */
@ -100,13 +99,13 @@ public record Quaternion(
public Quaternion add(final Quaternion obj) {
return new Quaternion(this.x + obj.x, this.y + obj.y, this.z + obj.z, this.w + obj.w);
}
/** Conjugate the quaternion */
@CheckReturnValue
public Quaternion conjugate() {
return new Quaternion(this.x * -1.0f, this.y * -1.0f, this.z * -1.0f, this.w);
}
/** Inversely scale the quaternion
* @param val Scale factor to divide by.
* @return New quaternion containing the value */
@ -116,7 +115,7 @@ public record Quaternion(
}
return this;
}
/** Return the dot product
* @param obj The other quaternion in the dot product
* @return Dot result value */
@ -124,7 +123,7 @@ public record Quaternion(
public float dot(final Quaternion obj) {
return this.x * obj.x + this.y * obj.y + this.z * obj.z + this.w * obj.w;
}
/** Compute the rotation angle (in radians) and the rotation axis
* @param angle Angle of the quaternion
* @return Axis of the quaternion */
@ -132,10 +131,10 @@ public record Quaternion(
public Vector3f getAngleAxis(float angle) {
final Quaternion quaternion = getUnit();
angle = (float) Math.acos(quaternion.w) * 2.0f;
Vector3f rotationAxis = quaternion.getVectorV();
final Vector3f rotationAxis = quaternion.getVectorV();
return rotationAxis.normalize();
}
/** Get the orientation matrix corresponding to this quaternion
* @return the 3x3 transformation matrix */
@CheckReturnValue
@ -157,9 +156,10 @@ public record Quaternion(
final float yys = this.y * ys;
final float yzs = this.y * zs;
final float zzs = this.z * zs;
return new Matrix3f(1.0f - yys - zzs, xys - wzs, xzs + wys, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, xzs - wys, yzs + wxs, 1.0f - xxs - yys);
return new Matrix3f(1.0f - yys - zzs, xys - wzs, xzs + wys, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, xzs - wys,
yzs + wxs, 1.0f - xxs - yys);
}
@CheckReturnValue
public Matrix4f getMatrix4() {
final float nQ = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
@ -179,29 +179,31 @@ public record Quaternion(
final float yys = this.y * ys;
final float yzs = this.y * zs;
final float zzs = this.z * zs;
return new Matrix4f(1.0f - yys - zzs, xys - wzs, xzs + wys, 0, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, 0, xzs - wys, yzs + wxs, 1.0f - xxs - yys, 0, 0, 0, 0, 1);
return new Matrix4f(1.0f - yys - zzs, xys - wzs, xzs + wys, 0, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, 0,
xzs - wys, yzs + wxs, 1.0f - xxs - yys, 0, 0, 0, 0, 1);
}
/** Return the unit quaternion
* @return Quaternion unitarised */
@CheckReturnValue
public Quaternion getUnit() {
return normalize();
}
/** get x, y, z in a Vector3f */
@CheckReturnValue
public Vector3f getVectorV() {
return new Vector3f(this.x, this.y, this.z);
}
/** Inverse the quaternion */
@CheckReturnValue
public Quaternion inverse() {
final float invLengthSquare = 1.0f / length2();
return new Quaternion(this.x * -invLengthSquare, this.y * -invLengthSquare, this.z * -invLengthSquare, this.w * invLengthSquare);
return new Quaternion(this.x * -invLengthSquare, this.y * -invLengthSquare, this.z * -invLengthSquare,
this.w * invLengthSquare);
}
/** In-Equality compare operator with an other object.
* @param obj Reference on the comparing object
* @return true The Objects are NOT identical
@ -210,7 +212,7 @@ public record Quaternion(
public boolean isDifferent(final Quaternion obj) {
return ((this.w != obj.w) || (this.z != obj.z) || (this.y != obj.y) || (this.x != obj.x));
}
/** Equality compare operator with an other object.
* @param obj Reference on the comparing object
* @return true The Objects are identical
@ -219,7 +221,7 @@ public record Quaternion(
public boolean isEqual(final Quaternion obj) {
return ((this.w == obj.w) && (this.z == obj.z) && (this.y == obj.y) && (this.x == obj.x));
}
/** Check if the quaternion is equal to (0,0,0,0)
* @return true The value is equal to (0,0,0,0)
* @return false The value is NOT equal to (0,0,0,0) */
@ -227,21 +229,21 @@ public record Quaternion(
public boolean isZero() {
return this.x == 0 && this.y == 0 && this.z == 0 && this.w == 0;
}
/** Return the length of the quaternion
* @return Length value */
@CheckReturnValue
public float length() {
return (float) Math.sqrt(length2());
}
/** Return the squared length of the quaternion.
* @return Squared length value. */
@CheckReturnValue
public float length2() {
return dot(this);
}
/** Subtract a vector from this one
* @param obj The vector to subtract
* @return New quaternion containing the value */
@ -249,7 +251,7 @@ public record Quaternion(
public Quaternion less(final Quaternion obj) {
return new Quaternion(this.x - obj.x, this.y - obj.y, this.z - obj.z, this.w - obj.w);
}
@CheckReturnValue
public Vector3f multiply(final float xxx, final float yyy, final float zzz) {
final Vector3f point = new Vector3f(xxx, yyy, zzz);
@ -260,7 +262,7 @@ public record Quaternion(
uuv = uuv.multiply(2.0f);
return uv.add(point).add(uuv);
}
/** Multiply this quaternion by the other.
* @param obj The other quaternion
* @return Local reference of the quaternion */
@ -268,13 +270,13 @@ public record Quaternion(
public Quaternion multiply(final Quaternion obj) {
final Vector3f base = getVectorV();
final Vector3f crossValue = base.cross(obj.getVectorV());
float x = this.w * obj.x + obj.w * this.x + crossValue.x();
float y = this.w * obj.y + obj.w * this.y + crossValue.y();
float z = this.w * obj.z + obj.w * this.z + crossValue.z();
float w = this.w * obj.w - base.dot(obj.getVectorV());
final float x = this.w * obj.x + obj.w * this.x + crossValue.x();
final float y = this.w * obj.y + obj.w * this.y + crossValue.y();
final float z = this.w * obj.z + obj.w * this.z + crossValue.z();
final float w = this.w * obj.w - base.dot(obj.getVectorV());
return (new Quaternion(x, y, z, w)).safeNormalize();
}
/** Operator* with a vector. This methods rotates a point given the rotation of a quaternion
* @param point Point to move
* @return Point with the updated position */
@ -287,7 +289,7 @@ public record Quaternion(
uuv = uuv.multiply(2.0f);
return uv.add(point).add(uuv);
}
/** Scale the quaternion
* @param val Scale factor
* @return New quaternion containing the value */
@ -295,7 +297,7 @@ public record Quaternion(
public Quaternion multiply(final float val) {
return new Quaternion(this.x * val, this.y * val, this.z * val, this.w * val);
}
/** Normalize this quaternion x^2 + y^2 + z^2 + w^2 = 1
* @return Local reference of the quaternion normalized */
@CheckReturnValue
@ -303,7 +305,7 @@ public record Quaternion(
final float invLength = 1.0f / length();
return new Quaternion(this.x * invLength, this.y * invLength, this.z * invLength, this.w * invLength);
}
/** Normalize this quaternion x^2 + y^2 + z^2 + w^2 = 1
* @return Local reference of the quaternion normalized */
@CheckReturnValue
@ -314,7 +316,7 @@ public record Quaternion(
}
return normalize();
}
/** Configure the quaternion with euler angles.
* @param angles Eular angle of the quaternion. */
@CheckReturnValue
@ -332,30 +334,32 @@ public record Quaternion(
final float sinYcosZ = sinY * cosZ;
final float cosYsinZ = cosY * sinZ;
final float sinYsinZ = sinY * sinZ;
float x = sinX * cosYcosZ - cosX * sinYsinZ;
float y = cosX * sinYcosZ + sinX * cosYsinZ;
float z = cosX * cosYsinZ - sinX * sinYcosZ;
float w = cosX * cosYcosZ + sinX * sinYsinZ;
final float x = sinX * cosYcosZ - cosX * sinYsinZ;
final float y = cosX * sinYcosZ + sinX * cosYsinZ;
final float z = cosX * cosYsinZ - sinX * sinYcosZ;
final float w = cosX * cosYcosZ + sinX * sinYsinZ;
return (new Quaternion(x, y, z, w)).normalize();
}
/** Set identity value at the quaternion */
public static final Quaternion IDENTITY = new Quaternion(0, 0, 0, 1);
/** Set each element to the max of the current values and the values of another Vector
* @param obj The other Vector to compare with */
@CheckReturnValue
public Quaternion max(final Quaternion obj) {
return new Quaternion(Math.max(this.x, obj.x), Math.max(this.y, obj.y), Math.max(this.z, obj.z), Math.max(this.w, obj.w));
return new Quaternion(Math.max(this.x, obj.x), Math.max(this.y, obj.y), Math.max(this.z, obj.z),
Math.max(this.w, obj.w));
}
/** Set each element to the min of the current values and the values of another Vector
* @param obj The other Vector to compare with */
@CheckReturnValue
public Quaternion min(final Quaternion obj) {
return new Quaternion(Math.min(this.x, obj.x), Math.min(this.y, obj.y), Math.min(this.z, obj.z), Math.min(this.w, obj.w));
return new Quaternion(Math.min(this.x, obj.x), Math.min(this.y, obj.y), Math.min(this.z, obj.z),
Math.min(this.w, obj.w));
}
// Compute the rotation angle (in radians) and the rotation axis
// This method is used to get the rotation angle (in radian) and the unit
// rotation axis of an orientation quaternion.
@ -379,9 +383,9 @@ public record Quaternion(
return axis.set(rotationAxis);
}
*/
public static final Quaternion ZERO = new Quaternion(0, 0, 0, 0);
/** Compute the spherical linear interpolation between two quaternions.
* @param obj1 First quaternion
* @param obj2 Second quaternion
@ -404,9 +408,10 @@ public record Quaternion(
final float coeff2 = (float) Math.sin(ttt * theta) / sineTheta * invert;
return this.multiply(coeff1).add(obj2.multiply(coeff2));
}
@Override
public String toString() {
return "Quaternion(" + FMath.floatToString(this.x) + "," + FMath.floatToString(this.y) + "," + FMath.floatToString(this.z) + "," + FMath.floatToString(this.w) + ")";
return "Quaternion(" + FMath.floatToString(this.x) + "," + FMath.floatToString(this.y) + ","
+ FMath.floatToString(this.z) + "," + FMath.floatToString(this.w) + ")";
}
}

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Transform3D(
// Position
Vector3f position,
@ -12,69 +11,72 @@ public record Transform3D(
* Get the identity of the transformation
*/
public static final Transform3D IDENTITY = new Transform3D(Vector3f.ZERO, Quaternion.IDENTITY);
public Transform3D(final Vector3f position) {
this(position, Quaternion.IDENTITY);
}
public Transform3D(final Vector3f position, final Matrix3f orientation) {
this(position, Quaternion.createFromMatrix(orientation));
}
public Transform3D(final Vector3f position, final Quaternion orientation) {
this.position = position;
this.orientation = orientation;
}
@CheckReturnValue
public Transform3D rotate(final Quaternion rotation) {
return new Transform3D(this.position, this.orientation.multiply(rotation));
}
@CheckReturnValue
public Transform3D withOrientation(final Quaternion orientation) {
return new Transform3D(this.position, orientation);
}
@CheckReturnValue
public Transform3D withPosition(final Vector3f position) {
return new Transform3D(position, this.orientation);
}
/// Get the OpenGL matrix of the transform
@CheckReturnValue
public Matrix4f getOpenGLMatrix() {
final Matrix3f tmpMatrix = this.orientation.getMatrix();
return new Matrix4f(tmpMatrix.a1(), tmpMatrix.a2(), tmpMatrix.a3(), this.position.x(), tmpMatrix.b1(), tmpMatrix.b2(), tmpMatrix.b3(), this.position.y(), tmpMatrix.c1(), tmpMatrix.c2(),
tmpMatrix.c3(), this.position.z(), 0.0f, 0.0f, 0.0f, 1.0f);
return new Matrix4f(tmpMatrix.a1(), tmpMatrix.a2(), tmpMatrix.a3(), this.position.x(), tmpMatrix.b1(),
tmpMatrix.b2(), tmpMatrix.b3(), this.position.y(), tmpMatrix.c1(), tmpMatrix.c2(), tmpMatrix.c3(),
this.position.z(), 0.0f, 0.0f, 0.0f, 1.0f);
}
/// Get the OpenGL matrix of the transform
@CheckReturnValue
public Matrix4f getOpenGLMatrixTransposed() {
final Matrix3f tmpMatrix = this.orientation.getMatrix();
return new Matrix4f(tmpMatrix.a1(), tmpMatrix.b1(), tmpMatrix.c1(), 0.0f, tmpMatrix.a2(), tmpMatrix.b2(), tmpMatrix.c2(), 0.0f, tmpMatrix.a3(), tmpMatrix.b3(), tmpMatrix.c3(), 0.0f,
this.position.x(), this.position.y(), this.position.z(), 1.0f);
return new Matrix4f(tmpMatrix.a1(), tmpMatrix.b1(), tmpMatrix.c1(), 0.0f, tmpMatrix.a2(), tmpMatrix.b2(),
tmpMatrix.c2(), 0.0f, tmpMatrix.a3(), tmpMatrix.b3(), tmpMatrix.c3(), 0.0f, this.position.x(),
this.position.y(), this.position.z(), 1.0f);
}
@CheckReturnValue
public Quaternion getOrientation() {
return this.orientation;
}
@CheckReturnValue
public Vector3f getPosition() {
return this.position;
}
/// Return an interpolated transform
@CheckReturnValue
public Transform3D interpolateTransforms(final Transform3D newOne, final float interpolationFactor) {
final Vector3f interPosition = this.position.multiply(1.0f - interpolationFactor).add(newOne.position.multiply(interpolationFactor));
final Vector3f interPosition = this.position.multiply(1.0f - interpolationFactor)
.add(newOne.position.multiply(interpolationFactor));
final Quaternion interOrientation = this.orientation.slerp(newOne.orientation, interpolationFactor);
return new Transform3D(interPosition, interOrientation);
}
/// Return the inverse of the transform
@CheckReturnValue
public Transform3D inverseNew() {
@ -82,25 +84,25 @@ public record Transform3D(
final Matrix3f invMatrix = invQuaternion.getMatrix();
return new Transform3D(invMatrix.multiply(this.position.multiply(-1)), invQuaternion);
}
/// Return true if the two transforms are different
@CheckReturnValue
public boolean isDifferent(final Transform3D transform2) {
return this.position.isDifferent(transform2.position) || this.orientation.isDifferent(transform2.orientation);
}
/// Return true if the two transforms are equal
@CheckReturnValue
public boolean isEqual(final Transform3D transform2) {
return this.position.isEqual(transform2.position) && this.orientation.isEqual(transform2.orientation);
}
/// Return the transformed vector
@CheckReturnValue
public Vector3f multiply(final Vector3f vector) {
return this.orientation.getMatrix().multiply(vector).add(this.position);
}
/// Operator of multiplication of a transform with another one
/*
@CheckReturnValue
@ -112,18 +114,20 @@ public record Transform3D(
/// Operator of multiplication of a transform with another one
@CheckReturnValue
public Transform3D multiply(final Transform3D transform2) {
return new Transform3D(this.orientation.getMatrix().multiply(transform2.position).add(this.position), this.orientation.multiply(transform2.orientation));
return new Transform3D(this.orientation.getMatrix().multiply(transform2.position).add(this.position),
this.orientation.multiply(transform2.orientation));
}
/// Set the transform from an OpenGL transform matrix
@CheckReturnValue
public Transform3D createFromOpenGL(final float[] matrix) {
final Matrix3f tmpMatrix = new Matrix3f(matrix[0], matrix[4], matrix[8], matrix[1], matrix[5], matrix[9], matrix[2], matrix[6], matrix[10]);
Quaternion orientation = Quaternion.createFromMatrix(tmpMatrix);
Vector3f position = new Vector3f(matrix[12], matrix[13], matrix[14]);
final Matrix3f tmpMatrix = new Matrix3f(matrix[0], matrix[4], matrix[8], matrix[1], matrix[5], matrix[9],
matrix[2], matrix[6], matrix[10]);
final Quaternion orientation = Quaternion.createFromMatrix(tmpMatrix);
final Vector3f position = new Vector3f(matrix[12], matrix[13], matrix[14]);
return new Transform3D(position, orientation);
}
@Override
public String toString() {
return "Transform3D(" + this.position + " & " + this.orientation + ")";

View File

@ -1,13 +1,15 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Vector2b(
boolean x,
boolean y) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector2b.class);
public static Vector2b valueOf(String value) {
boolean val1 = false;
boolean val2 = false;
@ -20,7 +22,7 @@ public record Vector2b(
}
final String[] values = value.split(",| ");
if (values.length > 2) {
Log.error("Can not parse Vector2f with more than 2 values: '" + value + "'");
LOGGER.error("Can not parse Vector2f with more than 2 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...
@ -33,19 +35,19 @@ public record Vector2b(
}
return new Vector2b(val1, val2);
}
/*
* **************************************************** Constructor
*****************************************************/
public Vector2b() {
this(false, false);
}
public Vector2b(final boolean x, final boolean y) {
this.x = x;
this.y = y;
}
/**
* In-Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -56,7 +58,7 @@ public record Vector2b(
public boolean isDifferent(final Vector2b obj) {
return (obj.x != this.x || obj.y != this.y);
}
/**
* Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -67,24 +69,24 @@ public record Vector2b(
public boolean isEqual(final Vector2b obj) {
return (obj.x == this.x && obj.y == this.y);
}
public static final Vector2b FALSE = new Vector2b(false, false);
public static final Vector2b TRUE = new Vector2b(true, true);
public static final Vector2b FALSE_FALSE = FALSE;
public static final Vector2b TRUE_TRUE = TRUE;
public static final Vector2b TRUE_FALSE = new Vector2b(true, false);
public static final Vector2b FALSE_TRUE = new Vector2b(false, true);
@Override
public String toString() {
return "(" + this.x + "," + this.y + ")";
}
@CheckReturnValue
public Vector2b withX(final boolean xxx) {
return new Vector2b(xxx, this.y);
}
@CheckReturnValue
public Vector2b withY(final boolean yyy) {
return new Vector2b(this.x, yyy);

View File

@ -1,12 +1,16 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
public record Vector2f(
float x,
float y) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector2f.class);
public static Vector2f valueOf(String value) {
float val1 = 0;
float val2 = 0;
@ -19,7 +23,7 @@ public record Vector2f(
}
final String[] values = value.split(",| ");
if (values.length > 2) {
Log.error("Can not parse Vector2f with more than 2 values: '" + value + "'");
LOGGER.error("Can not parse Vector2f with more than 2 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...

View File

@ -1,14 +1,15 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Vector2i(
int x,
int y) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector2i.class);
public static Vector2i valueOf(String value) throws NumberFormatException {
int val1 = 0;
int val2 = 0;
@ -21,7 +22,7 @@ public record Vector2i(
}
final String[] values = value.split(",| ");
if (values.length > 2) {
Log.error("Can not parse Vector2i with more than 2 values: '" + value + "'");
LOGGER.error("Can not parse Vector2i with more than 2 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...
@ -34,27 +35,27 @@ public record Vector2i(
}
return new Vector2i(val1, val2);
}
/*
* **************************************************** Constructor
*****************************************************/
public Vector2i() {
this(0, 0);
}
public Vector2i(final int x, final int y) {
this.x = x;
this.y = y;
}
public static Vector2i max(final Vector2i obj1, final Vector2i obj2) {
return new Vector2i(Math.max(obj1.x, obj2.x), Math.max(obj1.y, obj2.y));
}
public static Vector2i min(final Vector2i obj1, final Vector2i obj2) {
return new Vector2i(Math.min(obj1.x, obj2.x), Math.min(obj1.y, obj2.y));
}
/**
* Return a vector will the absolute values of each element
* @return New vector containing the value
@ -63,22 +64,22 @@ public record Vector2i(
public Vector2i absolute() {
return new Vector2i(Math.abs(this.x), Math.abs(this.y));
}
@CheckReturnValue
public Vector2i add(final int val) {
return new Vector2i(this.x + val, this.y + val);
}
@CheckReturnValue
public Vector2i add(final Vector2i obj) {
return new Vector2i(this.x + obj.x, this.y + obj.y);
}
@CheckReturnValue
public Vector2i add(final int xxx, final int yyy) {
return new Vector2i(this.x + xxx, this.y + yyy);
}
/**
* Return the axis with the largest ABSOLUTE value
* @return values 0,1 for x or y
@ -87,7 +88,7 @@ public record Vector2i(
public int closestAxis() {
return absolute().maxAxis();
}
/**
* Return the cross product / determinant
* @param obj The other vector in the cross product
@ -97,7 +98,7 @@ public record Vector2i(
public int cross(final Vector2i obj) {
return this.x * obj.y - this.y * obj.x;
}
/**
* Decrementation of this vector (-1 of 2 elements)
*/
@ -105,17 +106,17 @@ public record Vector2i(
public Vector2i decrement() {
return new Vector2i(this.x - 1, this.y - 1);
}
@CheckReturnValue
public Vector2i devide(final int val) {
return new Vector2i(this.x / val, this.y / val);
}
@CheckReturnValue
public Vector2i devide(final Vector2i obj) {
return new Vector2i(this.x / obj.x, this.y / obj.y);
}
/**
* Return the distance between the ends of this and another vector This
* is symantically treating the vector like a point
@ -126,7 +127,7 @@ public record Vector2i(
public int distance(final Vector2i obj) {
return (int) Math.sqrt(distance2(obj));
}
/**
* Return the distance squared between the ends of this and another
* vector This is symantically treating the vector like a point
@ -139,7 +140,7 @@ public record Vector2i(
final int deltaY = obj.y - this.y;
return deltaX * deltaX + deltaY * deltaY;
}
/**
* Return the dot product
* @param obj The other vector in the dot product
@ -149,7 +150,7 @@ public record Vector2i(
public int dot(final Vector2i obj) {
return this.x * obj.x + this.y * obj.y;
}
/**
* Return the axis with the smallest ABSOLUTE value
* @return values 0,1 for x, or z
@ -158,7 +159,7 @@ public record Vector2i(
public int furthestAxis() {
return absolute().minAxis();
}
/**
* Incrementation of this vector (+1 of 2 elements)
*/
@ -166,7 +167,7 @@ public record Vector2i(
public Vector2i increment() {
return new Vector2i(this.x + 1, this.y + 1);
}
/**
* In-Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -177,7 +178,7 @@ public record Vector2i(
public boolean isDifferent(final Vector2i obj) {
return (obj.x != this.x || obj.y != this.y);
}
/**
* Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -188,27 +189,27 @@ public record Vector2i(
public boolean isEqual(final Vector2i obj) {
return (obj.x == this.x && obj.y == this.y);
}
@CheckReturnValue
public boolean isGreater(final Vector2i obj) {
return (this.x > obj.x && this.y > obj.y);
}
@CheckReturnValue
public boolean isGreaterOrEqual(final Vector2i obj) {
return (this.x >= obj.x && this.y >= obj.y);
}
@CheckReturnValue
public boolean isLower(final Vector2i obj) {
return (this.x < obj.x && this.y < obj.y);
}
@CheckReturnValue
public boolean isLowerOrEqual(final Vector2i obj) {
return (this.x <= obj.x && this.y <= obj.y);
}
/**
* Check if the vector is equal to (0,0)
* @return true The value is equal to (0,0)
@ -218,7 +219,7 @@ public record Vector2i(
public boolean isZero() {
return this.x == 0 && this.y == 0;
}
/**
* Get the length of the vector
* @return Length value
@ -227,7 +228,7 @@ public record Vector2i(
public int length() {
return (int) Math.sqrt(length2());
}
/**
* Get the length of the vector squared
* @return Squared length value.
@ -236,22 +237,22 @@ public record Vector2i(
public int length2() {
return dot(this);
}
@CheckReturnValue
public Vector2i less(final int val) {
return new Vector2i(this.x - val, this.y - val);
}
@CheckReturnValue
public Vector2i less(final int xxx, final int yyy) {
return new Vector2i(this.x - xxx, this.y - yyy);
}
@CheckReturnValue
public Vector2i less(final Vector2i obj) {
return new Vector2i(this.x - obj.x, this.y - obj.y);
}
/**
* Return the axis with the largest value
* @return values are 0,1 for x or y
@ -260,7 +261,7 @@ public record Vector2i(
public int maxAxis() {
return this.x < this.y ? 1 : 0;
}
/**
* Return the axis with the smallest value
* @return values are 0,1 for x or y
@ -269,17 +270,17 @@ public record Vector2i(
public int minAxis() {
return this.x < this.y ? 0 : 1;
}
@CheckReturnValue
public Vector2i multiply(final int val) {
return new Vector2i(this.x * val, this.y * val);
}
@CheckReturnValue
public Vector2i multiply(final Vector2i obj) {
return new Vector2i(this.x * obj.x, this.y * obj.y);
}
/**
* Normalize this vector x^2 + y^2 = 1
* @return New vector containing the value
@ -288,7 +289,7 @@ public record Vector2i(
public Vector2i normalize() {
return this.devide(length());
}
/**
* Normalize this vector x^2 + y^2 = 1 (check if not deviding by 0, if it
* is the case ==> return (1,0))
@ -302,17 +303,17 @@ public record Vector2i(
}
return new Vector2i(1, 0);
};
@CheckReturnValue
public Vector2i max(final int xxx, final int yyy) {
return new Vector2i(Math.max(this.x, xxx), Math.max(this.y, yyy));
}
@CheckReturnValue
public Vector2i min(final int xxx, final int yyy) {
return new Vector2i(Math.min(this.x, xxx), Math.min(this.y, yyy));
}
/**
* Set 0 value on all the vector
*/
@ -328,17 +329,17 @@ public record Vector2i(
public static final Vector2i VALUE_256 = new Vector2i(256, 256);
public static final Vector2i VALUE_512 = new Vector2i(512, 512);
public static final Vector2i VALUE_1024 = new Vector2i(1024, 1024);
@Override
public String toString() {
return "Vector2i(" + this.x + "," + this.y + ")";
}
@CheckReturnValue
public Vector2i withX(final int xxx) {
return new Vector2i(xxx, this.y);
}
@CheckReturnValue
public Vector2i withY(final int yyy) {
return new Vector2i(this.x, yyy);

View File

@ -1,14 +1,16 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Vector3b(
boolean x,
boolean y,
boolean z) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector3b.class);
public static Vector3b valueOf(String value) {
boolean val1 = false;
boolean val2 = false;
@ -22,7 +24,7 @@ public record Vector3b(
}
final String[] values = value.split(",| ");
if (values.length > 3) {
Log.error("Can not parse Vector3b with more than 3 values: '" + value + "'");
LOGGER.error("Can not parse Vector3b with more than 3 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...
@ -41,20 +43,20 @@ public record Vector3b(
}
return new Vector3b(val1, val2, val3);
}
/*
* **************************************************** Constructor
*****************************************************/
public Vector3b() {
this(false, false, false);
}
public Vector3b(final boolean x, final boolean y, final boolean z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* In-Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -65,7 +67,7 @@ public record Vector3b(
public boolean isDifferent(final Vector3b obj) {
return (obj.x != this.x || obj.y != this.y || obj.z != this.z);
}
/**
* Equality compare operator with an other object.
* @param obj Reference on the comparing object
@ -76,7 +78,7 @@ public record Vector3b(
public boolean isEqual(final Vector3b obj) {
return (obj.x == this.x && obj.y == this.y && obj.z == this.z);
}
public static final Vector3b FALSE = new Vector3b(false, false, false);
public static final Vector3b TRUE = new Vector3b(true, true, true);
public static final Vector3b FALSE_FALSE_FALSE = FALSE;
@ -84,22 +86,22 @@ public record Vector3b(
public static final Vector3b TRUE_FALSE_FALSE = new Vector3b(true, false, false);
public static final Vector3b FALSE_TRUE_FALSE = new Vector3b(false, true, false);
public static final Vector3b FALSE_FALSE_TRUE = new Vector3b(false, false, true);
@Override
public String toString() {
return "(" + this.x + "," + this.y + ")";
}
@CheckReturnValue
public Vector3b withX(final boolean xxx) {
return new Vector3b(xxx, this.y, this.z);
}
@CheckReturnValue
public Vector3b withY(final boolean yyy) {
return new Vector3b(this.x, yyy, this.z);
}
@CheckReturnValue
public Vector3b withZ(final boolean zzz) {
return new Vector3b(this.x, this.y, zzz);

View File

@ -1,6 +1,9 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@ -8,6 +11,7 @@ public record Vector3f(
float x,
float y,
float z) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector3f.class);
/**
* Get the length square between the 2 vectors
* @param start First vector
@ -36,7 +40,7 @@ public record Vector3f(
}
final String[] values = value.split(",| ");
if (values.length > 3) {
Log.error("Can not parse Vector3f with more than 3 values: '" + value + "'");
LOGGER.error("Can not parse Vector3f with more than 3 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...

View File

@ -1,6 +1,9 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@ -8,6 +11,7 @@ public record Vector3i(
int x,
int y,
int z) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector3i.class);
public static Vector3i valueOf(String value) {
int val1 = 0;
int val2 = 0;
@ -21,7 +25,7 @@ public record Vector3i(
}
final String[] values = value.split(",| ");
if (values.length > 3) {
Log.error("Can not parse Vector3i with more than 3 values: '" + value + "'");
LOGGER.error("Can not parse Vector3i with more than 3 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...

View File

@ -1,7 +1,10 @@
package org.atriasoft.etk.math;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@ -10,6 +13,7 @@ public record Vector4f(
float y,
float z,
float w) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector4f.class);
/**
* Get the length square between the 2 vectors
* @param start First vector
@ -38,7 +42,7 @@ public record Vector4f(
}
final String[] values = value.split(",| ");
if (values.length > 3) {
Log.error("Can not parse Vector4f with more than 3 values: '" + value + "'");
LOGGER.error("Can not parse Vector4f with more than 3 values: '" + value + "'");
}
if (values.length == 1) {
// no coma ...

View File

@ -5,9 +5,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Theme {
final static Logger LOGGER = LoggerFactory.getLogger(Theme.class);
private static Map<String, Path> globalListTheme = new HashMap<>();
private static Map<String, Path> globalListThemeDefault = new HashMap<>();
@ -50,7 +54,7 @@ public class Theme {
* @param folderName The associated folder of the Theme (like "myTheme/folder/folder2/")
*/
public static void setName(final String refName, final Path folderName) {
Log.warning("Change theme : '" + refName + "' : '" + folderName + "'");
LOGGER.warn("Change theme : '" + refName + "' : '" + folderName + "'");
globalListTheme.put(refName, folderName);
updateProvider(refName);
}

View File

@ -3,6 +3,7 @@ package org.atriasoft.etk.util;
import java.util.Arrays;
import java.util.List;
public class ArraysTools {
public static <T> void fill(final T[] buffer, final T value) {
if (buffer == null) {

View File

@ -5,6 +5,7 @@
*/
package org.atriasoft.etk.util;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved

View File

@ -1,59 +0,0 @@
package test.atriasoft.etk;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log {
private static final String LIB_NAME = "etk-test";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
private Log() {}
public static void print(String data) {
if (PRINT_PRINT)
Logger.print(LIB_NAME_DRAW, data);
}
public static void critical(String data) {
if (PRINT_CRITICAL)
Logger.critical(LIB_NAME_DRAW, data);
}
public static void error(String data) {
if (PRINT_ERROR)
Logger.error(LIB_NAME_DRAW, data);
}
public static void warning(String data) {
if (PRINT_WARNING)
Logger.warning(LIB_NAME_DRAW, data);
}
public static void info(String data) {
if (PRINT_INFO)
Logger.info(LIB_NAME_DRAW, data);
}
public static void debug(String data) {
if (PRINT_DEBUG)
Logger.debug(LIB_NAME_DRAW, data);
}
public static void verbose(String data) {
if (PRINT_VERBOSE)
Logger.verbose(LIB_NAME_DRAW, data);
}
public static void todo(String data) {
if (PRINT_TODO)
Logger.todo(LIB_NAME_DRAW, data);
}
}

View File

@ -1,18 +0,0 @@
package test.atriasoft.etk;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log2 {
private static final String LIB_NAME = "etk-test-2";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
private Log2() {}
public static void debug(String data) {
if (PRINT_DEBUG)
Logger.debug(LIB_NAME_DRAW, data);
}
}

View File

@ -1,102 +0,0 @@
/*******************************************************************************
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* Contributors:
* Edouard DUPIN - initial API and implementation
******************************************************************************/
package test.atriasoft.etk;
import java.util.ArrayList;
import java.util.List;
import org.atriasoft.reggol.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class)
public class TestBasicLog {
@Test
@Order(1)
public void aaFirstInitialisation() {
List<String> args = new ArrayList<>();
args.add("--log-level=999");
args.add("--log-level=1");
args.add("--log-no-color");
args.add("--log-color");
args.add("--log-lib=sc-log-test+6");
args.add("--log-lib=sc-log-test/6");
args.add("--log-lib=sc-log-test:6");
args.add("--log-lib=sc-log-test:verbose");
args.add("--log-lib=sc-log-test2+3");
args.add("--log-lib=sc-log-test");
args.add("--log-with-stupid-parameter=sdkfjsqdlkf");
args.add("--help");
Logger.init(args);
}
@Test
@Order(2)
public void bbSecondInitialisation() {
List<String> args = new ArrayList<>();
Logger.init(args);
}
@Test
@Order(3)
public void ccBasicLogCall() {
Log.print("Simple print");
Log.todo("Simple todo");
Log.error("Simple error");
Log.warning("Simple warning");
Log.info("Simple info");
Log.debug("Simple debug");
Log.verbose("Simple verbose");
}
// TODO REFACTO REMOVE this and set it in the Test of the logger.
public static String getAAAAAAA(int dfsdf) {
int hhh = 0;
for (int kkk = 0; kkk < dfsdf; kkk++)
for (int iii = 0; iii < 10000; iii++)
for (int jjj = 0; jjj < 100000; jjj++)
for (int lll = 0; lll < 100000; lll++)
hhh++;
return "kkk" + hhh;
}
public static void testLog() {
Log.print("test direct [START]");
// test de 10 secondes contre 0.0?? second quand le niveau n'est pas assez grand ...
long timeStart = System.currentTimeMillis();
for (int iii = 0; iii < 100000000; iii++)
Log2.debug("test direct");
long timeStop = System.currentTimeMillis();
Log.print("test direct [END] : " + timeStart + " to " + timeStop + " ==> delta=" + (timeStop - timeStart));
Log.print("test concat [START]");
// C'est très long dans les 2 cas ...
timeStart = System.currentTimeMillis();
for (int iii = 0; iii < 6; iii++)
Log2.debug("test concat: non fonctionnel, il applelle le get a chaque log ... " + getAAAAAAA(iii));
timeStop = System.currentTimeMillis();
Log.print("test concat [END] : " + timeStart + " to " + timeStop + " ==> delta=" + (timeStop - timeStart));
}
@Test
@Order(4)
public void ddTestSimpleLog() {
testLog();
}
@Test
@Order(4)
public void eeUsage() {
Logger.usage();
}
}